1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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_Normalize_Scalars
;
53 procedure Check_Consistent_Optimize_Alignment
;
54 procedure Check_Consistent_Partition_Elaboration_Policy
;
55 procedure Check_Consistent_Queuing_Policy
;
56 procedure Check_Consistent_Restrictions
;
57 procedure Check_Consistent_Restriction_No_Default_Initialization
;
58 procedure Check_Consistent_SSO_Default
;
59 procedure Check_Consistent_Zero_Cost_Exception_Handling
;
61 procedure Consistency_Error_Msg
(Msg
: String);
62 -- Produce an error or a warning message, depending on whether an
63 -- inconsistent configuration is permitted or not.
65 function Same_Unit
(U1
: Unit_Name_Type
; U2
: Name_Id
) return Boolean;
66 -- Used to compare two unit names for No_Dependence checks. U1 is in
67 -- standard unit name format, and U2 is in literal form with periods.
69 -------------------------------------
70 -- Check_Configuration_Consistency --
71 -------------------------------------
73 procedure Check_Configuration_Consistency
is
75 if Queuing_Policy_Specified
/= ' ' then
76 Check_Consistent_Queuing_Policy
;
79 if Locking_Policy_Specified
/= ' ' then
80 Check_Consistent_Locking_Policy
;
83 if Partition_Elaboration_Policy_Specified
/= ' ' then
84 Check_Consistent_Partition_Elaboration_Policy
;
87 if SSO_Default_Specified
then
88 Check_Consistent_SSO_Default
;
91 if Zero_Cost_Exceptions_Specified
then
92 Check_Consistent_Zero_Cost_Exception_Handling
;
95 Check_Consistent_Normalize_Scalars
;
96 Check_Consistent_Optimize_Alignment
;
97 Check_Consistent_Dynamic_Elaboration_Checking
;
98 Check_Consistent_Restrictions
;
99 Check_Consistent_Restriction_No_Default_Initialization
;
100 Check_Consistent_Interrupt_States
;
101 Check_Consistent_Dispatching_Policy
;
102 end Check_Configuration_Consistency
;
104 -----------------------
105 -- Check_Consistency --
106 -----------------------
108 procedure Check_Consistency
is
110 -- Source file Id for this Sdep entry
112 ALI_Path_Id
: File_Name_Type
;
115 -- First, we go through the source table to see if there are any cases
116 -- in which we should go after source files and compute checksums of
117 -- the source files. We need to do this for any file for which we have
118 -- mismatching time stamps and (so far) matching checksums.
120 for S
in Source
.First
.. Source
.Last
loop
122 -- If all time stamps for a file match, then there is nothing to
123 -- do, since we will not be checking checksums in that case anyway
125 if Source
.Table
(S
).All_Timestamps_Match
then
128 -- If we did not find the source file, then we can't compute its
129 -- checksum anyway. Note that when we have a time stamp mismatch,
130 -- we try to find the source file unconditionally (i.e. if
131 -- Check_Source_Files is False).
133 elsif not Source
.Table
(S
).Source_Found
then
136 -- If we already have non-matching or missing checksums, then no
137 -- need to try going after source file, since we won't trust the
138 -- checksums in any case.
140 elsif not Source
.Table
(S
).All_Checksums_Match
then
143 -- Now we have the case where we have time stamp mismatches, and
144 -- the source file is around, but so far all checksums match. This
145 -- is the case where we need to compute the checksum from the source
146 -- file, since otherwise we would ignore the time stamp mismatches,
147 -- and that is wrong if the checksum of the source does not agree
148 -- with the checksums in the ALI files.
150 elsif Check_Source_Files
then
151 if not Checksums_Match
152 (Source
.Table
(S
).Checksum
,
153 Get_File_Checksum
(Source
.Table
(S
).Sfile
))
155 Source
.Table
(S
).All_Checksums_Match
:= False;
160 -- Loop through ALI files
162 ALIs_Loop
: for A
in ALIs
.First
.. ALIs
.Last
loop
164 -- Loop through Sdep entries in one ALI file
167 ALIs
.Table
(A
).First_Sdep
.. ALIs
.Table
(A
).Last_Sdep
169 if Sdep
.Table
(D
).Dummy_Entry
then
173 Src
:= Source_Id
(Get_Name_Table_Info
(Sdep
.Table
(D
).Sfile
));
175 -- If the time stamps match, or all checksums match, then we
176 -- are OK, otherwise we have a definite error.
178 if Sdep
.Table
(D
).Stamp
/= Source
.Table
(Src
).Stamp
179 and then not Source
.Table
(Src
).All_Checksums_Match
181 Error_Msg_File_1
:= ALIs
.Table
(A
).Sfile
;
182 Error_Msg_File_2
:= Sdep
.Table
(D
).Sfile
;
184 -- Two styles of message, depending on whether or not
185 -- the updated file is the one that must be recompiled
187 if Error_Msg_File_1
= Error_Msg_File_2
then
188 if Tolerate_Consistency_Errors
then
190 ("?{ has been modified and should be recompiled");
193 ("{ has been modified and must be recompiled");
198 Osint
.Full_Lib_File_Name
(ALIs
.Table
(A
).Afile
);
200 if Osint
.Is_Readonly_Library
(ALI_Path_Id
) then
201 if Tolerate_Consistency_Errors
then
202 Error_Msg
("?{ should be recompiled");
203 Error_Msg_File_1
:= ALI_Path_Id
;
204 Error_Msg
("?({ is obsolete and read-only)");
206 Error_Msg
("{ must be compiled");
207 Error_Msg_File_1
:= ALI_Path_Id
;
208 Error_Msg
("({ is obsolete and read-only)");
211 elsif Tolerate_Consistency_Errors
then
213 ("?{ should be recompiled ({ has been modified)");
216 Error_Msg
("{ must be recompiled ({ has been modified)");
220 if (not Tolerate_Consistency_Errors
) and Verbose_Mode
then
221 Error_Msg_File_1
:= Source
.Table
(Src
).Stamp_File
;
223 if Source
.Table
(Src
).Source_Found
then
225 Osint
.Full_Source_Name
(Error_Msg_File_1
);
228 Osint
.Full_Lib_File_Name
(Error_Msg_File_1
);
232 ("time stamp from { " & String (Source
.Table
(Src
).Stamp
));
234 Error_Msg_File_1
:= Sdep
.Table
(D
).Sfile
;
236 (" conflicts with { timestamp " &
237 String (Sdep
.Table
(D
).Stamp
));
240 Osint
.Full_Lib_File_Name
(ALIs
.Table
(A
).Afile
);
241 Error_Msg
(" from {");
244 -- Exit from the loop through Sdep entries once we find one
245 -- that does not match.
254 end Check_Consistency
;
256 -----------------------------------------
257 -- Check_Consistent_Dispatching_Policy --
258 -----------------------------------------
260 -- The rule is that all files for which the dispatching policy is
261 -- significant must meet the following rules:
263 -- 1. All files for which a task dispatching policy is significant must
264 -- be compiled with the same setting.
266 -- 2. If a partition contains one or more Priority_Specific_Dispatching
267 -- pragmas it cannot contain a Task_Dispatching_Policy pragma.
269 -- 3. No overlap is allowed in the priority ranges specified in
270 -- Priority_Specific_Dispatching pragmas within the same partition.
272 -- 4. If a partition contains one or more Priority_Specific_Dispatching
273 -- pragmas then the Ceiling_Locking policy is the only one allowed for
276 procedure Check_Consistent_Dispatching_Policy
is
278 -- Maximum priority value for which a Priority_Specific_Dispatching
279 -- pragma has been specified.
281 TDP_Pragma_Afile
: ALI_Id
:= No_ALI_Id
;
282 -- ALI file where a Task_Dispatching_Policy pragma appears
285 -- Consistency checks in units specifying a Task_Dispatching_Policy
287 if Task_Dispatching_Policy_Specified
/= ' ' then
288 Find_Policy
: for A1
in ALIs
.First
.. ALIs
.Last
loop
289 if ALIs
.Table
(A1
).Task_Dispatching_Policy
/= ' ' then
291 -- Store the place where the first task dispatching pragma
292 -- appears. We may need this value for issuing consistency
293 -- errors if Priority_Specific_Dispatching pragmas are used.
295 TDP_Pragma_Afile
:= A1
;
297 Check_Policy
: declare
298 Policy
: constant Character :=
299 ALIs
.Table
(A1
).Task_Dispatching_Policy
;
302 for A2
in A1
+ 1 .. ALIs
.Last
loop
303 if ALIs
.Table
(A2
).Task_Dispatching_Policy
/= ' '
305 ALIs
.Table
(A2
).Task_Dispatching_Policy
/= Policy
307 Error_Msg_File_1
:= ALIs
.Table
(A1
).Sfile
;
308 Error_Msg_File_2
:= ALIs
.Table
(A2
).Sfile
;
310 Consistency_Error_Msg
311 ("{ and { compiled with different task" &
312 " dispatching policies");
320 end loop Find_Policy
;
323 -- If no Priority_Specific_Dispatching entries, nothing else to do
325 if Specific_Dispatching
.Last
>= Specific_Dispatching
.First
then
327 -- Find out the maximum priority value for which one of the
328 -- Priority_Specific_Dispatching pragmas applies.
331 for J
in Specific_Dispatching
.First
.. Specific_Dispatching
.Last
loop
332 if Specific_Dispatching
.Table
(J
).Last_Priority
> Max_Prio
then
333 Max_Prio
:= Specific_Dispatching
.Table
(J
).Last_Priority
;
337 -- Now establish tables to be used for consistency checking
340 -- The following record type is used to record locations of the
341 -- Priority_Specific_Dispatching pragmas applying to the Priority.
343 type Specific_Dispatching_Entry
is record
344 Dispatching_Policy
: Character := ' ';
345 -- First character (upper case) of corresponding policy name
347 Afile
: ALI_Id
:= No_ALI_Id
;
348 -- ALI file that generated Priority Specific Dispatching
349 -- entry for consistency message.
352 -- Line numbers from Priority_Specific_Dispatching pragma
355 PSD_Table
: array (0 .. Max_Prio
) of Specific_Dispatching_Entry
:=
356 (others => Specific_Dispatching_Entry
'
357 (Dispatching_Policy => ' ',
360 -- Array containing an entry per priority containing the location
361 -- where there is a Priority_Specific_Dispatching pragma that
362 -- applies to the priority.
365 for F in ALIs.First .. ALIs.Last loop
366 for K in ALIs.Table (F).First_Specific_Dispatching ..
367 ALIs.Table (F).Last_Specific_Dispatching
370 DTK : Specific_Dispatching_Record
371 renames Specific_Dispatching.Table (K);
373 -- Check whether pragma Task_Dispatching_Policy and
374 -- pragma Priority_Specific_Dispatching are used in the
377 if Task_Dispatching_Policy_Specified /= ' ' then
378 Error_Msg_File_1 := ALIs.Table (F).Sfile;
380 ALIs.Table (TDP_Pragma_Afile).Sfile;
382 Error_Msg_Nat_1 := DTK.PSD_Pragma_Line;
384 Consistency_Error_Msg
385 ("Priority_Specific_Dispatching at {:#" &
386 " incompatible with Task_Dispatching_Policy at {");
389 -- Ceiling_Locking must also be specified for a partition
390 -- with at least one Priority_Specific_Dispatching
393 if Locking_Policy_Specified /= ' '
394 and then Locking_Policy_Specified /= 'C
'
396 for A in ALIs.First .. ALIs.Last loop
397 if ALIs.Table (A).Locking_Policy /= ' '
398 and then ALIs.Table (A).Locking_Policy /= 'C
'
400 Error_Msg_File_1 := ALIs.Table (F).Sfile;
401 Error_Msg_File_2 := ALIs.Table (A).Sfile;
403 Error_Msg_Nat_1 := DTK.PSD_Pragma_Line;
405 Consistency_Error_Msg
406 ("Priority_Specific_Dispatching at {:#" &
407 " incompatible with Locking_Policy at {");
412 -- Check overlapping priority ranges
414 Find_Overlapping : for Prio in
415 DTK.First_Priority .. DTK.Last_Priority
417 if PSD_Table (Prio).Afile = No_ALI_Id then
419 (Dispatching_Policy => DTK.Dispatching_Policy,
420 Afile => F, Loc => DTK.PSD_Pragma_Line);
422 elsif PSD_Table (Prio).Dispatching_Policy /=
423 DTK.Dispatching_Policy
427 ALIs.Table (PSD_Table (Prio).Afile).Sfile;
428 Error_Msg_File_2 := ALIs.Table (F).Sfile;
429 Error_Msg_Nat_1 := PSD_Table (Prio).Loc;
430 Error_Msg_Nat_2 := DTK.PSD_Pragma_Line;
432 Consistency_Error_Msg
433 ("overlapping priority ranges at {:# and {:#");
435 exit Find_Overlapping;
437 end loop Find_Overlapping;
443 end Check_Consistent_Dispatching_Policy;
445 ---------------------------------------------------
446 -- Check_Consistent_Dynamic_Elaboration_Checking --
447 ---------------------------------------------------
449 -- The rule here is that if a unit has dynamic elaboration checks,
450 -- then any unit it withs must meeting one of the following criteria:
452 -- 1. There is a pragma Elaborate_All for the with'ed unit
453 -- 2. The with'ed unit was compiled with dynamic elaboration checks
454 -- 3. The with'ed unit has pragma Preelaborate or Pure
455 -- 4. It is an internal GNAT unit (including children of GNAT)
457 procedure Check_Consistent_Dynamic_Elaboration_Checking is
459 if Dynamic_Elaboration_Checks_Specified then
460 for U in First_Unit_Entry .. Units.Last loop
462 UR : Unit_Record renames Units.Table (U);
465 if UR.Dynamic_Elab then
466 for W in UR.First_With .. UR.Last_With loop
468 WR : With_Record renames Withs.Table (W);
471 if Get_Name_Table_Info (WR.Uname) /= 0 then
473 WU : Unit_Record renames
476 (Get_Name_Table_Info (WR.Uname)));
479 -- Case 1. Elaborate_All for with'ed unit
481 if WR.Elaborate_All then
484 -- Case 2. With'ed unit has dynamic elab checks
486 elsif WU.Dynamic_Elab then
489 -- Case 3. With'ed unit is Preelaborate or Pure
491 elsif WU.Preelab or else WU.Pure then
494 -- Case 4. With'ed unit is internal file
496 elsif Is_Internal_File_Name (WU.Sfile) then
499 -- Issue warning, not one of the safe cases
502 Error_Msg_File_1 := UR.Sfile;
504 ("?{ has dynamic elaboration checks " &
507 Error_Msg_File_1 := WU.Sfile;
509 ("? { which has static elaboration " &
512 Warnings_Detected := Warnings_Detected - 1;
522 end Check_Consistent_Dynamic_Elaboration_Checking;
524 ---------------------------------------
525 -- Check_Consistent_Interrupt_States --
526 ---------------------------------------
528 -- The rule is that if the state of a given interrupt is specified
529 -- in more than one unit, it must be specified with a consistent state.
531 procedure Check_Consistent_Interrupt_States is
535 -- If no Interrupt_State entries, nothing to do
537 if Interrupt_States.Last < Interrupt_States.First then
541 -- First find out the maximum interrupt value
544 for J in Interrupt_States.First .. Interrupt_States.Last loop
545 if Interrupt_States.Table (J).Interrupt_Id > Max_Intrup then
546 Max_Intrup := Interrupt_States.Table (J).Interrupt_Id;
550 -- Now establish tables to be used for consistency checking
553 Istate : array (0 .. Max_Intrup) of Character := (others => 'n
');
554 -- Interrupt state entries, 'u
'/'s
'/'r
' or 'n
' to indicate an
555 -- entry that has not been set.
557 Afile : array (0 .. Max_Intrup) of ALI_Id;
558 -- ALI file that generated Istate entry for consistency message
560 Loc : array (0 .. Max_Intrup) of Nat;
561 -- Line numbers from IS pragma generating Istate entry
564 -- Interrupt number from entry being tested
567 -- Interrupt state from entry being tested
570 -- Line number from entry being tested
573 for F in ALIs.First .. ALIs.Last loop
574 for K in ALIs.Table (F).First_Interrupt_State ..
575 ALIs.Table (F).Last_Interrupt_State
577 Inum := Interrupt_States.Table (K).Interrupt_Id;
578 Stat := Interrupt_States.Table (K).Interrupt_State;
579 Lnum := Interrupt_States.Table (K).IS_Pragma_Line;
581 if Istate (Inum) = 'n
' then
582 Istate (Inum) := Stat;
586 elsif Istate (Inum) /= Stat then
587 Error_Msg_File_1 := ALIs.Table (Afile (Inum)).Sfile;
588 Error_Msg_File_2 := ALIs.Table (F).Sfile;
589 Error_Msg_Nat_1 := Loc (Inum);
590 Error_Msg_Nat_2 := Lnum;
592 Consistency_Error_Msg
593 ("inconsistent interrupt states at {:# and {:#");
598 end Check_Consistent_Interrupt_States;
600 -------------------------------------
601 -- Check_Consistent_Locking_Policy --
602 -------------------------------------
604 -- The rule is that all files for which the locking policy is
605 -- significant must be compiled with the same setting.
607 procedure Check_Consistent_Locking_Policy is
609 -- First search for a unit specifying a policy and then
610 -- check all remaining units against it.
612 Find_Policy : for A1 in ALIs.First .. ALIs.Last loop
613 if ALIs.Table (A1).Locking_Policy /= ' ' then
614 Check_Policy : declare
615 Policy : constant Character := ALIs.Table (A1).Locking_Policy;
618 for A2 in A1 + 1 .. ALIs.Last loop
619 if ALIs.Table (A2).Locking_Policy /= ' '
621 ALIs.Table (A2).Locking_Policy /= Policy
623 Error_Msg_File_1 := ALIs.Table (A1).Sfile;
624 Error_Msg_File_2 := ALIs.Table (A2).Sfile;
626 Consistency_Error_Msg
627 ("{ and { compiled with different locking policies");
635 end loop Find_Policy;
636 end Check_Consistent_Locking_Policy;
638 ----------------------------------------
639 -- Check_Consistent_Normalize_Scalars --
640 ----------------------------------------
642 -- The rule is that if any unit is compiled with Normalized_Scalars,
643 -- then all other units in the partition must also be compiled with
644 -- Normalized_Scalars in effect.
646 -- There is some issue as to whether this consistency check is desirable,
647 -- it is certainly required at the moment by the RM. We should keep a watch
648 -- on the ARG and HRG deliberations here. GNAT no longer depends on this
649 -- consistency (it used to do so, but that is no longer the case, since
650 -- pragma Initialize_Scalars pragma does not require consistency.)
652 procedure Check_Consistent_Normalize_Scalars is
654 if Normalize_Scalars_Specified and No_Normalize_Scalars_Specified then
655 Consistency_Error_Msg
656 ("some but not all files compiled with Normalize_Scalars");
659 Write_Str ("files compiled with Normalize_Scalars");
662 for A1 in ALIs.First .. ALIs.Last loop
663 if ALIs.Table (A1).Normalize_Scalars then
665 Write_Name (ALIs.Table (A1).Sfile);
671 Write_Str ("files compiled without Normalize_Scalars");
674 for A1 in ALIs.First .. ALIs.Last loop
675 if not ALIs.Table (A1).Normalize_Scalars then
677 Write_Name (ALIs.Table (A1).Sfile);
682 end Check_Consistent_Normalize_Scalars;
684 -----------------------------------------
685 -- Check_Consistent_Optimize_Alignment --
686 -----------------------------------------
688 -- The rule is that all units which depend on the global default setting
689 -- of Optimize_Alignment must be compiled with the same setting for this
690 -- default. Units which specify an explicit local value for this setting
691 -- are exempt from the consistency rule (this includes all internal units).
693 procedure Check_Consistent_Optimize_Alignment is
694 OA_Setting : Character := ' ';
695 -- Reset when we find a unit that depends on the default and does
696 -- not have a local specification of the Optimize_Alignment setting.
699 -- Id of unit from which OA_Setting was set
704 for U in First_Unit_Entry .. Units.Last loop
705 C := Units.Table (U).Optimize_Alignment;
708 if OA_Setting = ' ' then
712 elsif OA_Setting = C then
716 Error_Msg_Unit_1 := Units.Table (OA_Unit).Uname;
717 Error_Msg_Unit_2 := Units.Table (U).Uname;
719 Consistency_Error_Msg
720 ("$ and $ compiled with different "
721 & "default Optimize_Alignment settings");
726 end Check_Consistent_Optimize_Alignment;
728 ---------------------------------------------------
729 -- Check_Consistent_Partition_Elaboration_Policy --
730 ---------------------------------------------------
732 -- The rule is that all files for which the partition elaboration policy is
733 -- significant must be compiled with the same setting.
735 procedure Check_Consistent_Partition_Elaboration_Policy is
737 -- First search for a unit specifying a policy and then
738 -- check all remaining units against it.
740 Find_Policy : for A1 in ALIs.First .. ALIs.Last loop
741 if ALIs.Table (A1).Partition_Elaboration_Policy /= ' ' then
742 Check_Policy : declare
743 Policy : constant Character :=
744 ALIs.Table (A1).Partition_Elaboration_Policy;
747 for A2 in A1 + 1 .. ALIs.Last loop
748 if ALIs.Table (A2).Partition_Elaboration_Policy /= ' '
750 ALIs.Table (A2).Partition_Elaboration_Policy /= Policy
752 Error_Msg_File_1 := ALIs.Table (A1).Sfile;
753 Error_Msg_File_2 := ALIs.Table (A2).Sfile;
755 Consistency_Error_Msg
756 ("{ and { compiled with different partition "
757 & "elaboration policies");
763 -- A No_Task_Hierarchy restriction must be specified for the
764 -- Sequential policy (RM H.6(6/2)).
766 if Partition_Elaboration_Policy_Specified = 'S
'
767 and then not Cumulative_Restrictions.Set (No_Task_Hierarchy)
769 Error_Msg_File_1 := ALIs.Table (A1).Sfile;
771 ("{ has sequential partition elaboration policy, but no");
773 ("pragma Restrictions (No_Task_Hierarchy) was specified");
778 end loop Find_Policy;
779 end Check_Consistent_Partition_Elaboration_Policy;
781 -------------------------------------
782 -- Check_Consistent_Queuing_Policy --
783 -------------------------------------
785 -- The rule is that all files for which the queuing policy is
786 -- significant must be compiled with the same setting.
788 procedure Check_Consistent_Queuing_Policy is
790 -- First search for a unit specifying a policy and then
791 -- check all remaining units against it.
793 Find_Policy : for A1 in ALIs.First .. ALIs.Last loop
794 if ALIs.Table (A1).Queuing_Policy /= ' ' then
795 Check_Policy : declare
796 Policy : constant Character := ALIs.Table (A1).Queuing_Policy;
798 for A2 in A1 + 1 .. ALIs.Last loop
799 if ALIs.Table (A2).Queuing_Policy /= ' '
801 ALIs.Table (A2).Queuing_Policy /= Policy
803 Error_Msg_File_1 := ALIs.Table (A1).Sfile;
804 Error_Msg_File_2 := ALIs.Table (A2).Sfile;
806 Consistency_Error_Msg
807 ("{ and { compiled with different queuing policies");
815 end loop Find_Policy;
816 end Check_Consistent_Queuing_Policy;
818 -----------------------------------
819 -- Check_Consistent_Restrictions --
820 -----------------------------------
822 -- The rule is that if a restriction is specified in any unit, then all
823 -- units must obey the restriction. The check applies only to restrictions
824 -- which require partition wide consistency, and not to internal units.
826 procedure Check_Consistent_Restrictions is
827 Restriction_File_Output : Boolean;
828 -- Shows if we have output header messages for restriction violation
830 procedure Print_Restriction_File (R : All_Restrictions);
831 -- Print header line for R if not printed yet
833 ----------------------------
834 -- Print_Restriction_File --
835 ----------------------------
837 procedure Print_Restriction_File (R : All_Restrictions) is
839 if not Restriction_File_Output then
840 Restriction_File_Output := True;
842 -- Find an ali file specifying the restriction
844 for A in ALIs.First .. ALIs.Last loop
845 if ALIs.Table (A).Restrictions.Set (R)
846 and then (R in All_Boolean_Restrictions
847 or else ALIs.Table (A).Restrictions.Value (R) =
848 Cumulative_Restrictions.Value (R))
850 -- We have found that ALI file A specifies the restriction
851 -- that is being violated (the minimum value is specified
852 -- in the case of a parameter restriction).
855 M1 : constant String := "{ has restriction ";
856 S : constant String := Restriction_Id'Image (R);
857 M2 : String (1 .. 2000); -- big enough
861 Name_Buffer (1 .. S'Length) := S;
862 Name_Len := S'Length;
863 Set_Casing (Mixed_Case);
867 M2 (P .. P + S'Length - 1) := Name_Buffer (1 .. S'Length);
870 if R in All_Parameter_Restrictions then
871 M2 (P .. P + 4) := " => #";
873 Int (Cumulative_Restrictions.Value (R));
877 Error_Msg_File_1 := ALIs.Table (A).Sfile;
878 Consistency_Error_Msg (M2 (1 .. P - 1));
879 Consistency_Error_Msg
880 ("but the following files violate this restriction:");
886 end Print_Restriction_File;
888 -- Start of processing for Check_Consistent_Restrictions
891 -- We used to have a special test here:
893 -- A special test, if we have a main program, then if it has an
894 -- allocator in the body, this is considered to be a violation of
895 -- the restriction No_Allocators_After_Elaboration. We just mark
896 -- this restriction and then the normal circuit will flag it.
898 -- But we don't do that any more, because in the final version of Ada
899 -- 2012, it is statically illegal to have an allocator in a library-
900 -- level subprogram, so we don't need this bind time test any more.
901 -- If we have a main program with parameters (which GNAT allows), then
902 -- allocators in that will be caught by the run-time check.
904 -- Loop through all restriction violations
906 for R in All_Restrictions loop
908 -- Check for violation of this restriction
910 if Cumulative_Restrictions.Set (R)
911 and then Cumulative_Restrictions.Violated (R)
912 and then (R in Partition_Boolean_Restrictions
913 or else (R in All_Parameter_Restrictions
915 Cumulative_Restrictions.Count (R) >
916 Cumulative_Restrictions.Value (R)))
918 Restriction_File_Output := False;
920 -- Loop through files looking for violators
922 for A2 in ALIs.First .. ALIs.Last loop
924 T : ALIs_Record renames ALIs.Table (A2);
927 if T.Restrictions.Violated (R) then
929 -- We exclude predefined files from the list of
930 -- violators. This should be rethought. It is not
931 -- clear that this is the right thing to do, that
932 -- is particularly the case for restricted runtimes.
934 if not Is_Internal_File_Name (T.Sfile) then
936 -- Case of Boolean restriction, just print file name
938 if R in All_Boolean_Restrictions then
939 Print_Restriction_File (R);
940 Error_Msg_File_1 := T.Sfile;
941 Consistency_Error_Msg (" {");
943 -- Case of Parameter restriction where violation
944 -- count exceeds restriction value, print file
945 -- name and count, adding "at least" if the
946 -- exact count is not known.
948 elsif R in Checked_Add_Parameter_Restrictions
949 or else T.Restrictions.Count (R) >
950 Cumulative_Restrictions.Value (R)
952 Print_Restriction_File (R);
953 Error_Msg_File_1 := T.Sfile;
954 Error_Msg_Nat_1 := Int (T.Restrictions.Count (R));
956 if T.Restrictions.Unknown (R) then
957 Consistency_Error_Msg
958 (" { (count = at least #)");
960 Consistency_Error_Msg
971 -- Now deal with No_Dependence indications. Note that we put the loop
972 -- through entries in the no dependency table first, since this loop
973 -- is most often empty (no such pragma Restrictions in use).
975 for ND in No_Deps.First .. No_Deps.Last loop
977 ND_Unit : constant Name_Id := No_Deps.Table (ND).No_Dep_Unit;
979 for J in ALIs.First .. ALIs.Last loop
981 A : ALIs_Record renames ALIs.Table (J);
984 for K in A.First_Unit .. A.Last_Unit loop
986 U : Unit_Record renames Units.Table (K);
988 for L in U.First_With .. U.Last_With loop
990 (Withs.Table (L).Uname, ND_Unit)
992 Error_Msg_File_1 := U.Sfile;
993 Error_Msg_Name_1 := ND_Unit;
994 Consistency_Error_Msg
995 ("file { violates restriction " &
996 "No_Dependence => %");
1005 end Check_Consistent_Restrictions;
1007 ------------------------------------------------------------
1008 -- Check_Consistent_Restriction_No_Default_Initialization --
1009 ------------------------------------------------------------
1011 -- The Restriction (No_Default_Initialization) has special consistency
1012 -- rules. The rule is that no unit compiled without this restriction
1013 -- that violates the restriction can WITH a unit that is compiled with
1016 procedure Check_Consistent_Restriction_No_Default_Initialization is
1018 -- Nothing to do if no one set this restriction
1020 if not Cumulative_Restrictions.Set (No_Default_Initialization) then
1024 -- Nothing to do if no one violates the restriction
1026 if not Cumulative_Restrictions.Violated (No_Default_Initialization) then
1030 -- Otherwise we go into a full scan to find possible problems
1032 for U in Units.First .. Units.Last loop
1034 UTE : Unit_Record renames Units.Table (U);
1035 ATE : ALIs_Record renames ALIs.Table (UTE.My_ALI);
1038 if ATE.Restrictions.Violated (No_Default_Initialization) then
1039 for W in UTE.First_With .. UTE.Last_With loop
1041 AFN : constant File_Name_Type := Withs.Table (W).Afile;
1044 -- The file name may not be present for withs of certain
1045 -- generic run-time files. The test can be safely left
1046 -- out in such cases anyway.
1048 if AFN /= No_File then
1050 WAI : constant ALI_Id :=
1051 ALI_Id (Get_Name_Table_Info (AFN));
1052 WTE : ALIs_Record renames ALIs.Table (WAI);
1055 if WTE.Restrictions.Set
1056 (No_Default_Initialization)
1058 Error_Msg_Unit_1 := UTE.Uname;
1059 Consistency_Error_Msg
1060 ("unit $ compiled without restriction "
1061 & "No_Default_Initialization");
1062 Error_Msg_Unit_1 := Withs.Table (W).Uname;
1063 Consistency_Error_Msg
1064 ("withs unit $, compiled with restriction "
1065 & "No_Default_Initialization");
1074 end Check_Consistent_Restriction_No_Default_Initialization;
1076 ----------------------------------
1077 -- Check_Consistent_SSO_Default --
1078 ----------------------------------
1080 procedure Check_Consistent_SSO_Default is
1081 Default : Character;
1084 Default := ALIs.Table (ALIs.First).SSO_Default;
1086 -- Check all entries match the default above from the first entry
1088 for A1 in ALIs.First + 1 .. ALIs.Last loop
1089 if ALIs.Table (A1).SSO_Default /= Default then
1095 -- All match, return
1097 if Default /= '?
' then
1101 -- Here we have a mismatch
1103 Consistency_Error_Msg
1104 ("files not compiled with same Default_Scalar_Storage_Order");
1107 Write_Str ("files compiled with High_Order_First");
1110 for A1 in ALIs.First .. ALIs.Last loop
1111 if ALIs.Table (A1).SSO_Default = 'H
' then
1113 Write_Name (ALIs.Table (A1).Sfile);
1119 Write_Str ("files compiled with Low_Order_First");
1122 for A1 in ALIs.First .. ALIs.Last loop
1123 if ALIs.Table (A1).SSO_Default = 'L
' then
1125 Write_Name (ALIs.Table (A1).Sfile);
1131 Write_Str ("files compiled with no Default_Scalar_Storage_Order");
1134 for A1 in ALIs.First .. ALIs.Last loop
1135 if ALIs.Table (A1).SSO_Default = ' ' then
1137 Write_Name (ALIs.Table (A1).Sfile);
1141 end Check_Consistent_SSO_Default;
1143 ---------------------------------------------------
1144 -- Check_Consistent_Zero_Cost_Exception_Handling --
1145 ---------------------------------------------------
1147 -- Check consistent zero cost exception handling. The rule is that
1148 -- all units must have the same exception handling mechanism.
1150 procedure Check_Consistent_Zero_Cost_Exception_Handling is
1152 Check_Mechanism : for A1 in ALIs.First + 1 .. ALIs.Last loop
1153 if ALIs.Table (A1).Zero_Cost_Exceptions /=
1154 ALIs.Table (ALIs.First).Zero_Cost_Exceptions
1156 Error_Msg_File_1 := ALIs.Table (A1).Sfile;
1157 Error_Msg_File_2 := ALIs.Table (ALIs.First).Sfile;
1159 Consistency_Error_Msg ("{ and { compiled with different "
1160 & "exception handling mechanisms");
1162 end loop Check_Mechanism;
1163 end Check_Consistent_Zero_Cost_Exception_Handling;
1165 -------------------------------
1166 -- Check_Duplicated_Subunits --
1167 -------------------------------
1169 procedure Check_Duplicated_Subunits is
1171 for J in Sdep.First .. Sdep.Last loop
1172 if Sdep.Table (J).Subunit_Name /= No_Name then
1173 Get_Decoded_Name_String (Sdep.Table (J).Subunit_Name);
1174 Name_Len := Name_Len + 2;
1175 Name_Buffer (Name_Len - 1) := '%';
1177 -- See if there is a body or spec with the same name
1179 for K in Boolean loop
1181 Name_Buffer (Name_Len) := 'b
';
1183 Name_Buffer (Name_Len) := 's
';
1187 Unit : constant Unit_Name_Type := Name_Find;
1188 Info : constant Int := Get_Name_Table_Info (Unit);
1193 Write_Str ("error: subunit """);
1194 Write_Name_Decoded (Sdep.Table (J).Subunit_Name);
1195 Write_Str (""" in file """);
1196 Write_Name_Decoded (Sdep.Table (J).Sfile);
1199 Write_Str (" has same name as unit
""");
1200 Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
1201 Write_Str (""" found
in file
""");
1202 Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
1205 Write_Str (" this is not allowed within a single "
1206 & "partition (RM 10.2(19))");
1208 Osint.Exit_Program (Osint.E_Fatal);
1214 end Check_Duplicated_Subunits;
1216 --------------------
1217 -- Check_Versions --
1218 --------------------
1220 procedure Check_Versions is
1221 VL : constant Natural := ALIs.Table (ALIs.First).Ver_Len;
1224 for A in ALIs.First .. ALIs.Last loop
1225 if ALIs.Table (A).Ver_Len /= VL
1226 or else ALIs.Table (A).Ver (1 .. VL) /=
1227 ALIs.Table (ALIs.First).Ver (1 .. VL)
1229 Error_Msg_File_1 := ALIs.Table (A).Sfile;
1230 Error_Msg_File_2 := ALIs.Table (ALIs.First).Sfile;
1232 Consistency_Error_Msg
1233 ("{ and { compiled with different GNAT versions");
1238 ---------------------------
1239 -- Consistency_Error_Msg --
1240 ---------------------------
1242 procedure Consistency_Error_Msg (Msg : String) is
1244 if Tolerate_Consistency_Errors then
1246 -- If consistency errors are tolerated,
1247 -- output the message as a warning.
1249 Error_Msg ('?
' & Msg);
1251 -- Otherwise the consistency error is a true error
1256 end Consistency_Error_Msg;
1262 function Same_Unit (U1 : Unit_Name_Type; U2 : Name_Id) return Boolean is
1264 -- Note, the string U1 has a terminating %s or %b, U2 does not
1266 if Length_Of_Name (U1) - 2 = Length_Of_Name (U2) then
1267 Get_Name_String (U1);
1270 U1_Str : constant String := Name_Buffer (1 .. Name_Len - 2);
1272 Get_Name_String (U2);
1273 return U1_Str = Name_Buffer (1 .. Name_Len);