1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with ALI
.Util
; use ALI
.Util
;
28 with Binderr
; use Binderr
;
29 with Butil
; use Butil
;
30 with Casing
; use Casing
;
31 with Fname
; use Fname
;
32 with Namet
; use Namet
;
35 with Output
; use Output
;
36 with Rident
; use Rident
;
37 with Types
; use Types
;
39 package body Bcheck
is
41 -----------------------
42 -- Local Subprograms --
43 -----------------------
45 -- The following checking subprograms make up the parts of the
46 -- configuration consistency check. See bodies for details of checks.
48 procedure Check_Consistent_Dispatching_Policy
;
49 procedure Check_Consistent_Dynamic_Elaboration_Checking
;
50 procedure Check_Consistent_Interrupt_States
;
51 procedure Check_Consistent_Locking_Policy
;
52 procedure Check_Consistent_No_Component_Reordering
;
53 procedure Check_Consistent_Normalize_Scalars
;
54 procedure Check_Consistent_Optimize_Alignment
;
55 procedure Check_Consistent_Partition_Elaboration_Policy
;
56 procedure Check_Consistent_Queuing_Policy
;
57 procedure Check_Consistent_Restrictions
;
58 procedure Check_Consistent_Restriction_No_Default_Initialization
;
59 procedure Check_Consistent_SSO_Default
;
60 procedure Check_Consistent_Exception_Handling
;
62 procedure Consistency_Error_Msg
(Msg
: String);
63 -- Produce an error or a warning message, depending on whether an
64 -- inconsistent configuration is permitted or not.
66 function Same_Unit
(U1
: Unit_Name_Type
; U2
: Name_Id
) return Boolean;
67 -- Used to compare two unit names for No_Dependence checks. U1 is in
68 -- standard unit name format, and U2 is in literal form with periods.
70 -------------------------------------
71 -- Check_Configuration_Consistency --
72 -------------------------------------
74 procedure Check_Configuration_Consistency
is
76 if Queuing_Policy_Specified
/= ' ' then
77 Check_Consistent_Queuing_Policy
;
80 if Locking_Policy_Specified
/= ' ' then
81 Check_Consistent_Locking_Policy
;
84 if No_Component_Reordering_Specified
then
85 Check_Consistent_No_Component_Reordering
;
88 if Partition_Elaboration_Policy_Specified
/= ' ' then
89 Check_Consistent_Partition_Elaboration_Policy
;
92 if SSO_Default_Specified
then
93 Check_Consistent_SSO_Default
;
96 if Zero_Cost_Exceptions_Specified
97 or else Frontend_Exceptions_Specified
99 Check_Consistent_Exception_Handling
;
102 Check_Consistent_Normalize_Scalars
;
103 Check_Consistent_Optimize_Alignment
;
104 Check_Consistent_Dynamic_Elaboration_Checking
;
105 Check_Consistent_Restrictions
;
106 Check_Consistent_Restriction_No_Default_Initialization
;
107 Check_Consistent_Interrupt_States
;
108 Check_Consistent_Dispatching_Policy
;
109 end Check_Configuration_Consistency
;
111 -----------------------
112 -- Check_Consistency --
113 -----------------------
115 procedure Check_Consistency
is
117 -- Source file Id for this Sdep entry
119 ALI_Path_Id
: File_Name_Type
;
122 -- First, we go through the source table to see if there are any cases
123 -- in which we should go after source files and compute checksums of
124 -- the source files. We need to do this for any file for which we have
125 -- mismatching time stamps and (so far) matching checksums.
127 for S
in Source
.First
.. Source
.Last
loop
129 -- If all time stamps for a file match, then there is nothing to
130 -- do, since we will not be checking checksums in that case anyway
132 if Source
.Table
(S
).All_Timestamps_Match
then
135 -- If we did not find the source file, then we can't compute its
136 -- checksum anyway. Note that when we have a time stamp mismatch,
137 -- we try to find the source file unconditionally (i.e. if
138 -- Check_Source_Files is False).
140 elsif not Source
.Table
(S
).Source_Found
then
143 -- If we already have non-matching or missing checksums, then no
144 -- need to try going after source file, since we won't trust the
145 -- checksums in any case.
147 elsif not Source
.Table
(S
).All_Checksums_Match
then
150 -- Now we have the case where we have time stamp mismatches, and
151 -- the source file is around, but so far all checksums match. This
152 -- is the case where we need to compute the checksum from the source
153 -- file, since otherwise we would ignore the time stamp mismatches,
154 -- and that is wrong if the checksum of the source does not agree
155 -- with the checksums in the ALI files.
157 elsif Check_Source_Files
then
158 if not Checksums_Match
159 (Source
.Table
(S
).Checksum
,
160 Get_File_Checksum
(Source
.Table
(S
).Sfile
))
162 Source
.Table
(S
).All_Checksums_Match
:= False;
167 -- Loop through ALI files
169 ALIs_Loop
: for A
in ALIs
.First
.. ALIs
.Last
loop
171 -- Loop through Sdep entries in one ALI file
174 ALIs
.Table
(A
).First_Sdep
.. ALIs
.Table
(A
).Last_Sdep
176 if Sdep
.Table
(D
).Dummy_Entry
then
180 Src
:= Source_Id
(Get_Name_Table_Int
(Sdep
.Table
(D
).Sfile
));
182 -- If the time stamps match, or all checksums match, then we
183 -- are OK, otherwise we have a definite error.
185 if Sdep
.Table
(D
).Stamp
/= Source
.Table
(Src
).Stamp
186 and then not Source
.Table
(Src
).All_Checksums_Match
188 Error_Msg_File_1
:= ALIs
.Table
(A
).Sfile
;
189 Error_Msg_File_2
:= Sdep
.Table
(D
).Sfile
;
191 -- Two styles of message, depending on whether or not
192 -- the updated file is the one that must be recompiled
194 if Error_Msg_File_1
= Error_Msg_File_2
then
195 if Tolerate_Consistency_Errors
then
197 ("?{ has been modified and should be recompiled");
200 ("{ has been modified and must be recompiled");
205 Osint
.Full_Lib_File_Name
(ALIs
.Table
(A
).Afile
);
207 if Osint
.Is_Readonly_Library
(ALI_Path_Id
) then
208 if Tolerate_Consistency_Errors
then
209 Error_Msg
("?{ should be recompiled");
210 Error_Msg_File_1
:= ALI_Path_Id
;
211 Error_Msg
("?({ is obsolete and read-only)");
213 Error_Msg
("{ must be compiled");
214 Error_Msg_File_1
:= ALI_Path_Id
;
215 Error_Msg
("({ is obsolete and read-only)");
218 elsif Tolerate_Consistency_Errors
then
220 ("?{ should be recompiled ({ has been modified)");
223 Error_Msg
("{ must be recompiled ({ has been modified)");
227 if (not Tolerate_Consistency_Errors
) and Verbose_Mode
then
228 Error_Msg_File_1
:= Source
.Table
(Src
).Stamp_File
;
230 if Source
.Table
(Src
).Source_Found
then
232 Osint
.Full_Source_Name
(Error_Msg_File_1
);
235 Osint
.Full_Lib_File_Name
(Error_Msg_File_1
);
239 ("time stamp from { " & String (Source
.Table
(Src
).Stamp
));
241 Error_Msg_File_1
:= Sdep
.Table
(D
).Sfile
;
243 (" conflicts with { timestamp " &
244 String (Sdep
.Table
(D
).Stamp
));
247 Osint
.Full_Lib_File_Name
(ALIs
.Table
(A
).Afile
);
248 Error_Msg
(" from {");
251 -- Exit from the loop through Sdep entries once we find one
252 -- that does not match.
261 end Check_Consistency
;
263 -----------------------------------------
264 -- Check_Consistent_Dispatching_Policy --
265 -----------------------------------------
267 -- The rule is that all files for which the dispatching policy is
268 -- significant must meet the following rules:
270 -- 1. All files for which a task dispatching policy is significant must
271 -- be compiled with the same setting.
273 -- 2. If a partition contains one or more Priority_Specific_Dispatching
274 -- pragmas it cannot contain a Task_Dispatching_Policy pragma.
276 -- 3. No overlap is allowed in the priority ranges specified in
277 -- Priority_Specific_Dispatching pragmas within the same partition.
279 -- 4. If a partition contains one or more Priority_Specific_Dispatching
280 -- pragmas then the Ceiling_Locking policy is the only one allowed for
283 procedure Check_Consistent_Dispatching_Policy
is
285 -- Maximum priority value for which a Priority_Specific_Dispatching
286 -- pragma has been specified.
288 TDP_Pragma_Afile
: ALI_Id
:= No_ALI_Id
;
289 -- ALI file where a Task_Dispatching_Policy pragma appears
292 -- Consistency checks in units specifying a Task_Dispatching_Policy
294 if Task_Dispatching_Policy_Specified
/= ' ' then
295 Find_Policy
: for A1
in ALIs
.First
.. ALIs
.Last
loop
296 if ALIs
.Table
(A1
).Task_Dispatching_Policy
/= ' ' then
298 -- Store the place where the first task dispatching pragma
299 -- appears. We may need this value for issuing consistency
300 -- errors if Priority_Specific_Dispatching pragmas are used.
302 TDP_Pragma_Afile
:= A1
;
304 Check_Policy
: declare
305 Policy
: constant Character :=
306 ALIs
.Table
(A1
).Task_Dispatching_Policy
;
309 for A2
in A1
+ 1 .. ALIs
.Last
loop
310 if ALIs
.Table
(A2
).Task_Dispatching_Policy
/= ' '
312 ALIs
.Table
(A2
).Task_Dispatching_Policy
/= Policy
314 Error_Msg_File_1
:= ALIs
.Table
(A1
).Sfile
;
315 Error_Msg_File_2
:= ALIs
.Table
(A2
).Sfile
;
317 Consistency_Error_Msg
318 ("{ and { compiled with different task" &
319 " dispatching policies");
327 end loop Find_Policy
;
330 -- If no Priority_Specific_Dispatching entries, nothing else to do
332 if Specific_Dispatching
.Last
>= Specific_Dispatching
.First
then
334 -- Find out the maximum priority value for which one of the
335 -- Priority_Specific_Dispatching pragmas applies.
338 for J
in Specific_Dispatching
.First
.. Specific_Dispatching
.Last
loop
339 if Specific_Dispatching
.Table
(J
).Last_Priority
> Max_Prio
then
340 Max_Prio
:= Specific_Dispatching
.Table
(J
).Last_Priority
;
344 -- Now establish tables to be used for consistency checking
347 -- The following record type is used to record locations of the
348 -- Priority_Specific_Dispatching pragmas applying to the Priority.
350 type Specific_Dispatching_Entry
is record
351 Dispatching_Policy
: Character := ' ';
352 -- First character (upper case) of corresponding policy name
354 Afile
: ALI_Id
:= No_ALI_Id
;
355 -- ALI file that generated Priority Specific Dispatching
356 -- entry for consistency message.
359 -- Line numbers from Priority_Specific_Dispatching pragma
362 PSD_Table
: array (0 .. Max_Prio
) of Specific_Dispatching_Entry
:=
363 (others => Specific_Dispatching_Entry
'
364 (Dispatching_Policy => ' ',
367 -- Array containing an entry per priority containing the location
368 -- where there is a Priority_Specific_Dispatching pragma that
369 -- applies to the priority.
372 for F in ALIs.First .. ALIs.Last loop
373 for K in ALIs.Table (F).First_Specific_Dispatching ..
374 ALIs.Table (F).Last_Specific_Dispatching
377 DTK : Specific_Dispatching_Record
378 renames Specific_Dispatching.Table (K);
380 -- Check whether pragma Task_Dispatching_Policy and
381 -- pragma Priority_Specific_Dispatching are used in the
384 if Task_Dispatching_Policy_Specified /= ' ' then
385 Error_Msg_File_1 := ALIs.Table (F).Sfile;
387 ALIs.Table (TDP_Pragma_Afile).Sfile;
389 Error_Msg_Nat_1 := DTK.PSD_Pragma_Line;
391 Consistency_Error_Msg
392 ("Priority_Specific_Dispatching at {:#" &
393 " incompatible with Task_Dispatching_Policy at {");
396 -- Ceiling_Locking must also be specified for a partition
397 -- with at least one Priority_Specific_Dispatching
400 if Locking_Policy_Specified /= ' '
401 and then Locking_Policy_Specified /= 'C
'
403 for A in ALIs.First .. ALIs.Last loop
404 if ALIs.Table (A).Locking_Policy /= ' '
405 and then ALIs.Table (A).Locking_Policy /= 'C
'
407 Error_Msg_File_1 := ALIs.Table (F).Sfile;
408 Error_Msg_File_2 := ALIs.Table (A).Sfile;
410 Error_Msg_Nat_1 := DTK.PSD_Pragma_Line;
412 Consistency_Error_Msg
413 ("Priority_Specific_Dispatching at {:#" &
414 " incompatible with Locking_Policy at {");
419 -- Check overlapping priority ranges
421 Find_Overlapping : for Prio in
422 DTK.First_Priority .. DTK.Last_Priority
424 if PSD_Table (Prio).Afile = No_ALI_Id then
426 (Dispatching_Policy => DTK.Dispatching_Policy,
427 Afile => F, Loc => DTK.PSD_Pragma_Line);
429 elsif PSD_Table (Prio).Dispatching_Policy /=
430 DTK.Dispatching_Policy
434 ALIs.Table (PSD_Table (Prio).Afile).Sfile;
435 Error_Msg_File_2 := ALIs.Table (F).Sfile;
436 Error_Msg_Nat_1 := PSD_Table (Prio).Loc;
437 Error_Msg_Nat_2 := DTK.PSD_Pragma_Line;
439 Consistency_Error_Msg
440 ("overlapping priority ranges at {:# and {:#");
442 exit Find_Overlapping;
444 end loop Find_Overlapping;
450 end Check_Consistent_Dispatching_Policy;
452 ---------------------------------------------------
453 -- Check_Consistent_Dynamic_Elaboration_Checking --
454 ---------------------------------------------------
456 -- The rule here is that if a unit has dynamic elaboration checks,
457 -- then any unit it withs must meet one of the following criteria:
459 -- 1. There is a pragma Elaborate_All for the with'ed unit
460 -- 2. The with'ed unit was compiled with dynamic elaboration checks
461 -- 3. The with'ed unit has pragma Preelaborate or Pure
462 -- 4. It is an internal GNAT unit (including children of GNAT)
463 -- 5. It is an interface of a Stand-Alone Library
465 procedure Check_Consistent_Dynamic_Elaboration_Checking is
467 if Dynamic_Elaboration_Checks_Specified then
468 for U in First_Unit_Entry .. Units.Last loop
470 UR : Unit_Record renames Units.Table (U);
473 if UR.Dynamic_Elab then
474 for W in UR.First_With .. UR.Last_With loop
476 WR : With_Record renames Withs.Table (W);
479 if Get_Name_Table_Int (WR.Uname) /= 0 then
481 WU : Unit_Record renames
484 (Get_Name_Table_Int (WR.Uname)));
487 -- Case 1. Elaborate_All for with'ed unit
489 if WR.Elaborate_All then
492 -- Case 2. With'ed unit has dynamic elab checks
494 elsif WU.Dynamic_Elab then
497 -- Case 3. With'ed unit is Preelaborate or Pure
499 elsif WU.Preelab or else WU.Pure then
502 -- Case 4. With'ed unit is internal file
504 elsif Is_Internal_File_Name (WU.Sfile) then
507 -- Case 5. With'ed unit is a SAL interface
509 elsif WU.SAL_Interface then
512 -- Issue warning, not one of the safe cases
515 Error_Msg_File_1 := UR.Sfile;
517 ("?{ has dynamic elaboration checks " &
520 Error_Msg_File_1 := WU.Sfile;
522 ("? { which has static elaboration " &
525 Warnings_Detected := Warnings_Detected + 1;
535 end Check_Consistent_Dynamic_Elaboration_Checking;
537 ---------------------------------------
538 -- Check_Consistent_Interrupt_States --
539 ---------------------------------------
541 -- The rule is that if the state of a given interrupt is specified
542 -- in more than one unit, it must be specified with a consistent state.
544 procedure Check_Consistent_Interrupt_States is
548 -- If no Interrupt_State entries, nothing to do
550 if Interrupt_States.Last < Interrupt_States.First then
554 -- First find out the maximum interrupt value
557 for J in Interrupt_States.First .. Interrupt_States.Last loop
558 if Interrupt_States.Table (J).Interrupt_Id > Max_Intrup then
559 Max_Intrup := Interrupt_States.Table (J).Interrupt_Id;
563 -- Now establish tables to be used for consistency checking
566 Istate : array (0 .. Max_Intrup) of Character := (others => 'n
');
567 -- Interrupt state entries, 'u
'/'s
'/'r
' or 'n
' to indicate an
568 -- entry that has not been set.
570 Afile : array (0 .. Max_Intrup) of ALI_Id;
571 -- ALI file that generated Istate entry for consistency message
573 Loc : array (0 .. Max_Intrup) of Nat;
574 -- Line numbers from IS pragma generating Istate entry
577 -- Interrupt number from entry being tested
580 -- Interrupt state from entry being tested
583 -- Line number from entry being tested
586 for F in ALIs.First .. ALIs.Last loop
587 for K in ALIs.Table (F).First_Interrupt_State ..
588 ALIs.Table (F).Last_Interrupt_State
590 Inum := Interrupt_States.Table (K).Interrupt_Id;
591 Stat := Interrupt_States.Table (K).Interrupt_State;
592 Lnum := Interrupt_States.Table (K).IS_Pragma_Line;
594 if Istate (Inum) = 'n
' then
595 Istate (Inum) := Stat;
599 elsif Istate (Inum) /= Stat then
600 Error_Msg_File_1 := ALIs.Table (Afile (Inum)).Sfile;
601 Error_Msg_File_2 := ALIs.Table (F).Sfile;
602 Error_Msg_Nat_1 := Loc (Inum);
603 Error_Msg_Nat_2 := Lnum;
605 Consistency_Error_Msg
606 ("inconsistent interrupt states at {:# and {:#");
611 end Check_Consistent_Interrupt_States;
613 -------------------------------------
614 -- Check_Consistent_Locking_Policy --
615 -------------------------------------
617 -- The rule is that all files for which the locking policy is
618 -- significant must be compiled with the same setting.
620 procedure Check_Consistent_Locking_Policy is
622 -- First search for a unit specifying a policy and then
623 -- check all remaining units against it.
625 Find_Policy : for A1 in ALIs.First .. ALIs.Last loop
626 if ALIs.Table (A1).Locking_Policy /= ' ' then
627 Check_Policy : declare
628 Policy : constant Character := ALIs.Table (A1).Locking_Policy;
631 for A2 in A1 + 1 .. ALIs.Last loop
632 if ALIs.Table (A2).Locking_Policy /= ' '
634 ALIs.Table (A2).Locking_Policy /= Policy
636 Error_Msg_File_1 := ALIs.Table (A1).Sfile;
637 Error_Msg_File_2 := ALIs.Table (A2).Sfile;
639 Consistency_Error_Msg
640 ("{ and { compiled with different locking policies");
648 end loop Find_Policy;
649 end Check_Consistent_Locking_Policy;
651 ----------------------------------------------
652 -- Check_Consistent_No_Component_Reordering --
653 ----------------------------------------------
655 -- This routine checks for a consistent No_Component_Reordering setting.
656 -- Note that internal units are excluded from this check, since we don't
657 -- in any case allow the pragma to affect types in internal units, and
658 -- there is thus no requirement to recompile the run-time with the setting.
660 procedure Check_Consistent_No_Component_Reordering is
661 OK : Boolean := True;
663 -- Check that all entries have No_Component_Reordering set
665 for A1 in ALIs.First .. ALIs.Last loop
666 if not Is_Internal_File_Name (ALIs.Table (A1).Sfile)
667 and then not ALIs.Table (A1).No_Component_Reordering
680 -- Here we have an inconsistency
682 Consistency_Error_Msg
683 ("some but not all files compiled with No_Component_Reordering");
686 Write_Str ("files compiled with No_Component_Reordering");
689 for A1 in ALIs.First .. ALIs.Last loop
690 if not Is_Internal_File_Name (ALIs.Table (A1).Sfile)
691 and then ALIs.Table (A1).No_Component_Reordering
694 Write_Name (ALIs.Table (A1).Sfile);
700 Write_Str ("files compiled without No_Component_Reordering");
703 for A1 in ALIs.First .. ALIs.Last loop
704 if not Is_Internal_File_Name (ALIs.Table (A1).Sfile)
705 and then not ALIs.Table (A1).No_Component_Reordering
708 Write_Name (ALIs.Table (A1).Sfile);
712 end Check_Consistent_No_Component_Reordering;
714 ----------------------------------------
715 -- Check_Consistent_Normalize_Scalars --
716 ----------------------------------------
718 -- The rule is that if any unit is compiled with Normalize_Scalars,
719 -- then all other units in the partition must also be compiled with
720 -- Normalize_Scalars in effect.
722 -- There is some issue as to whether this consistency check is desirable,
723 -- it is certainly required at the moment by the RM. We should keep a watch
724 -- on the ARG and HRG deliberations here. GNAT no longer depends on this
725 -- consistency (it used to do so, but that is no longer the case, since
726 -- pragma Initialize_Scalars pragma does not require consistency.)
728 procedure Check_Consistent_Normalize_Scalars is
730 if Normalize_Scalars_Specified and No_Normalize_Scalars_Specified then
731 Consistency_Error_Msg
732 ("some but not all files compiled with Normalize_Scalars");
735 Write_Str ("files compiled with Normalize_Scalars");
738 for A1 in ALIs.First .. ALIs.Last loop
739 if ALIs.Table (A1).Normalize_Scalars then
741 Write_Name (ALIs.Table (A1).Sfile);
747 Write_Str ("files compiled without Normalize_Scalars");
750 for A1 in ALIs.First .. ALIs.Last loop
751 if not ALIs.Table (A1).Normalize_Scalars then
753 Write_Name (ALIs.Table (A1).Sfile);
758 end Check_Consistent_Normalize_Scalars;
760 -----------------------------------------
761 -- Check_Consistent_Optimize_Alignment --
762 -----------------------------------------
764 -- The rule is that all units which depend on the global default setting
765 -- of Optimize_Alignment must be compiled with the same setting for this
766 -- default. Units which specify an explicit local value for this setting
767 -- are exempt from the consistency rule (this includes all internal units).
769 procedure Check_Consistent_Optimize_Alignment is
770 OA_Setting : Character := ' ';
771 -- Reset when we find a unit that depends on the default and does
772 -- not have a local specification of the Optimize_Alignment setting.
775 -- Id of unit from which OA_Setting was set
780 for U in First_Unit_Entry .. Units.Last loop
781 C := Units.Table (U).Optimize_Alignment;
784 if OA_Setting = ' ' then
788 elsif OA_Setting = C then
792 Error_Msg_Unit_1 := Units.Table (OA_Unit).Uname;
793 Error_Msg_Unit_2 := Units.Table (U).Uname;
795 Consistency_Error_Msg
796 ("$ and $ compiled with different "
797 & "default Optimize_Alignment settings");
802 end Check_Consistent_Optimize_Alignment;
804 ---------------------------------------------------
805 -- Check_Consistent_Partition_Elaboration_Policy --
806 ---------------------------------------------------
808 -- The rule is that all files for which the partition elaboration policy is
809 -- significant must be compiled with the same setting.
811 procedure Check_Consistent_Partition_Elaboration_Policy is
813 -- First search for a unit specifying a policy and then
814 -- check all remaining units against it.
816 Find_Policy : for A1 in ALIs.First .. ALIs.Last loop
817 if ALIs.Table (A1).Partition_Elaboration_Policy /= ' ' then
818 Check_Policy : declare
819 Policy : constant Character :=
820 ALIs.Table (A1).Partition_Elaboration_Policy;
823 for A2 in A1 + 1 .. ALIs.Last loop
824 if ALIs.Table (A2).Partition_Elaboration_Policy /= ' '
826 ALIs.Table (A2).Partition_Elaboration_Policy /= Policy
828 Error_Msg_File_1 := ALIs.Table (A1).Sfile;
829 Error_Msg_File_2 := ALIs.Table (A2).Sfile;
831 Consistency_Error_Msg
832 ("{ and { compiled with different partition "
833 & "elaboration policies");
839 -- A No_Task_Hierarchy restriction must be specified for the
840 -- Sequential policy (RM H.6(6/2)).
842 if Partition_Elaboration_Policy_Specified = 'S
'
843 and then not Cumulative_Restrictions.Set (No_Task_Hierarchy)
845 Error_Msg_File_1 := ALIs.Table (A1).Sfile;
847 ("{ has sequential partition elaboration policy, but no");
849 ("pragma Restrictions (No_Task_Hierarchy) was specified");
854 end loop Find_Policy;
855 end Check_Consistent_Partition_Elaboration_Policy;
857 -------------------------------------
858 -- Check_Consistent_Queuing_Policy --
859 -------------------------------------
861 -- The rule is that all files for which the queuing policy is
862 -- significant must be compiled with the same setting.
864 procedure Check_Consistent_Queuing_Policy is
866 -- First search for a unit specifying a policy and then
867 -- check all remaining units against it.
869 Find_Policy : for A1 in ALIs.First .. ALIs.Last loop
870 if ALIs.Table (A1).Queuing_Policy /= ' ' then
871 Check_Policy : declare
872 Policy : constant Character := ALIs.Table (A1).Queuing_Policy;
874 for A2 in A1 + 1 .. ALIs.Last loop
875 if ALIs.Table (A2).Queuing_Policy /= ' '
877 ALIs.Table (A2).Queuing_Policy /= Policy
879 Error_Msg_File_1 := ALIs.Table (A1).Sfile;
880 Error_Msg_File_2 := ALIs.Table (A2).Sfile;
882 Consistency_Error_Msg
883 ("{ and { compiled with different queuing policies");
891 end loop Find_Policy;
892 end Check_Consistent_Queuing_Policy;
894 -----------------------------------
895 -- Check_Consistent_Restrictions --
896 -----------------------------------
898 -- The rule is that if a restriction is specified in any unit, then all
899 -- units must obey the restriction. The check applies only to restrictions
900 -- which require partition wide consistency, and not to internal units.
902 procedure Check_Consistent_Restrictions is
903 Restriction_File_Output : Boolean;
904 -- Shows if we have output header messages for restriction violation
906 procedure Print_Restriction_File (R : All_Restrictions);
907 -- Print header line for R if not printed yet
909 ----------------------------
910 -- Print_Restriction_File --
911 ----------------------------
913 procedure Print_Restriction_File (R : All_Restrictions) is
915 if not Restriction_File_Output then
916 Restriction_File_Output := True;
918 -- Find an ali file specifying the restriction
920 for A in ALIs.First .. ALIs.Last loop
921 if ALIs.Table (A).Restrictions.Set (R)
922 and then (R in All_Boolean_Restrictions
923 or else ALIs.Table (A).Restrictions.Value (R) =
924 Cumulative_Restrictions.Value (R))
926 -- We have found that ALI file A specifies the restriction
927 -- that is being violated (the minimum value is specified
928 -- in the case of a parameter restriction).
931 M1 : constant String := "{ has restriction ";
932 S : constant String := Restriction_Id'Image (R);
933 M2 : String (1 .. 2000); -- big enough
937 Name_Buffer (1 .. S'Length) := S;
938 Name_Len := S'Length;
939 Set_Casing (Mixed_Case);
943 M2 (P .. P + S'Length - 1) := Name_Buffer (1 .. S'Length);
946 if R in All_Parameter_Restrictions then
947 M2 (P .. P + 4) := " => #";
949 Int (Cumulative_Restrictions.Value (R));
953 Error_Msg_File_1 := ALIs.Table (A).Sfile;
954 Consistency_Error_Msg (M2 (1 .. P - 1));
955 Consistency_Error_Msg
956 ("but the following files violate this restriction:");
962 end Print_Restriction_File;
964 -- Start of processing for Check_Consistent_Restrictions
967 -- We used to have a special test here:
969 -- A special test, if we have a main program, then if it has an
970 -- allocator in the body, this is considered to be a violation of
971 -- the restriction No_Allocators_After_Elaboration. We just mark
972 -- this restriction and then the normal circuit will flag it.
974 -- But we don't do that any more, because in the final version of Ada
975 -- 2012, it is statically illegal to have an allocator in a library-
976 -- level subprogram, so we don't need this bind time test any more.
977 -- If we have a main program with parameters (which GNAT allows), then
978 -- allocators in that will be caught by the run-time check.
980 -- Loop through all restriction violations
982 for R in All_Restrictions loop
984 -- Check for violation of this restriction
986 if Cumulative_Restrictions.Set (R)
987 and then Cumulative_Restrictions.Violated (R)
988 and then (R in Partition_Boolean_Restrictions
989 or else (R in All_Parameter_Restrictions
991 Cumulative_Restrictions.Count (R) >
992 Cumulative_Restrictions.Value (R)))
994 Restriction_File_Output := False;
996 -- Loop through files looking for violators
998 for A2 in ALIs.First .. ALIs.Last loop
1000 T : ALIs_Record renames ALIs.Table (A2);
1003 if T.Restrictions.Violated (R) then
1005 -- We exclude predefined files from the list of
1006 -- violators. This should be rethought. It is not
1007 -- clear that this is the right thing to do, that
1008 -- is particularly the case for restricted runtimes.
1010 if not Is_Internal_File_Name (T.Sfile) then
1012 -- Case of Boolean restriction, just print file name
1014 if R in All_Boolean_Restrictions then
1015 Print_Restriction_File (R);
1016 Error_Msg_File_1 := T.Sfile;
1017 Consistency_Error_Msg (" {");
1019 -- Case of Parameter restriction where violation
1020 -- count exceeds restriction value, print file
1021 -- name and count, adding "at least" if the
1022 -- exact count is not known.
1024 elsif R in Checked_Add_Parameter_Restrictions
1025 or else T.Restrictions.Count (R) >
1026 Cumulative_Restrictions.Value (R)
1028 Print_Restriction_File (R);
1029 Error_Msg_File_1 := T.Sfile;
1030 Error_Msg_Nat_1 := Int (T.Restrictions.Count (R));
1032 if T.Restrictions.Unknown (R) then
1033 Consistency_Error_Msg
1034 (" { (count = at least #)");
1036 Consistency_Error_Msg
1047 -- Now deal with No_Dependence indications. Note that we put the loop
1048 -- through entries in the no dependency table first, since this loop
1049 -- is most often empty (no such pragma Restrictions in use).
1051 for ND in No_Deps.First .. No_Deps.Last loop
1053 ND_Unit : constant Name_Id := No_Deps.Table (ND).No_Dep_Unit;
1055 for J in ALIs.First .. ALIs.Last loop
1057 A : ALIs_Record renames ALIs.Table (J);
1059 for K in A.First_Unit .. A.Last_Unit loop
1061 U : Unit_Record renames Units.Table (K);
1063 -- Exclude runtime units from this check since the
1064 -- user does not care how a runtime unit is
1067 if not Is_Internal_File_Name (U.Sfile) then
1068 for L in U.First_With .. U.Last_With loop
1069 if Same_Unit (Withs.Table (L).Uname, ND_Unit)
1071 Error_Msg_File_1 := U.Sfile;
1072 Error_Msg_Name_1 := ND_Unit;
1073 Consistency_Error_Msg
1074 ("file { violates restriction " &
1075 "No_Dependence => %");
1085 end Check_Consistent_Restrictions;
1087 ------------------------------------------------------------
1088 -- Check_Consistent_Restriction_No_Default_Initialization --
1089 ------------------------------------------------------------
1091 -- The Restriction (No_Default_Initialization) has special consistency
1092 -- rules. The rule is that no unit compiled without this restriction
1093 -- that violates the restriction can WITH a unit that is compiled with
1096 procedure Check_Consistent_Restriction_No_Default_Initialization is
1098 -- Nothing to do if no one set this restriction
1100 if not Cumulative_Restrictions.Set (No_Default_Initialization) then
1104 -- Nothing to do if no one violates the restriction
1106 if not Cumulative_Restrictions.Violated (No_Default_Initialization) then
1110 -- Otherwise we go into a full scan to find possible problems
1112 for U in Units.First .. Units.Last loop
1114 UTE : Unit_Record renames Units.Table (U);
1115 ATE : ALIs_Record renames ALIs.Table (UTE.My_ALI);
1118 if ATE.Restrictions.Violated (No_Default_Initialization) then
1119 for W in UTE.First_With .. UTE.Last_With loop
1121 AFN : constant File_Name_Type := Withs.Table (W).Afile;
1124 -- The file name may not be present for withs of certain
1125 -- generic run-time files. The test can be safely left
1126 -- out in such cases anyway.
1128 if AFN /= No_File then
1130 WAI : constant ALI_Id :=
1131 ALI_Id (Get_Name_Table_Int (AFN));
1132 WTE : ALIs_Record renames ALIs.Table (WAI);
1135 if WTE.Restrictions.Set
1136 (No_Default_Initialization)
1138 Error_Msg_Unit_1 := UTE.Uname;
1139 Consistency_Error_Msg
1140 ("unit $ compiled without restriction "
1141 & "No_Default_Initialization");
1142 Error_Msg_Unit_1 := Withs.Table (W).Uname;
1143 Consistency_Error_Msg
1144 ("withs unit $, compiled with restriction "
1145 & "No_Default_Initialization");
1154 end Check_Consistent_Restriction_No_Default_Initialization;
1156 ----------------------------------
1157 -- Check_Consistent_SSO_Default --
1158 ----------------------------------
1160 -- This routine checks for a consistent SSO default setting. Note that
1161 -- internal units are excluded from this check, since we don't in any
1162 -- case allow the pragma to affect types in internal units, and there
1163 -- is thus no requirement to recompile the run-time with the default set.
1165 procedure Check_Consistent_SSO_Default is
1166 Default : Character;
1169 Default := ALIs.Table (ALIs.First).SSO_Default;
1171 -- The default must be set from a non-internal unit
1174 (not Is_Internal_File_Name (ALIs.Table (ALIs.First).Sfile));
1176 -- Check all entries match the default above from the first entry
1178 for A1 in ALIs.First + 1 .. ALIs.Last loop
1179 if not Is_Internal_File_Name (ALIs.Table (A1).Sfile)
1180 and then ALIs.Table (A1).SSO_Default /= Default
1187 -- All match, return
1189 if Default /= '?
' then
1193 -- Here we have a mismatch
1195 Consistency_Error_Msg
1196 ("files not compiled with same Default_Scalar_Storage_Order");
1199 Write_Str ("files compiled with High_Order_First");
1202 for A1 in ALIs.First .. ALIs.Last loop
1203 if ALIs.Table (A1).SSO_Default = 'H
' then
1205 Write_Name (ALIs.Table (A1).Sfile);
1211 Write_Str ("files compiled with Low_Order_First");
1214 for A1 in ALIs.First .. ALIs.Last loop
1215 if ALIs.Table (A1).SSO_Default = 'L
' then
1217 Write_Name (ALIs.Table (A1).Sfile);
1223 Write_Str ("files compiled with no Default_Scalar_Storage_Order");
1226 for A1 in ALIs.First .. ALIs.Last loop
1227 if not Is_Internal_File_Name (ALIs.Table (A1).Sfile)
1228 and then ALIs.Table (A1).SSO_Default = ' '
1231 Write_Name (ALIs.Table (A1).Sfile);
1235 end Check_Consistent_SSO_Default;
1237 -----------------------------------------
1238 -- Check_Consistent_Exception_Handling --
1239 -----------------------------------------
1241 -- All units must have the same exception handling mechanism.
1243 procedure Check_Consistent_Exception_Handling is
1245 Check_Mechanism : for A1 in ALIs.First + 1 .. ALIs.Last loop
1246 if (ALIs.Table (A1).Zero_Cost_Exceptions /=
1247 ALIs.Table (ALIs.First).Zero_Cost_Exceptions)
1249 (ALIs.Table (A1).Frontend_Exceptions /=
1250 ALIs.Table (ALIs.First).Frontend_Exceptions)
1252 Error_Msg_File_1 := ALIs.Table (A1).Sfile;
1253 Error_Msg_File_2 := ALIs.Table (ALIs.First).Sfile;
1255 Consistency_Error_Msg
1256 ("{ and { compiled with different exception handling "
1259 end loop Check_Mechanism;
1260 end Check_Consistent_Exception_Handling;
1262 -------------------------------
1263 -- Check_Duplicated_Subunits --
1264 -------------------------------
1266 procedure Check_Duplicated_Subunits is
1268 for J in Sdep.First .. Sdep.Last loop
1269 if Sdep.Table (J).Subunit_Name /= No_Name then
1270 Get_Decoded_Name_String (Sdep.Table (J).Subunit_Name);
1271 Name_Len := Name_Len + 2;
1272 Name_Buffer (Name_Len - 1) := '%';
1274 -- See if there is a body or spec with the same name
1276 for K in Boolean loop
1278 Name_Buffer (Name_Len) := 'b
';
1280 Name_Buffer (Name_Len) := 's
';
1284 Unit : constant Unit_Name_Type := Name_Find;
1285 Info : constant Int := Get_Name_Table_Int (Unit);
1290 Write_Str ("error: subunit """);
1291 Write_Name_Decoded (Sdep.Table (J).Subunit_Name);
1292 Write_Str (""" in file """);
1293 Write_Name_Decoded (Sdep.Table (J).Sfile);
1296 Write_Str (" has same name as unit
""");
1297 Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
1298 Write_Str (""" found
in file
""");
1299 Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
1302 Write_Str (" this is not allowed within a single "
1303 & "partition (RM 10.2(19))");
1305 Osint.Exit_Program (Osint.E_Fatal);
1311 end Check_Duplicated_Subunits;
1313 --------------------
1314 -- Check_Versions --
1315 --------------------
1317 procedure Check_Versions is
1318 VL : constant Natural := ALIs.Table (ALIs.First).Ver_Len;
1321 for A in ALIs.First .. ALIs.Last loop
1322 if ALIs.Table (A).Ver_Len /= VL
1323 or else ALIs.Table (A).Ver (1 .. VL) /=
1324 ALIs.Table (ALIs.First).Ver (1 .. VL)
1326 Error_Msg_File_1 := ALIs.Table (A).Sfile;
1327 Error_Msg_File_2 := ALIs.Table (ALIs.First).Sfile;
1329 Consistency_Error_Msg
1330 ("{ and { compiled with different GNAT versions");
1335 ---------------------------
1336 -- Consistency_Error_Msg --
1337 ---------------------------
1339 procedure Consistency_Error_Msg (Msg : String) is
1341 if Tolerate_Consistency_Errors then
1343 -- If consistency errors are tolerated,
1344 -- output the message as a warning.
1346 Error_Msg ('?
' & Msg);
1348 -- Otherwise the consistency error is a true error
1353 end Consistency_Error_Msg;
1359 function Same_Unit (U1 : Unit_Name_Type; U2 : Name_Id) return Boolean is
1361 -- Note, the string U1 has a terminating %s or %b, U2 does not
1363 if Length_Of_Name (U1) - 2 = Length_Of_Name (U2) then
1364 Get_Name_String (U1);
1367 U1_Str : constant String := Name_Buffer (1 .. Name_Len - 2);
1369 Get_Name_String (U2);
1370 return U1_Str = Name_Buffer (1 .. Name_Len);