1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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
;
33 with Namet
; use Namet
;
36 with Output
; use Output
;
37 with Rident
; use Rident
;
38 with Types
; use Types
;
40 package body Bcheck
is
42 -----------------------
43 -- Local Subprograms --
44 -----------------------
46 -- The following checking subprograms make up the parts of the
47 -- configuration consistency check. See bodies for details of checks.
49 procedure Check_Consistent_Dispatching_Policy
;
50 procedure Check_Consistent_Dynamic_Elaboration_Checking
;
51 procedure Check_Consistent_Interrupt_States
;
52 procedure Check_Consistent_Locking_Policy
;
53 procedure Check_Consistent_No_Component_Reordering
;
54 procedure Check_Consistent_Normalize_Scalars
;
55 procedure Check_Consistent_Optimize_Alignment
;
56 procedure Check_Consistent_Partition_Elaboration_Policy
;
57 procedure Check_Consistent_Queuing_Policy
;
58 procedure Check_Consistent_Restrictions
;
59 procedure Check_Consistent_Restriction_No_Default_Initialization
;
60 procedure Check_Consistent_SSO_Default
;
61 procedure Check_Consistent_Exception_Handling
;
63 procedure Consistency_Error_Msg
(Msg
: String);
64 -- Produce an error or a warning message, depending on whether an
65 -- inconsistent configuration is permitted or not.
67 function Same_Unit
(U1
: Unit_Name_Type
; U2
: Name_Id
) return Boolean;
68 -- Used to compare two unit names for No_Dependence checks. U1 is in
69 -- standard unit name format, and U2 is in literal form with periods.
71 -------------------------------------
72 -- Check_Configuration_Consistency --
73 -------------------------------------
75 procedure Check_Configuration_Consistency
is
77 if Queuing_Policy_Specified
/= ' ' then
78 Check_Consistent_Queuing_Policy
;
81 if Locking_Policy_Specified
/= ' ' then
82 Check_Consistent_Locking_Policy
;
85 if No_Component_Reordering_Specified
then
86 Check_Consistent_No_Component_Reordering
;
89 if Partition_Elaboration_Policy_Specified
/= ' ' then
90 Check_Consistent_Partition_Elaboration_Policy
;
93 if SSO_Default_Specified
then
94 Check_Consistent_SSO_Default
;
97 if Zero_Cost_Exceptions_Specified
then
98 Check_Consistent_Exception_Handling
;
101 Check_Consistent_Normalize_Scalars
;
102 Check_Consistent_Optimize_Alignment
;
103 Check_Consistent_Dynamic_Elaboration_Checking
;
104 Check_Consistent_Restrictions
;
105 Check_Consistent_Restriction_No_Default_Initialization
;
106 Check_Consistent_Interrupt_States
;
107 Check_Consistent_Dispatching_Policy
;
108 end Check_Configuration_Consistency
;
110 -----------------------
111 -- Check_Consistency --
112 -----------------------
114 procedure Check_Consistency
is
116 -- Source file Id for this Sdep entry
118 ALI_Path_Id
: File_Name_Type
;
121 -- First, we go through the source table to see if there are any cases
122 -- in which we should go after source files and compute checksums of
123 -- the source files. We need to do this for any file for which we have
124 -- mismatching time stamps and (so far) matching checksums.
126 for S
in Source
.First
.. Source
.Last
loop
128 -- If all time stamps for a file match, then there is nothing to
129 -- do, since we will not be checking checksums in that case anyway
131 if Source
.Table
(S
).All_Timestamps_Match
then
134 -- If we did not find the source file, then we can't compute its
135 -- checksum anyway. Note that when we have a time stamp mismatch,
136 -- we try to find the source file unconditionally (i.e. if
137 -- Check_Source_Files is False).
139 elsif not Source
.Table
(S
).Source_Found
then
142 -- If we already have non-matching or missing checksums, then no
143 -- need to try going after source file, since we won't trust the
144 -- checksums in any case.
146 elsif not Source
.Table
(S
).All_Checksums_Match
then
149 -- Now we have the case where we have time stamp mismatches, and
150 -- the source file is around, but so far all checksums match. This
151 -- is the case where we need to compute the checksum from the source
152 -- file, since otherwise we would ignore the time stamp mismatches,
153 -- and that is wrong if the checksum of the source does not agree
154 -- with the checksums in the ALI files.
156 elsif Check_Source_Files
then
157 if not Checksums_Match
158 (Source
.Table
(S
).Checksum
,
159 Get_File_Checksum
(Source
.Table
(S
).Sfile
))
161 Source
.Table
(S
).All_Checksums_Match
:= False;
166 -- Loop through ALI files
168 ALIs_Loop
: for A
in ALIs
.First
.. ALIs
.Last
loop
170 -- Loop through Sdep entries in one ALI file
173 ALIs
.Table
(A
).First_Sdep
.. ALIs
.Table
(A
).Last_Sdep
175 if Sdep
.Table
(D
).Dummy_Entry
then
179 Src
:= Source_Id
(Get_Name_Table_Int
(Sdep
.Table
(D
).Sfile
));
181 -- If the time stamps match, or all checksums match, then we
182 -- are OK, otherwise we have a definite error.
184 if Sdep
.Table
(D
).Stamp
/= Source
.Table
(Src
).Stamp
185 and then not Source
.Table
(Src
).All_Checksums_Match
187 Error_Msg_File_1
:= ALIs
.Table
(A
).Sfile
;
188 Error_Msg_File_2
:= Sdep
.Table
(D
).Sfile
;
190 -- Two styles of message, depending on whether or not
191 -- the updated file is the one that must be recompiled
193 if Error_Msg_File_1
= Error_Msg_File_2
then
194 if Tolerate_Consistency_Errors
then
196 ("?{ has been modified and should be recompiled");
199 ("{ has been modified and must be recompiled");
204 Osint
.Full_Lib_File_Name
(ALIs
.Table
(A
).Afile
);
206 if Osint
.Is_Readonly_Library
(ALI_Path_Id
) then
207 if Tolerate_Consistency_Errors
then
208 Error_Msg
("?{ should be recompiled");
209 Error_Msg_File_1
:= ALI_Path_Id
;
210 Error_Msg
("?({ is obsolete and read-only)");
212 Error_Msg
("{ must be compiled");
213 Error_Msg_File_1
:= ALI_Path_Id
;
214 Error_Msg
("({ is obsolete and read-only)");
217 elsif Tolerate_Consistency_Errors
then
219 ("?{ should be recompiled ({ has been modified)");
222 Error_Msg
("{ must be recompiled ({ has been modified)");
226 if not Tolerate_Consistency_Errors
and Verbose_Mode
then
227 Error_Msg_File_1
:= Source
.Table
(Src
).Stamp_File
;
229 if Source
.Table
(Src
).Source_Found
then
231 Osint
.Full_Source_Name
(Error_Msg_File_1
);
234 Osint
.Full_Lib_File_Name
(Error_Msg_File_1
);
238 ("time stamp from { " & String (Source
.Table
(Src
).Stamp
));
240 Error_Msg_File_1
:= Sdep
.Table
(D
).Sfile
;
242 (" conflicts with { timestamp " &
243 String (Sdep
.Table
(D
).Stamp
));
246 Osint
.Full_Lib_File_Name
(ALIs
.Table
(A
).Afile
);
247 Error_Msg
(" from {");
250 -- Exit from the loop through Sdep entries once we find one
251 -- that does not match.
260 end Check_Consistency
;
262 -----------------------------------------
263 -- Check_Consistent_Dispatching_Policy --
264 -----------------------------------------
266 -- The rule is that all files for which the dispatching policy is
267 -- significant must meet the following rules:
269 -- 1. All files for which a task dispatching policy is significant must
270 -- be compiled with the same setting.
272 -- 2. If a partition contains one or more Priority_Specific_Dispatching
273 -- pragmas it cannot contain a Task_Dispatching_Policy pragma.
275 -- 3. No overlap is allowed in the priority ranges specified in
276 -- Priority_Specific_Dispatching pragmas within the same partition.
278 -- 4. If a partition contains one or more Priority_Specific_Dispatching
279 -- pragmas then the Ceiling_Locking policy is the only one allowed for
282 procedure Check_Consistent_Dispatching_Policy
is
284 -- Maximum priority value for which a Priority_Specific_Dispatching
285 -- pragma has been specified.
287 TDP_Pragma_Afile
: ALI_Id
:= No_ALI_Id
;
288 -- ALI file where a Task_Dispatching_Policy pragma appears
291 -- Consistency checks in units specifying a Task_Dispatching_Policy
293 if Task_Dispatching_Policy_Specified
/= ' ' then
294 Find_Policy
: for A1
in ALIs
.First
.. ALIs
.Last
loop
295 if ALIs
.Table
(A1
).Task_Dispatching_Policy
/= ' ' then
297 -- Store the place where the first task dispatching pragma
298 -- appears. We may need this value for issuing consistency
299 -- errors if Priority_Specific_Dispatching pragmas are used.
301 TDP_Pragma_Afile
:= A1
;
303 Check_Policy
: declare
304 Policy
: constant Character :=
305 ALIs
.Table
(A1
).Task_Dispatching_Policy
;
308 for A2
in A1
+ 1 .. ALIs
.Last
loop
309 if ALIs
.Table
(A2
).Task_Dispatching_Policy
/= ' '
311 ALIs
.Table
(A2
).Task_Dispatching_Policy
/= Policy
313 Error_Msg_File_1
:= ALIs
.Table
(A1
).Sfile
;
314 Error_Msg_File_2
:= ALIs
.Table
(A2
).Sfile
;
316 Consistency_Error_Msg
317 ("{ and { compiled with different task" &
318 " dispatching policies");
326 end loop Find_Policy
;
329 -- If no Priority_Specific_Dispatching entries, nothing else to do
331 if Specific_Dispatching
.Last
>= Specific_Dispatching
.First
then
333 -- Find out the maximum priority value for which one of the
334 -- Priority_Specific_Dispatching pragmas applies.
337 for J
in Specific_Dispatching
.First
.. Specific_Dispatching
.Last
loop
338 if Specific_Dispatching
.Table
(J
).Last_Priority
> Max_Prio
then
339 Max_Prio
:= Specific_Dispatching
.Table
(J
).Last_Priority
;
343 -- Now establish tables to be used for consistency checking
346 -- The following record type is used to record locations of the
347 -- Priority_Specific_Dispatching pragmas applying to the Priority.
349 type Specific_Dispatching_Entry
is record
350 Dispatching_Policy
: Character := ' ';
351 -- First character (upper case) of corresponding policy name
353 Afile
: ALI_Id
:= No_ALI_Id
;
354 -- ALI file that generated Priority Specific Dispatching
355 -- entry for consistency message.
358 -- Line numbers from Priority_Specific_Dispatching pragma
361 PSD_Table
: array (0 .. Max_Prio
) of Specific_Dispatching_Entry
:=
362 (others => Specific_Dispatching_Entry
'
363 (Dispatching_Policy => ' ',
366 -- Array containing an entry per priority containing the location
367 -- where there is a Priority_Specific_Dispatching pragma that
368 -- applies to the priority.
371 for F in ALIs.First .. ALIs.Last loop
372 for K in ALIs.Table (F).First_Specific_Dispatching ..
373 ALIs.Table (F).Last_Specific_Dispatching
376 DTK : Specific_Dispatching_Record
377 renames Specific_Dispatching.Table (K);
379 -- Check whether pragma Task_Dispatching_Policy and
380 -- pragma Priority_Specific_Dispatching are used in the
383 if Task_Dispatching_Policy_Specified /= ' ' then
384 Error_Msg_File_1 := ALIs.Table (F).Sfile;
386 ALIs.Table (TDP_Pragma_Afile).Sfile;
388 Error_Msg_Nat_1 := DTK.PSD_Pragma_Line;
390 Consistency_Error_Msg
391 ("Priority_Specific_Dispatching at {:#" &
392 " incompatible with Task_Dispatching_Policy at {");
395 -- Ceiling_Locking must also be specified for a partition
396 -- with at least one Priority_Specific_Dispatching
399 if Locking_Policy_Specified /= ' '
400 and then Locking_Policy_Specified /= 'C
'
402 for A in ALIs.First .. ALIs.Last loop
403 if ALIs.Table (A).Locking_Policy /= ' '
404 and then ALIs.Table (A).Locking_Policy /= 'C
'
406 Error_Msg_File_1 := ALIs.Table (F).Sfile;
407 Error_Msg_File_2 := ALIs.Table (A).Sfile;
409 Error_Msg_Nat_1 := DTK.PSD_Pragma_Line;
411 Consistency_Error_Msg
412 ("Priority_Specific_Dispatching at {:#" &
413 " incompatible with Locking_Policy at {");
418 -- Check overlapping priority ranges
420 Find_Overlapping : for Prio in
421 DTK.First_Priority .. DTK.Last_Priority
423 if PSD_Table (Prio).Afile = No_ALI_Id then
425 (Dispatching_Policy => DTK.Dispatching_Policy,
426 Afile => F, Loc => DTK.PSD_Pragma_Line);
428 elsif PSD_Table (Prio).Dispatching_Policy /=
429 DTK.Dispatching_Policy
433 ALIs.Table (PSD_Table (Prio).Afile).Sfile;
434 Error_Msg_File_2 := ALIs.Table (F).Sfile;
435 Error_Msg_Nat_1 := PSD_Table (Prio).Loc;
436 Error_Msg_Nat_2 := DTK.PSD_Pragma_Line;
438 Consistency_Error_Msg
439 ("overlapping priority ranges at {:# and {:#");
441 exit Find_Overlapping;
443 end loop Find_Overlapping;
449 end Check_Consistent_Dispatching_Policy;
451 ---------------------------------------------------
452 -- Check_Consistent_Dynamic_Elaboration_Checking --
453 ---------------------------------------------------
455 -- The rule here is that if a unit has dynamic elaboration checks,
456 -- then any unit it withs must meet one of the following criteria:
458 -- 1. There is a pragma Elaborate_All for the with'ed unit
459 -- 2. The with'ed unit was compiled with dynamic elaboration checks
460 -- 3. The with'ed unit has pragma Preelaborate or Pure
461 -- 4. It is an internal GNAT unit (including children of GNAT)
462 -- 5. It is an interface of a Stand-Alone Library
464 procedure Check_Consistent_Dynamic_Elaboration_Checking is
466 if Dynamic_Elaboration_Checks_Specified then
467 for U in First_Unit_Entry .. Units.Last loop
469 UR : Unit_Record renames Units.Table (U);
472 if UR.Dynamic_Elab then
473 for W in UR.First_With .. UR.Last_With loop
475 WR : With_Record renames Withs.Table (W);
478 if Get_Name_Table_Int (WR.Uname) /= 0 then
480 WU : Unit_Record renames
483 (Get_Name_Table_Int (WR.Uname)));
486 -- Case 1. Elaborate_All for with'ed unit
488 if WR.Elaborate_All then
491 -- Case 2. With'ed unit has dynamic elab checks
493 elsif WU.Dynamic_Elab then
496 -- Case 3. With'ed unit is Preelaborate or Pure
498 elsif WU.Preelab or else WU.Pure then
501 -- Case 4. With'ed unit is internal file
503 elsif Is_Internal_File_Name (WU.Sfile) then
506 -- Case 5. With'ed unit is a SAL interface
508 elsif WU.SAL_Interface then
511 -- Issue warning, not one of the safe cases
514 Error_Msg_File_1 := UR.Sfile;
516 ("?{ has dynamic elaboration checks " &
519 Error_Msg_File_1 := WU.Sfile;
521 ("? { which has static elaboration " &
524 Warnings_Detected := Warnings_Detected + 1;
534 end Check_Consistent_Dynamic_Elaboration_Checking;
536 ---------------------------------------
537 -- Check_Consistent_Interrupt_States --
538 ---------------------------------------
540 -- The rule is that if the state of a given interrupt is specified
541 -- in more than one unit, it must be specified with a consistent state.
543 procedure Check_Consistent_Interrupt_States is
547 -- If no Interrupt_State entries, nothing to do
549 if Interrupt_States.Last < Interrupt_States.First then
553 -- First find out the maximum interrupt value
556 for J in Interrupt_States.First .. Interrupt_States.Last loop
557 if Interrupt_States.Table (J).Interrupt_Id > Max_Intrup then
558 Max_Intrup := Interrupt_States.Table (J).Interrupt_Id;
562 -- Now establish tables to be used for consistency checking
565 Istate : array (0 .. Max_Intrup) of Character := (others => 'n
');
566 -- Interrupt state entries, 'u
'/'s
'/'r
' or 'n
' to indicate an
567 -- entry that has not been set.
569 Afile : array (0 .. Max_Intrup) of ALI_Id;
570 -- ALI file that generated Istate entry for consistency message
572 Loc : array (0 .. Max_Intrup) of Nat;
573 -- Line numbers from IS pragma generating Istate entry
576 -- Interrupt number from entry being tested
579 -- Interrupt state from entry being tested
582 -- Line number from entry being tested
585 for F in ALIs.First .. ALIs.Last loop
586 for K in ALIs.Table (F).First_Interrupt_State ..
587 ALIs.Table (F).Last_Interrupt_State
589 Inum := Interrupt_States.Table (K).Interrupt_Id;
590 Stat := Interrupt_States.Table (K).Interrupt_State;
591 Lnum := Interrupt_States.Table (K).IS_Pragma_Line;
593 if Istate (Inum) = 'n
' then
594 Istate (Inum) := Stat;
598 elsif Istate (Inum) /= Stat then
599 Error_Msg_File_1 := ALIs.Table (Afile (Inum)).Sfile;
600 Error_Msg_File_2 := ALIs.Table (F).Sfile;
601 Error_Msg_Nat_1 := Loc (Inum);
602 Error_Msg_Nat_2 := Lnum;
604 Consistency_Error_Msg
605 ("inconsistent interrupt states at {:# and {:#");
610 end Check_Consistent_Interrupt_States;
612 -------------------------------------
613 -- Check_Consistent_Locking_Policy --
614 -------------------------------------
616 -- The rule is that all files for which the locking policy is
617 -- significant must be compiled with the same setting.
619 procedure Check_Consistent_Locking_Policy is
621 -- First search for a unit specifying a policy and then
622 -- check all remaining units against it.
624 Find_Policy : for A1 in ALIs.First .. ALIs.Last loop
625 if ALIs.Table (A1).Locking_Policy /= ' ' then
626 Check_Policy : declare
627 Policy : constant Character := ALIs.Table (A1).Locking_Policy;
630 for A2 in A1 + 1 .. ALIs.Last loop
631 if ALIs.Table (A2).Locking_Policy /= ' '
633 ALIs.Table (A2).Locking_Policy /= Policy
635 Error_Msg_File_1 := ALIs.Table (A1).Sfile;
636 Error_Msg_File_2 := ALIs.Table (A2).Sfile;
638 Consistency_Error_Msg
639 ("{ and { compiled with different locking policies");
647 end loop Find_Policy;
648 end Check_Consistent_Locking_Policy;
650 ----------------------------------------------
651 -- Check_Consistent_No_Component_Reordering --
652 ----------------------------------------------
654 -- This routine checks for a consistent No_Component_Reordering setting.
655 -- Note that internal units are excluded from this check, since we don't
656 -- in any case allow the pragma to affect types in internal units, and
657 -- there is thus no requirement to recompile the run-time with the setting.
659 procedure Check_Consistent_No_Component_Reordering is
660 OK : Boolean := True;
662 -- Check that all entries have No_Component_Reordering set
664 for A1 in ALIs.First .. ALIs.Last loop
665 if not Is_Internal_File_Name (ALIs.Table (A1).Sfile)
666 and then not ALIs.Table (A1).No_Component_Reordering
679 -- Here we have an inconsistency
681 Consistency_Error_Msg
682 ("some but not all files compiled with No_Component_Reordering");
685 Write_Str ("files compiled with No_Component_Reordering");
688 for A1 in ALIs.First .. ALIs.Last loop
689 if not Is_Internal_File_Name (ALIs.Table (A1).Sfile)
690 and then ALIs.Table (A1).No_Component_Reordering
693 Write_Name (ALIs.Table (A1).Sfile);
699 Write_Str ("files compiled without No_Component_Reordering");
702 for A1 in ALIs.First .. ALIs.Last loop
703 if not Is_Internal_File_Name (ALIs.Table (A1).Sfile)
704 and then not ALIs.Table (A1).No_Component_Reordering
707 Write_Name (ALIs.Table (A1).Sfile);
711 end Check_Consistent_No_Component_Reordering;
713 ----------------------------------------
714 -- Check_Consistent_Normalize_Scalars --
715 ----------------------------------------
717 -- The rule is that if any unit is compiled with Normalize_Scalars,
718 -- then all other units in the partition must also be compiled with
719 -- Normalize_Scalars in effect.
721 -- There is some issue as to whether this consistency check is desirable,
722 -- it is certainly required at the moment by the RM. We should keep a watch
723 -- on the ARG and HRG deliberations here. GNAT no longer depends on this
724 -- consistency (it used to do so, but that is no longer the case, since
725 -- pragma Initialize_Scalars pragma does not require consistency.)
727 procedure Check_Consistent_Normalize_Scalars is
729 if Normalize_Scalars_Specified and No_Normalize_Scalars_Specified then
730 Consistency_Error_Msg
731 ("some but not all files compiled with Normalize_Scalars");
734 Write_Str ("files compiled with Normalize_Scalars");
737 for A1 in ALIs.First .. ALIs.Last loop
738 if ALIs.Table (A1).Normalize_Scalars then
740 Write_Name (ALIs.Table (A1).Sfile);
746 Write_Str ("files compiled without Normalize_Scalars");
749 for A1 in ALIs.First .. ALIs.Last loop
750 if not ALIs.Table (A1).Normalize_Scalars then
752 Write_Name (ALIs.Table (A1).Sfile);
757 end Check_Consistent_Normalize_Scalars;
759 -----------------------------------------
760 -- Check_Consistent_Optimize_Alignment --
761 -----------------------------------------
763 -- The rule is that all units which depend on the global default setting
764 -- of Optimize_Alignment must be compiled with the same setting for this
765 -- default. Units which specify an explicit local value for this setting
766 -- are exempt from the consistency rule (this includes all internal units).
768 procedure Check_Consistent_Optimize_Alignment is
769 OA_Setting : Character := ' ';
770 -- Reset when we find a unit that depends on the default and does
771 -- not have a local specification of the Optimize_Alignment setting.
773 OA_Unit : Unit_Id := No_Unit_Id;
774 -- Id of unit from which OA_Setting was set
779 for U in First_Unit_Entry .. Units.Last loop
780 C := Units.Table (U).Optimize_Alignment;
783 if OA_Setting = ' ' then
787 elsif OA_Setting = C then
791 pragma Assert (Present (OA_Unit));
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 Error_Msg_File_1 := ALIs.Table (A1).Sfile;
1250 Error_Msg_File_2 := ALIs.Table (ALIs.First).Sfile;
1252 Consistency_Error_Msg
1253 ("{ and { compiled with different exception handling "
1256 end loop Check_Mechanism;
1257 end Check_Consistent_Exception_Handling;
1259 -------------------------------
1260 -- Check_Duplicated_Subunits --
1261 -------------------------------
1263 procedure Check_Duplicated_Subunits is
1265 for J in Sdep.First .. Sdep.Last loop
1266 if Sdep.Table (J).Subunit_Name /= No_Name then
1267 Get_Decoded_Name_String (Sdep.Table (J).Subunit_Name);
1268 Name_Len := Name_Len + 2;
1269 Name_Buffer (Name_Len - 1) := '%';
1271 -- See if there is a body or spec with the same name
1273 for K in Boolean loop
1275 Name_Buffer (Name_Len) := 'b
';
1277 Name_Buffer (Name_Len) := 's
';
1281 Unit : constant Unit_Name_Type := Name_Find;
1282 Info : constant Int := Get_Name_Table_Int (Unit);
1287 Write_Str ("error: subunit """);
1288 Write_Name_Decoded (Sdep.Table (J).Subunit_Name);
1289 Write_Str (""" in file """);
1290 Write_Name_Decoded (Sdep.Table (J).Sfile);
1293 Write_Str (" has same name as unit
""");
1294 Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
1295 Write_Str (""" found
in file
""");
1296 Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
1299 Write_Str (" this is not allowed within a single "
1300 & "partition (RM 10.2(19))");
1302 Osint.Exit_Program (Osint.E_Fatal);
1308 end Check_Duplicated_Subunits;
1310 --------------------
1311 -- Check_Versions --
1312 --------------------
1314 procedure Check_Versions is
1315 VL : constant Natural := ALIs.Table (ALIs.First).Ver_Len;
1318 for A in ALIs.First .. ALIs.Last loop
1319 if ALIs.Table (A).Ver_Len /= VL
1320 or else ALIs.Table (A).Ver (1 .. VL) /=
1321 ALIs.Table (ALIs.First).Ver (1 .. VL)
1323 -- Version mismatch found; generate error message.
1328 Prefix : constant String :=
1329 Verbose_Library_Version
1330 (1 .. Verbose_Library_Version'Length
1331 - Library_Version'Length);
1333 type ALI_Version is record
1334 Primary, Secondary : Int range -1 .. Int'Last;
1337 No_Version : constant ALI_Version := (-1, -1);
1339 function Remove_Prefix (S : String) return String is
1340 (S (S'First + Prefix'Length .. S'Last));
1342 function Extract_Version (S : String) return ALI_Version;
1343 -- Attempts to extract and return a pair of nonnegative library
1344 -- version numbers from the given string; if unsuccessful,
1345 -- then returns No_Version.
1347 ---------------------
1348 -- Extract_Version --
1349 ---------------------
1351 function Extract_Version (S : String) return ALI_Version is
1352 pragma Assert (S'First = 1);
1354 function Int_Value (Img : String) return Int;
1355 -- Using Int'Value leads to complications in
1356 -- building the binder, so DIY.
1362 function Int_Value (Img : String) return Int is
1365 if Img'Length in 1 .. 9
1366 and then (for all C of Img => C in '0' .. '9')
1369 Result := (10 * Result) +
1370 (Character'Pos (C) - Character'Pos ('0'));
1379 if S'Length > Prefix'Length
1380 and then S (1 .. Prefix'Length) = Prefix
1383 Suffix : constant String := Remove_Prefix (S);
1384 Dot_Found : Boolean := False;
1385 Primary, Secondary : Int;
1387 for Dot_Index in Suffix'Range loop
1388 if Suffix (Dot_Index) = '.' then
1391 Int_Value (Suffix (Suffix'First
1394 Int_Value (Suffix (Dot_Index + 1
1400 if not Dot_Found then
1401 Primary := Int_Value (Suffix);
1405 if Primary /= -1 and Secondary /= -1 then
1406 return (Primary => Primary,
1407 Secondary => Secondary);
1412 end Extract_Version;
1416 V1_Text : constant String :=
1417 ALIs.Table (A).Ver (1 .. ALIs.Table (A).Ver_Len);
1418 V2_Text : constant String :=
1419 ALIs.Table (ALIs.First).Ver (1 .. VL);
1420 V1 : constant ALI_Version := Extract_Version (V1_Text);
1421 V2 : constant ALI_Version := Extract_Version (V2_Text);
1423 Include_Version_Numbers_In_Message : constant Boolean :=
1424 V1 /= V2 and V1 /= No_Version and V2 /= No_Version;
1426 Error_Msg_File_1 := ALIs.Table (A).Sfile;
1427 Error_Msg_File_2 := ALIs.Table (ALIs.First).Sfile;
1429 if Include_Version_Numbers_In_Message then
1430 if V1.Secondary = V2.Secondary then
1431 -- Excluding equal secondary values from error
1432 -- message text matters for generating reproducible
1433 -- regression test outputs.
1435 Error_Msg_Nat_1 := V1.Primary;
1436 Error_Msg_Nat_2 := V2.Primary;
1437 Consistency_Error_Msg
1438 ("{ and { compiled with different GNAT versions"
1441 Consistency_Error_Msg
1442 ("{ and { compiled with different GNAT versions"
1444 & Remove_Prefix (V1_Text)
1446 & Remove_Prefix (V2_Text));
1449 Consistency_Error_Msg
1450 ("{ and { compiled with different GNAT versions");
1457 ---------------------------
1458 -- Consistency_Error_Msg --
1459 ---------------------------
1461 procedure Consistency_Error_Msg (Msg : String) is
1463 if Tolerate_Consistency_Errors then
1465 -- If consistency errors are tolerated,
1466 -- output the message as a warning.
1468 Error_Msg ('?
' & Msg);
1470 -- Otherwise the consistency error is a true error
1475 end Consistency_Error_Msg;
1481 function Same_Unit (U1 : Unit_Name_Type; U2 : Name_Id) return Boolean is
1483 -- Note, the string U1 has a terminating %s or %b, U2 does not
1485 if Length_Of_Name (U1) - 2 = Length_Of_Name (U2) then
1486 Get_Name_String (U1);
1489 U1_Str : constant String := Name_Buffer (1 .. Name_Len - 2);
1491 Get_Name_String (U2);
1492 return U1_Str = Name_Buffer (1 .. Name_Len);