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 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Back_End
; use Back_End
;
30 with Csets
; use Csets
;
31 with Debug
; use Debug
;
33 with Errout
; use Errout
;
36 with Fname
; use Fname
;
37 with Fname
.UF
; use Fname
.UF
;
39 with Ghost
; use Ghost
;
40 with Gnatvsn
; use Gnatvsn
;
43 with Lib
.Writ
; use Lib
.Writ
;
45 with Namet
; use Namet
;
48 with Osint
; use Osint
;
49 with Osint
.C
; use Osint
.C
;
50 with Output
; use Output
;
53 with Repinfo
; use Repinfo
;
55 with Rident
; use Rident
;
66 with Sinfo
; use Sinfo
;
67 with Sinput
.L
; use Sinput
.L
;
69 with Sprint
; use Sprint
;
71 with Stylesw
; use Stylesw
;
72 with Targparm
; use Targparm
;
75 with Treepr
; use Treepr
;
77 with Types
; use Types
;
78 with Uintp
; use Uintp
;
79 with Uname
; use Uname
;
82 with Validsw
; use Validsw
;
84 with System
.Assertions
;
92 procedure Adjust_Global_Switches
;
93 -- There are various interactions between front-end switch settings,
94 -- including debug switch settings and target dependent parameters.
95 -- This procedure takes care of properly handling these interactions.
96 -- We do it after scanning out all the switches, so that we are not
97 -- depending on the order in which switches appear.
99 procedure Check_Bad_Body
(Unit_Node
: Node_Id
; Unit_Kind
: Node_Kind
);
100 -- Called to check whether a unit described by its compilation unit node
101 -- and kind has a bad body.
103 procedure Check_Rep_Info
;
104 -- Called when we are not generating code, to check if -gnatR was requested
105 -- and if so, explain that we will not be honoring the request.
107 procedure Post_Compilation_Validation_Checks
;
108 -- This procedure performs various validation checks that have to be left
109 -- to the end of the compilation process, after generating code but before
110 -- issuing error messages. In particular, these checks generally require
111 -- the information provided by the back end in back annotation of declared
112 -- entities (e.g. actual size and alignment values chosen by the back end).
114 ----------------------------
115 -- Adjust_Global_Switches --
116 ----------------------------
118 procedure Adjust_Global_Switches
is
119 procedure SPARK_Library_Warning
(Kind
: String);
120 -- Issue a warning in GNATprove mode if the run-time library does not
121 -- fully support IEEE-754 floating-point semantics.
123 ---------------------------
124 -- SPARK_Library_Warning --
125 ---------------------------
127 procedure SPARK_Library_Warning
(Kind
: String) is
130 ("warning: run-time library may be configured incorrectly");
132 ("warning: (SPARK analysis requires support for " & Kind
& ')');
133 end SPARK_Library_Warning
;
135 -- Start of processing for Adjust_Global_Switches
138 -- -gnatd.M enables Relaxed_RM_Semantics
140 if Debug_Flag_Dot_MM
then
141 Relaxed_RM_Semantics
:= True;
144 -- -gnatd.1 enables unnesting of subprograms
146 if Debug_Flag_Dot_1
then
147 Unnest_Subprogram_Mode
:= True;
150 -- -gnatd.u enables special C expansion mode
152 if Debug_Flag_Dot_U
then
153 Modify_Tree_For_C
:= True;
156 -- Set all flags required when generating C code
158 if Generate_C_Code
then
159 Modify_Tree_For_C
:= True;
160 Unnest_Subprogram_Mode
:= True;
161 Minimize_Expression_With_Actions
:= True;
163 -- Set operating mode to Generate_Code to benefit from full front-end
164 -- expansion (e.g. generics).
166 Operating_Mode
:= Generate_Code
;
168 -- Suppress alignment checks since we do not have access to alignment
169 -- info on the target.
171 Suppress_Options
.Suppress
(Alignment_Check
) := False;
174 -- -gnatd.E sets Error_To_Warning mode, causing selected error messages
175 -- to be treated as warnings instead of errors.
177 if Debug_Flag_Dot_EE
then
178 Error_To_Warning
:= True;
181 -- Disable CodePeer_Mode in Check_Syntax, since we need front-end
184 if Operating_Mode
= Check_Syntax
then
185 CodePeer_Mode
:= False;
188 -- Set ASIS mode if -gnatt and -gnatc are set
190 if Operating_Mode
= Check_Semantics
and then Tree_Output
then
193 -- Set ASIS GNSA mode if -gnatd.H is set
195 if Debug_Flag_Dot_HH
then
196 ASIS_GNSA_Mode
:= True;
199 -- Turn off inlining in ASIS mode, since ASIS cannot handle the extra
200 -- information in the trees caused by inlining being active.
202 -- More specifically, the tree seems to be malformed from the ASIS
203 -- point of view if -gnatc and -gnatn appear together???
205 Inline_Active
:= False;
207 -- Turn off SCIL generation and CodePeer mode in semantics mode,
208 -- since SCIL requires front-end expansion.
210 Generate_SCIL
:= False;
211 CodePeer_Mode
:= False;
214 -- SCIL mode needs to disable front-end inlining since the generated
215 -- trees (in particular order and consistency between specs compiled
216 -- as part of a main unit or as part of a with-clause) are causing
219 if Generate_SCIL
then
220 Front_End_Inlining
:= False;
223 -- Tune settings for optimal SCIL generation in CodePeer mode
225 if CodePeer_Mode
then
227 -- Turn off gnatprove mode (which can be set via e.g. -gnatd.F), not
228 -- compatible with CodePeer mode.
230 GNATprove_Mode
:= False;
231 Debug_Flag_Dot_FF
:= False;
233 -- Turn off C tree generation, not compatible with CodePeer mode. We
234 -- do not expect this to happen in normal use, since both modes are
235 -- enabled by special tools, but it is useful to turn off these flags
236 -- this way when we are doing CodePeer tests on existing test suites
237 -- that may have -gnateg set, to avoid the need for special casing.
239 Modify_Tree_For_C
:= False;
240 Generate_C_Code
:= False;
241 Unnest_Subprogram_Mode
:= False;
243 -- Turn off inlining, confuses CodePeer output and gains nothing
245 Front_End_Inlining
:= False;
246 Inline_Active
:= False;
248 -- Disable front-end optimizations, to keep the tree as close to the
249 -- source code as possible, and also to avoid inconsistencies between
250 -- trees when using different optimization switches.
252 Optimization_Level
:= 0;
254 -- Enable some restrictions systematically to simplify the generated
255 -- code (and ease analysis). Note that restriction checks are also
256 -- disabled in CodePeer mode, see Restrict.Check_Restriction, and
257 -- user specified Restrictions pragmas are ignored, see
258 -- Sem_Prag.Process_Restrictions_Or_Restriction_Warnings.
260 Restrict
.Restrictions
.Set
(No_Exception_Registration
) := True;
261 Restrict
.Restrictions
.Set
(No_Initialize_Scalars
) := True;
262 Restrict
.Restrictions
.Set
(No_Task_Hierarchy
) := True;
263 Restrict
.Restrictions
.Set
(No_Abort_Statements
) := True;
264 Restrict
.Restrictions
.Set
(Max_Asynchronous_Select_Nesting
) := True;
265 Restrict
.Restrictions
.Value
(Max_Asynchronous_Select_Nesting
) := 0;
267 -- Suppress division by zero and access checks since they are handled
268 -- implicitly by CodePeer.
270 -- Turn off dynamic elaboration checks: generates inconsistencies in
271 -- trees between specs compiled as part of a main unit or as part of
274 -- Turn off alignment checks: these cannot be proved statically by
275 -- CodePeer and generate false positives.
277 -- Enable all other language checks
279 Suppress_Options
.Suppress
:=
280 (Alignment_Check
=> True,
281 Division_Check
=> True,
282 Elaboration_Check
=> True,
285 Dynamic_Elaboration_Checks
:= False;
287 -- Set STRICT mode for overflow checks if not set explicitly. This
288 -- prevents suppressing of overflow checks by default, in code down
291 if Suppress_Options
.Overflow_Mode_General
= Not_Set
then
292 Suppress_Options
.Overflow_Mode_General
:= Strict
;
293 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
296 -- CodePeer handles division and overflow checks directly, based on
297 -- the marks set by the frontend, hence no special expansion should
298 -- be performed in the frontend for division and overflow checks.
300 Backend_Divide_Checks_On_Target
:= True;
301 Backend_Overflow_Checks_On_Target
:= True;
303 -- Kill debug of generated code, since it messes up sloc values
305 Debug_Generated_Code
:= False;
307 -- Ditto for -gnateG which interacts badly with handling of pragma
308 -- Annotate in gnat2scil.
310 Generate_Processed_File
:= False;
312 -- Disable Exception_Extra_Info (-gnateE) which generates more
313 -- complex trees with no added value, and may confuse CodePeer.
315 Exception_Extra_Info
:= False;
317 -- Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
318 -- to support source navigation.
322 -- Polling mode forced off, since it generates confusing junk
324 Polling_Required
:= False;
326 -- Set operating mode to Generate_Code to benefit from full front-end
327 -- expansion (e.g. generics).
329 Operating_Mode
:= Generate_Code
;
331 -- We need SCIL generation of course
333 Generate_SCIL
:= True;
335 -- Enable assertions, since they give CodePeer valuable extra info
337 Assertions_Enabled
:= True;
339 -- Set normal RM validity checking and checking of copies (to catch
340 -- e.g. wrong values used in unchecked conversions).
341 -- All other validity checking is turned off, since this can generate
342 -- very complex trees that only confuse CodePeer and do not bring
343 -- enough useful info.
345 Reset_Validity_Check_Options
;
346 Validity_Check_Default
:= True;
347 Validity_Check_Copies
:= True;
349 -- Turn off style check options and ignore any style check pragmas
350 -- since we are not interested in any front-end warnings when we are
351 -- getting CodePeer output.
353 Reset_Style_Check_Options
;
354 Ignore_Style_Checks_Pragmas
:= True;
356 -- Always perform semantics and generate ali files in CodePeer mode,
357 -- so that a gnatmake -c -k will proceed further when possible.
359 Force_ALI_Tree_File
:= True;
360 Try_Semantics
:= True;
362 -- Make the Ada front end more liberal so that the compiler will
363 -- allow illegal code that is allowed by other compilers. CodePeer
364 -- is in the business of finding problems, not enforcing rules.
365 -- This is useful when using CodePeer mode with other compilers.
367 Relaxed_RM_Semantics
:= True;
369 -- Disable all simple value propagation. This is an optimization
370 -- which is valuable for code optimization, and also for generation
371 -- of compiler warnings, but these are being turned off by default,
372 -- and CodePeer generates better messages (referencing original
373 -- variables) this way.
374 -- Do this only if -gnatws is set (the default with -gnatcC), so that
375 -- if warnings are enabled, we'll get better messages from GNAT.
377 if Warning_Mode
= Suppress
then
378 Debug_Flag_MM
:= True;
382 -- Enable some individual switches that are implied by relaxed RM
385 if Relaxed_RM_Semantics
then
386 Opt
.Allow_Integer_Address
:= True;
387 Overriding_Renamings
:= True;
388 Treat_Categorization_Errors_As_Warnings
:= True;
391 -- Enable GNATprove_Mode when using -gnatd.F switch
393 if Debug_Flag_Dot_FF
then
394 GNATprove_Mode
:= True;
397 -- GNATprove_Mode is also activated by default in the gnat2why
400 if GNATprove_Mode
then
402 -- Turn off CodePeer mode (which can be set via e.g. -gnatC or
403 -- -gnateC), not compatible with GNATprove mode.
405 CodePeer_Mode
:= False;
406 Generate_SCIL
:= False;
408 -- Turn off C tree generation, not compatible with GNATprove mode. We
409 -- do not expect this to happen in normal use, since both modes are
410 -- enabled by special tools, but it is useful to turn off these flags
411 -- this way when we are doing GNATprove tests on existing test suites
412 -- that may have -gnateg set, to avoid the need for special casing.
414 Modify_Tree_For_C
:= False;
415 Generate_C_Code
:= False;
416 Unnest_Subprogram_Mode
:= False;
418 -- Turn off inlining, which would confuse formal verification output
421 Front_End_Inlining
:= False;
422 Inline_Active
:= False;
424 -- Issue warnings for failure to inline subprograms, as otherwise
425 -- expected in GNATprove mode for the local subprograms without
428 Ineffective_Inline_Warnings
:= True;
430 -- Disable front-end optimizations, to keep the tree as close to the
431 -- source code as possible, and also to avoid inconsistencies between
432 -- trees when using different optimization switches.
434 Optimization_Level
:= 0;
436 -- Enable some restrictions systematically to simplify the generated
437 -- code (and ease analysis).
439 Restrict
.Restrictions
.Set
(No_Initialize_Scalars
) := True;
441 -- Note: at this point we used to suppress various checks, but that
442 -- is not what we want. We need the semantic processing for these
443 -- checks (which will set flags like Do_Overflow_Check, showing the
444 -- points at which potential checks are required semantically). We
445 -- don't want the expansion associated with these checks, but that
446 -- happens anyway because this expansion is simply not done in the
447 -- SPARK version of the expander.
449 -- On the contrary, we need to enable explicitly all language checks,
450 -- as they may have been suppressed by the use of switch -gnatp.
452 Suppress_Options
.Suppress
:= (others => False);
454 -- Detect overflow on unconstrained floating-point types, such as
455 -- the predefined types Float, Long_Float and Long_Long_Float from
456 -- package Standard. Not necessary if float overflows are checked
457 -- (Machine_Overflow true), since appropriate Do_Overflow_Check flags
458 -- will be set in any case.
460 Check_Float_Overflow
:= not Machine_Overflows_On_Target
;
462 -- Set STRICT mode for overflow checks if not set explicitly. This
463 -- prevents suppressing of overflow checks by default, in code down
466 if Suppress_Options
.Overflow_Mode_General
= Not_Set
then
467 Suppress_Options
.Overflow_Mode_General
:= Strict
;
468 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
471 -- Kill debug of generated code, since it messes up sloc values
473 Debug_Generated_Code
:= False;
475 -- Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
476 -- as it is needed for computing effects of subprograms in the formal
477 -- verification backend.
481 -- Polling mode forced off, since it generates confusing junk
483 Polling_Required
:= False;
485 -- Set operating mode to Check_Semantics, but a light front-end
486 -- expansion is still performed.
488 Operating_Mode
:= Check_Semantics
;
490 -- Enable assertions, since they give valuable extra information for
491 -- formal verification.
493 Assertions_Enabled
:= True;
495 -- Disable validity checks, since it generates code raising
496 -- exceptions for invalid data, which confuses GNATprove. Invalid
497 -- data is directly detected by GNATprove's flow analysis.
499 Validity_Checks_On
:= False;
501 -- Turn off style check options since we are not interested in any
502 -- front-end warnings when we are getting SPARK output.
504 Reset_Style_Check_Options
;
506 -- Suppress the generation of name tables for enumerations, which are
507 -- not needed for formal verification, and fall outside the SPARK
508 -- subset (use of pointers).
510 Global_Discard_Names
:= True;
512 -- Suppress the expansion of tagged types and dispatching calls,
513 -- which lead to the generation of non-SPARK code (use of pointers),
514 -- which is more complex to formally verify than the original source.
516 Tagged_Type_Expansion
:= False;
518 -- Detect that the runtime library support for floating-point numbers
519 -- may not be compatible with SPARK analysis of IEEE-754 floats.
521 if Denorm_On_Target
= False then
522 SPARK_Library_Warning
("float subnormals");
524 elsif Machine_Rounds_On_Target
= False then
525 SPARK_Library_Warning
("float rounding");
527 elsif Signed_Zeros_On_Target
= False then
528 SPARK_Library_Warning
("signed zeros");
532 -- Set Configurable_Run_Time mode if system.ads flag set or if the
533 -- special debug flag -gnatdY is set.
535 if Targparm
.Configurable_Run_Time_On_Target
or Debug_Flag_YY
then
536 Configurable_Run_Time_Mode
:= True;
539 -- Set -gnatR3m mode if debug flag A set
541 if Debug_Flag_AA
then
542 Back_Annotate_Rep_Info
:= True;
543 List_Representation_Info
:= 1;
544 List_Representation_Info_Mechanisms
:= True;
547 -- Force Target_Strict_Alignment true if debug flag -gnatd.a is set
549 if Debug_Flag_Dot_A
then
550 Ttypes
.Target_Strict_Alignment
:= True;
553 -- Increase size of allocated entities if debug flag -gnatd.N is set
555 if Debug_Flag_Dot_NN
then
556 Atree
.Num_Extension_Nodes
:= Atree
.Num_Extension_Nodes
+ 1;
559 -- Disable static allocation of dispatch tables if -gnatd.t or if layout
560 -- is enabled. The front end's layout phase currently treats types that
561 -- have discriminant-dependent arrays as not being static even when a
562 -- discriminant constraint on the type is static, and this leads to
563 -- problems with subtypes of type Ada.Tags.Dispatch_Table_Wrapper. ???
565 if Debug_Flag_Dot_T
or else Frontend_Layout_On_Target
then
566 Static_Dispatch_Tables
:= False;
569 -- Flip endian mode if -gnatd8 set
572 Ttypes
.Bytes_Big_Endian
:= not Ttypes
.Bytes_Big_Endian
;
575 -- Activate front-end layout if debug flag -gnatdF is set
577 if Debug_Flag_FF
then
578 Targparm
.Frontend_Layout_On_Target
:= True;
581 -- Set and check exception mechanism. This is only meaningful when
582 -- compiling, and in particular not meaningful for special modes used
583 -- for program analysis rather than compilation: ASIS mode, CodePeer
584 -- mode and GNATprove mode.
586 if Operating_Mode
= Generate_Code
587 and then not (ASIS_Mode
or CodePeer_Mode
or GNATprove_Mode
)
589 case Targparm
.Frontend_Exceptions_On_Target
is
591 case Targparm
.ZCX_By_Default_On_Target
is
594 ("Run-time library configured incorrectly");
596 ("(requesting support for Frontend ZCX exceptions)");
597 raise Unrecoverable_Error
;
600 Exception_Mechanism
:= Front_End_SJLJ
;
604 case Targparm
.ZCX_By_Default_On_Target
is
606 Exception_Mechanism
:= Back_End_ZCX
;
608 Exception_Mechanism
:= Back_End_SJLJ
;
613 -- Set proper status for overflow check mechanism
615 -- If already set (by -gnato or above in SPARK or CodePeer mode) then we
616 -- have nothing to do.
618 if Opt
.Suppress_Options
.Overflow_Mode_General
/= Not_Set
then
621 -- Otherwise set overflow mode defaults
624 -- Overflow checks are on by default (Suppress set False) except in
625 -- GNAT_Mode, where we want them off by default (we are not ready to
626 -- enable overflow checks in the compiler yet, for one thing the case
627 -- of 64-bit checks needs System.Arith_64 which is not a compiler
628 -- unit and it is a pain to try to include it in the compiler.
630 Suppress_Options
.Suppress
(Overflow_Check
) := GNAT_Mode
;
632 -- Set appropriate default overflow handling mode. Note: at present
633 -- we set STRICT in all three of the following cases. They are
634 -- separated because in the future we may make different choices.
636 -- By default set STRICT mode if -gnatg in effect
639 Suppress_Options
.Overflow_Mode_General
:= Strict
;
640 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
642 -- If we have backend divide and overflow checks, then by default
643 -- overflow checks are STRICT. Historically this code used to also
644 -- activate overflow checks, although no target currently has these
645 -- flags set, so this was dead code anyway.
647 elsif Targparm
.Backend_Divide_Checks_On_Target
649 Targparm
.Backend_Overflow_Checks_On_Target
651 Suppress_Options
.Overflow_Mode_General
:= Strict
;
652 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
654 -- Otherwise for now, default is STRICT mode. This may change in the
655 -- future, but for now this is the compatible behavior with previous
659 Suppress_Options
.Overflow_Mode_General
:= Strict
;
660 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
664 -- Set default for atomic synchronization. As this synchronization
665 -- between atomic accesses can be expensive, and not typically needed
666 -- on some targets, an optional target parameter can turn the option
667 -- off. Note Atomic Synchronization is implemented as check.
669 Suppress_Options
.Suppress
(Atomic_Synchronization
) :=
670 not Atomic_Sync_Default_On_Target
;
672 -- Set default for Alignment_Check, if we are on a machine with non-
673 -- strict alignment, then we suppress this check, since it is over-
674 -- zealous for such machines.
676 if not Ttypes
.Target_Strict_Alignment
then
677 Suppress_Options
.Suppress
(Alignment_Check
) := True;
680 -- Set switch indicating if back end can handle limited types, and
681 -- guarantee that no incorrect copies are made (e.g. in the context
682 -- of an if or case expression).
684 -- Debug flag -gnatd.L decisively sets usage on
686 if Debug_Flag_Dot_LL
then
687 Back_End_Handles_Limited_Types
:= True;
689 -- If no debug flag, usage off for SCIL cases
691 elsif Generate_SCIL
then
692 Back_End_Handles_Limited_Types
:= False;
694 -- Otherwise normal gcc back end, for now still turn flag off by
695 -- default, since there are unresolved problems in the front end.
698 Back_End_Handles_Limited_Types
:= False;
701 -- If the inlining level has not been set by the user, compute it from
702 -- the optimization level: 1 at -O1/-O2 (and -Os), 2 at -O3 and above.
704 if Inline_Level
= 0 then
705 if Optimization_Level
< 3 then
712 -- Treat -gnatn as equivalent to -gnatN for non-GCC targets
714 if Inline_Active
and not Front_End_Inlining
then
716 -- We really should have a tag for this, what if we added a new
717 -- back end some day, it would not be true for this test, but it
718 -- would be non-GCC, so this is a bit troublesome ???
720 Front_End_Inlining
:= Generate_C_Code
;
723 -- Set back-end inlining indication
727 -- No back-end inlining available on C generation
731 -- No back-end inlining in GNATprove mode, since it just confuses
732 -- the formal verification process.
734 and then not GNATprove_Mode
736 -- No back-end inlining if front-end inlining explicitly enabled.
737 -- Done to minimize the output differences to customers still using
738 -- this deprecated switch; in addition, this behavior reduces the
739 -- output differences in old tests.
741 and then not Front_End_Inlining
743 -- Back-end inlining is disabled if debug flag .z is set
745 and then not Debug_Flag_Dot_Z
;
747 -- Output warning if -gnateE specified and cannot be supported
749 if Exception_Extra_Info
750 and then Restrict
.No_Exception_Handlers_Set
754 ("warning: extra exception information (-gnateE) was specified");
757 ("warning: this capability is not available in this configuration");
762 -- Finally capture adjusted value of Suppress_Options as the initial
763 -- value for Scope_Suppress, which will be modified as we move from
764 -- scope to scope (by Suppress/Unsuppress/Overflow_Checks pragmas).
766 Sem
.Scope_Suppress
:= Opt
.Suppress_Options
;
767 end Adjust_Global_Switches
;
773 procedure Check_Bad_Body
(Unit_Node
: Node_Id
; Unit_Kind
: Node_Kind
) is
774 Fname
: File_Name_Type
;
776 procedure Bad_Body_Error
(Msg
: String);
777 -- Issue message for bad body found
783 procedure Bad_Body_Error
(Msg
: String) is
785 Error_Msg_N
(Msg
, Unit_Node
);
786 Error_Msg_File_1
:= Fname
;
787 Error_Msg_N
("remove incorrect body in file{!", Unit_Node
);
792 Sname
: Unit_Name_Type
;
793 Src_Ind
: Source_File_Index
;
795 -- Start of processing for Check_Bad_Body
798 -- Nothing to do if we are only checking syntax, because we don't know
799 -- enough to know if we require or forbid a body in this case.
801 if Operating_Mode
= Check_Syntax
then
805 -- Check for body not allowed
807 if (Unit_Kind
= N_Package_Declaration
808 and then not Body_Required
(Unit_Node
))
809 or else (Unit_Kind
= N_Generic_Package_Declaration
810 and then not Body_Required
(Unit_Node
))
811 or else Unit_Kind
= N_Package_Renaming_Declaration
812 or else Unit_Kind
= N_Subprogram_Renaming_Declaration
813 or else Nkind
(Original_Node
(Unit
(Unit_Node
)))
814 in N_Generic_Instantiation
816 Sname
:= Unit_Name
(Main_Unit
);
818 -- If we do not already have a body name, then get the body name
820 if not Is_Body_Name
(Sname
) then
821 Sname
:= Get_Body_Name
(Sname
);
824 Fname
:= Get_File_Name
(Sname
, Subunit
=> False);
825 Src_Ind
:= Load_Source_File
(Fname
);
827 -- Case where body is present and it is not a subunit. Exclude the
828 -- subunit case, because it has nothing to do with the package we are
829 -- compiling. It is illegal for a child unit and a subunit with the
830 -- same expanded name (RM 10.2(9)) to appear together in a partition,
831 -- but there is nothing to stop a compilation environment from having
832 -- both, and the test here simply allows that. If there is an attempt
833 -- to include both in a partition, this is diagnosed at bind time. In
834 -- Ada 83 mode this is not a warning case.
836 -- Note that in general we do not give the message if the file in
837 -- question does not look like a body. This includes weird cases,
838 -- but in particular means that if the file is just a No_Body pragma,
839 -- then we won't give the message (that's the whole point of this
840 -- pragma, to be used this way and to cause the body file to be
841 -- ignored in this context).
843 if Src_Ind
/= No_Source_File
844 and then Source_File_Is_Body
(Src_Ind
)
846 Errout
.Finalize
(Last_Call
=> False);
848 Error_Msg_Unit_1
:= Sname
;
850 -- Ada 83 case of a package body being ignored. This is not an
851 -- error as far as the Ada 83 RM is concerned, but it is almost
852 -- certainly not what is wanted so output a warning. Give this
853 -- message only if there were no errors, since otherwise it may
854 -- be incorrect (we may have misinterpreted a junk spec as not
855 -- needing a body when it really does).
857 if Unit_Kind
= N_Package_Declaration
858 and then Ada_Version
= Ada_83
859 and then Operating_Mode
= Generate_Code
860 and then Distribution_Stub_Mode
/= Generate_Caller_Stub_Body
861 and then not Compilation_Errors
864 ("package $$ does not require a body??", Unit_Node
);
865 Error_Msg_File_1
:= Fname
;
866 Error_Msg_N
("body in file{ will be ignored??", Unit_Node
);
868 -- Ada 95 cases of a body file present when no body is
869 -- permitted. This we consider to be an error.
872 -- For generic instantiations, we never allow a body
874 if Nkind
(Original_Node
(Unit
(Unit_Node
))) in
875 N_Generic_Instantiation
878 ("generic instantiation for $$ does not allow a body");
880 -- A library unit that is a renaming never allows a body
882 elsif Unit_Kind
in N_Renaming_Declaration
then
884 ("renaming declaration for $$ does not allow a body!");
886 -- Remaining cases are packages and generic packages. Here
887 -- we only do the test if there are no previous errors,
888 -- because if there are errors, they may lead us to
889 -- incorrectly believe that a package does not allow a
890 -- body when in fact it does.
892 elsif not Compilation_Errors
then
893 if Unit_Kind
= N_Package_Declaration
then
895 ("package $$ does not allow a body!");
897 elsif Unit_Kind
= N_Generic_Package_Declaration
then
899 ("generic package $$ does not allow a body!");
912 procedure Check_Rep_Info
is
914 if List_Representation_Info
/= 0
915 or else List_Representation_Info_Mechanisms
920 ("cannot generate representation information, no code generated");
927 ----------------------------------------
928 -- Post_Compilation_Validation_Checks --
929 ----------------------------------------
931 procedure Post_Compilation_Validation_Checks
is
933 -- Validate alignment check warnings. In some cases we generate warnings
934 -- about possible alignment errors because we don't know the alignment
935 -- that will be chosen by the back end. This routine is in charge of
936 -- getting rid of those warnings if we can tell they are not needed.
938 Checks
.Validate_Alignment_Check_Warnings
;
940 -- Validate compile time warnings and errors (using the values for size
941 -- and alignment annotated by the backend where possible). We need to
942 -- unlock temporarily these tables to reanalyze their expression.
947 Sem_Ch13
.Validate_Compile_Time_Warning_Errors
;
952 -- Validate unchecked conversions (using the values for size and
953 -- alignment annotated by the backend where possible).
955 Sem_Ch13
.Validate_Unchecked_Conversions
;
957 -- Validate address clauses (again using alignment values annotated
958 -- by the backend where possible).
960 Sem_Ch13
.Validate_Address_Clauses
;
962 -- Validate independence pragmas (again using values annotated by the
963 -- back end for component layout where possible) but only for non-GCC
964 -- back ends, as this is done a priori for GCC back ends.
966 if AAMP_On_Target
then
967 Sem_Ch13
.Validate_Independence
;
969 end Post_Compilation_Validation_Checks
;
973 Back_End_Mode
: Back_End
.Back_End_Mode_Type
;
974 Ecode
: Exit_Code_Type
;
976 Main_Unit_Kind
: Node_Kind
;
977 -- Kind of main compilation unit node
979 Main_Unit_Node
: Node_Id
;
980 -- Compilation unit node for main unit
982 -- Start of processing for Gnat1drv
985 -- This inner block is set up to catch assertion errors and constraint
986 -- errors. Since the code for handling these errors can cause another
987 -- exception to be raised (namely Unrecoverable_Error), we need two
988 -- nested blocks, so that the outer one handles unrecoverable error.
991 -- Initialize all packages. For the most part, these initialization
992 -- calls can be made in any order. Exceptions are as follows:
994 -- Lib.Initialize need to be called before Scan_Compiler_Arguments,
995 -- because it initializes a table filled by Scan_Compiler_Arguments.
1000 Lib
.Xref
.Initialize
;
1001 Scan_Compiler_Arguments
;
1002 Osint
.Add_Default_Search_Dirs
;
1019 Sem_Ch12
.Initialize
;
1020 Sem_Ch13
.Initialize
;
1021 Sem_Elim
.Initialize
;
1022 Sem_Eval
.Initialize
;
1023 Sem_Type
.Init_Interp_Tables
;
1025 -- Capture compilation date and time
1027 Opt
.Compilation_Time
:= System
.OS_Lib
.Current_Time_String
;
1029 -- Get the target parameters only when -gnats is not used, to avoid
1030 -- failing when there is no default runtime.
1032 if Operating_Mode
/= Check_Syntax
then
1034 -- Acquire target parameters from system.ads (package System source)
1036 Targparm_Acquire
: declare
1039 S
: Source_File_Index
;
1043 Name_Buffer
(1 .. 10) := "system.ads";
1046 S
:= Load_Source_File
(N
);
1048 -- Failed to read system.ads, fatal error
1050 if S
= No_Source_File
then
1052 ("fatal error, run-time library not installed correctly");
1053 Write_Line
("cannot locate file system.ads");
1054 raise Unrecoverable_Error
;
1056 -- Read system.ads successfully, remember its source index
1059 System_Source_File_Index
:= S
;
1062 -- Call to get target parameters. Note that the actual interface
1063 -- routines are in Tbuild. They can't be in this procedure because
1064 -- of accessibility issues.
1066 Targparm
.Get_Target_Parameters
1067 (System_Text
=> Source_Text
(S
),
1068 Source_First
=> Source_First
(S
),
1069 Source_Last
=> Source_Last
(S
),
1070 Make_Id
=> Tbuild
.Make_Id
'Access,
1071 Make_SC
=> Tbuild
.Make_SC
'Access,
1072 Set_NOD
=> Tbuild
.Set_NOD
'Access,
1073 Set_NSA
=> Tbuild
.Set_NSA
'Access,
1074 Set_NUA
=> Tbuild
.Set_NUA
'Access,
1075 Set_NUP
=> Tbuild
.Set_NUP
'Access);
1077 -- Acquire configuration pragma information from Targparm
1079 Restrict
.Restrictions
:= Targparm
.Restrictions_On_Target
;
1080 end Targparm_Acquire
;
1083 -- Perform various adjustments and settings of global switches
1085 Adjust_Global_Switches
;
1087 -- Output copyright notice if full list mode unless we have a list
1088 -- file, in which case we defer this so that it is output in the file.
1090 if (Verbose_Mode
or else (Full_List
and then Full_List_File_Name
= null))
1092 -- Debug flag gnatd7 suppresses this copyright notice
1094 and then not Debug_Flag_7
1097 Write_Str
("GNAT ");
1098 Write_Str
(Gnat_Version_String
);
1100 Write_Str
("Copyright 1992-" & Current_Year
1101 & ", Free Software Foundation, Inc.");
1105 -- Check we do not have more than one source file, this happens only in
1106 -- the case where the driver is called directly, it cannot happen when
1107 -- gnat1 is invoked from gcc in the normal case.
1109 if Osint
.Number_Of_Files
/= 1 then
1112 Osint
.Fail
("you must provide one source file");
1114 elsif Usage_Requested
then
1118 -- Generate target dependent output file if requested
1120 if Target_Dependent_Info_Write_Name
/= null then
1121 Set_Targ
.Write_Target_Dependent_Values
;
1124 -- Call the front end
1126 Original_Operating_Mode
:= Operating_Mode
;
1129 -- Exit with errors if the main source could not be parsed
1131 if Sinput
.Main_Source_File
= No_Source_File
then
1132 Errout
.Finalize
(Last_Call
=> True);
1133 Errout
.Output_Messages
;
1134 Exit_Program
(E_Errors
);
1137 Main_Unit_Node
:= Cunit
(Main_Unit
);
1138 Main_Unit_Kind
:= Nkind
(Unit
(Main_Unit_Node
));
1140 Check_Bad_Body
(Main_Unit_Node
, Main_Unit_Kind
);
1142 -- In CodePeer mode we always delete old SCIL files before regenerating
1143 -- new ones, in case of e.g. errors, and also to remove obsolete scilx
1144 -- files generated by CodePeer itself.
1146 if CodePeer_Mode
then
1147 Comperr
.Delete_SCIL_Files
;
1150 -- Ditto for old C files before regenerating new ones
1152 if Generate_C_Code
then
1157 -- Exit if compilation errors detected
1159 Errout
.Finalize
(Last_Call
=> False);
1161 if Compilation_Errors
then
1163 Post_Compilation_Validation_Checks
;
1164 Errout
.Output_Messages
;
1167 -- Generate ALI file if specially requested
1169 if Opt
.Force_ALI_Tree_File
then
1170 Write_ALI
(Object
=> False);
1174 Errout
.Finalize
(Last_Call
=> True);
1175 Exit_Program
(E_Errors
);
1178 -- Set Generate_Code on main unit and its spec. We do this even if are
1179 -- not generating code, since Lib-Writ uses this to determine which
1180 -- units get written in the ali file.
1182 Set_Generate_Code
(Main_Unit
);
1184 -- If we have a corresponding spec, and it comes from source or it is
1185 -- not a generated spec for a child subprogram body, then we need object
1186 -- code for the spec unit as well.
1188 if Nkind
(Unit
(Main_Unit_Node
)) in N_Unit_Body
1189 and then not Acts_As_Spec
(Main_Unit_Node
)
1191 if Nkind
(Unit
(Main_Unit_Node
)) = N_Subprogram_Body
1192 and then not Comes_From_Source
(Library_Unit
(Main_Unit_Node
))
1197 (Get_Cunit_Unit_Number
(Library_Unit
(Main_Unit_Node
)));
1201 -- Case of no code required to be generated, exit indicating no error
1203 if Original_Operating_Mode
= Check_Syntax
then
1205 Errout
.Finalize
(Last_Call
=> True);
1206 Errout
.Output_Messages
;
1211 -- Use a goto instead of calling Exit_Program so that finalization
1214 goto End_Of_Program
;
1216 elsif Original_Operating_Mode
= Check_Semantics
then
1217 Back_End_Mode
:= Declarations_Only
;
1219 -- All remaining cases are cases in which the user requested that code
1220 -- be generated (i.e. no -gnatc or -gnats switch was used). Check if we
1221 -- can in fact satisfy this request.
1223 -- Cannot generate code if someone has turned off code generation for
1224 -- any reason at all. We will try to figure out a reason below.
1226 elsif Operating_Mode
/= Generate_Code
then
1227 Back_End_Mode
:= Skip
;
1229 -- We can generate code for a subprogram body unless there were missing
1230 -- subunits. Note that we always generate code for all generic units (a
1231 -- change from some previous versions of GNAT).
1233 elsif Main_Unit_Kind
= N_Subprogram_Body
1234 and then not Subunits_Missing
1236 Back_End_Mode
:= Generate_Object
;
1238 -- We can generate code for a package body unless there are subunits
1239 -- missing (note that we always generate code for generic units, which
1240 -- is a change from some earlier versions of GNAT).
1242 elsif Main_Unit_Kind
= N_Package_Body
and then not Subunits_Missing
then
1243 Back_End_Mode
:= Generate_Object
;
1245 -- We can generate code for a package declaration or a subprogram
1246 -- declaration only if it does not required a body.
1248 elsif Nkind_In
(Main_Unit_Kind
, N_Package_Declaration
,
1249 N_Subprogram_Declaration
)
1251 (not Body_Required
(Main_Unit_Node
)
1252 or else Distribution_Stub_Mode
= Generate_Caller_Stub_Body
)
1254 Back_End_Mode
:= Generate_Object
;
1256 -- We can generate code for a generic package declaration of a generic
1257 -- subprogram declaration only if does not require a body.
1259 elsif Nkind_In
(Main_Unit_Kind
, N_Generic_Package_Declaration
,
1260 N_Generic_Subprogram_Declaration
)
1261 and then not Body_Required
(Main_Unit_Node
)
1263 Back_End_Mode
:= Generate_Object
;
1265 -- Compilation units that are renamings do not require bodies, so we can
1266 -- generate code for them.
1268 elsif Nkind_In
(Main_Unit_Kind
, N_Package_Renaming_Declaration
,
1269 N_Subprogram_Renaming_Declaration
)
1271 Back_End_Mode
:= Generate_Object
;
1273 -- Compilation units that are generic renamings do not require bodies
1274 -- so we can generate code for them.
1276 elsif Main_Unit_Kind
in N_Generic_Renaming_Declaration
then
1277 Back_End_Mode
:= Generate_Object
;
1279 -- It is not an error to analyze in CodePeer mode a spec which requires
1280 -- a body, in order to generate SCIL for this spec.
1281 -- Ditto for Generate_C_Code mode and generate a C header for a spec.
1283 elsif CodePeer_Mode
or Generate_C_Code
then
1284 Back_End_Mode
:= Generate_Object
;
1286 -- It is not an error to analyze in GNATprove mode a spec which requires
1287 -- a body, when the body is not available. During frame condition
1288 -- generation, the corresponding ALI file is generated. During
1289 -- analysis, the spec is analyzed.
1291 elsif GNATprove_Mode
then
1292 Back_End_Mode
:= Declarations_Only
;
1294 -- In all other cases (specs which have bodies, generics, and bodies
1295 -- where subunits are missing), we cannot generate code and we generate
1296 -- a warning message. Note that generic instantiations are gone at this
1297 -- stage since they have been replaced by their instances.
1300 Back_End_Mode
:= Skip
;
1303 -- At this stage Back_End_Mode is set to indicate if the backend should
1304 -- be called to generate code. If it is Skip, then code generation has
1305 -- been turned off, even though code was requested by the original
1306 -- command. This is not an error from the user point of view, but it is
1307 -- an error from the point of view of the gcc driver, so we must exit
1308 -- with an error status.
1310 -- We generate an informative message (from the gcc point of view, it
1311 -- is an error message, but from the users point of view this is not an
1312 -- error, just a consequence of compiling something that cannot
1315 if Back_End_Mode
= Skip
then
1317 -- An ignored Ghost unit is rewritten into a null statement because
1318 -- it must not produce an ALI or object file. Do not emit any errors
1319 -- related to code generation because the unit does not exist.
1321 if Is_Ignored_Ghost_Unit
(Main_Unit_Node
) then
1323 -- Exit the gnat driver with success, otherwise external builders
1324 -- such as gnatmake and gprbuild will treat the compilation of an
1325 -- ignored Ghost unit as a failure. Note that this will produce
1326 -- an empty object file for the unit.
1330 -- Otherwise the unit is missing a crucial piece that prevents code
1337 Write_Str
("cannot generate code for file ");
1338 Write_Name
(Unit_File_Name
(Main_Unit
));
1340 if Subunits_Missing
then
1341 Write_Str
(" (missing subunits)");
1344 -- Force generation of ALI file, for backward compatibility
1346 Opt
.Force_ALI_Tree_File
:= True;
1348 elsif Main_Unit_Kind
= N_Subunit
then
1349 Write_Str
(" (subunit)");
1352 -- Force generation of ALI file, for backward compatibility
1354 Opt
.Force_ALI_Tree_File
:= True;
1356 elsif Main_Unit_Kind
= N_Subprogram_Declaration
then
1357 Write_Str
(" (subprogram spec)");
1360 -- Generic package body in GNAT implementation mode
1362 elsif Main_Unit_Kind
= N_Package_Body
and then GNAT_Mode
then
1363 Write_Str
(" (predefined generic)");
1366 -- Force generation of ALI file, for backward compatibility
1368 Opt
.Force_ALI_Tree_File
:= True;
1370 -- Only other case is a package spec
1373 Write_Str
(" (package spec)");
1378 Set_Standard_Output
;
1380 Post_Compilation_Validation_Checks
;
1381 Errout
.Finalize
(Last_Call
=> True);
1382 Errout
.Output_Messages
;
1386 -- Generate ALI file if specially requested, or for missing subunits,
1387 -- subunits or predefined generic.
1389 if Opt
.Force_ALI_Tree_File
then
1390 Write_ALI
(Object
=> False);
1396 -- Exit the driver with an appropriate status indicator. This will
1397 -- generate an empty object file for ignored Ghost units, otherwise
1398 -- no object file will be generated.
1400 Exit_Program
(Ecode
);
1403 -- In -gnatc mode, we only do annotation if -gnatt or -gnatR is also set
1404 -- as indicated by Back_Annotate_Rep_Info being set to True.
1406 -- We don't call for annotations on a subunit, because to process those
1407 -- the back end requires that the parent(s) be properly compiled.
1409 -- Annotation is suppressed for targets where front-end layout is
1410 -- enabled, because the front end determines representations.
1412 -- The back end is not invoked in ASIS mode with GNSA because all type
1413 -- representation information will be provided by the GNSA back end, not
1416 if Back_End_Mode
= Declarations_Only
1418 (not (Back_Annotate_Rep_Info
or Generate_SCIL
or GNATprove_Mode
)
1419 or else Main_Unit_Kind
= N_Subunit
1420 or else Frontend_Layout_On_Target
1421 or else ASIS_GNSA_Mode
)
1423 Post_Compilation_Validation_Checks
;
1424 Errout
.Finalize
(Last_Call
=> True);
1425 Errout
.Output_Messages
;
1426 Write_ALI
(Object
=> False);
1434 -- Ensure that we properly register a dependency on system.ads, since
1435 -- even if we do not semantically depend on this, Targparm has read
1436 -- system parameters from the system.ads file.
1438 Lib
.Writ
.Ensure_System_Dependency
;
1440 -- Add dependencies, if any, on preprocessing data file and on
1441 -- preprocessing definition file(s).
1443 Prepcomp
.Add_Dependencies
;
1445 -- In gnatprove mode we're writing the ALI much earlier than usual
1446 -- as flow analysis needs the file present in order to append its
1447 -- own globals to it.
1449 if GNATprove_Mode
then
1451 -- Note: In GNATprove mode, an "object" file is always generated as
1452 -- the result of calling gnat1 or gnat2why, although this is not the
1453 -- same as the object file produced for compilation.
1455 Write_ALI
(Object
=> True);
1458 -- Some back ends (for instance Gigi) are known to rely on SCOs for code
1459 -- generation. Make sure they are available.
1461 if Generate_SCO
then
1462 Par_SCO
.SCO_Record_Filtered
;
1465 -- Back end needs to explicitly unlock tables it needs to touch
1479 -- Here we call the back end to generate the output code
1481 Generating_Code
:= True;
1482 Back_End
.Call_Back_End
(Back_End_Mode
);
1484 -- Once the backend is complete, we unlock the names table. This call
1485 -- allows a few extra entries, needed for example for the file name
1486 -- for the library file output.
1490 -- Generate the call-graph output of dispatching calls
1492 Exp_CG
.Generate_CG_Output
;
1494 -- Perform post compilation validation checks
1496 Post_Compilation_Validation_Checks
;
1498 -- Now we complete output of errors, rep info and the tree info. These
1499 -- are delayed till now, since it is perfectly possible for gigi to
1500 -- generate errors, modify the tree (in particular by setting flags
1501 -- indicating that elaboration is required, and also to back annotate
1502 -- representation information for List_Rep_Info).
1504 Errout
.Finalize
(Last_Call
=> True);
1505 Errout
.Output_Messages
;
1506 List_Rep_Info
(Ttypes
.Bytes_Big_Endian
);
1507 Inline
.List_Inlining_Info
;
1509 -- Only write the library if the backend did not generate any error
1510 -- messages. Otherwise signal errors to the driver program so that
1511 -- there will be no attempt to generate an object file.
1513 if Compilation_Errors
then
1515 Exit_Program
(E_Errors
);
1518 if not GNATprove_Mode
then
1519 Write_ALI
(Object
=> (Back_End_Mode
= Generate_Object
));
1522 if not Compilation_Errors
then
1524 -- In case of ada backends, we need to make sure that the generated
1525 -- object file has a timestamp greater than the ALI file. We do this
1526 -- to make gnatmake happy when checking the ALI and obj timestamps,
1527 -- where it expects the object file being written after the ali file.
1529 -- Gnatmake's assumption is true for gcc platforms where the gcc
1530 -- wrapper needs to call the assembler after calling gnat1, but is
1531 -- not true for ada backends, where the object files are created
1532 -- directly by gnat1 (so are created before the ali file).
1534 Back_End
.Gen_Or_Update_Object_File
;
1537 -- Generate ASIS tree after writing the ALI file, since in ASIS mode,
1538 -- Write_ALI may in fact result in further tree decoration from the
1539 -- original tree file. Note that we dump the tree just before generating
1540 -- it, so that the dump will exactly reflect what is written out.
1545 -- Finalize name table and we are all done
1550 -- Handle fatal internal compiler errors
1552 when Rtsfind
.RE_Not_Available
=>
1553 Comperr
.Compiler_Abort
("RE_Not_Available");
1555 when System
.Assertions
.Assert_Failure
=>
1556 Comperr
.Compiler_Abort
("Assert_Failure");
1558 when Constraint_Error
=>
1559 Comperr
.Compiler_Abort
("Constraint_Error");
1561 when Program_Error
=>
1562 Comperr
.Compiler_Abort
("Program_Error");
1564 -- Assume this is a bug. If it is real, the message will in any case
1565 -- say Storage_Error, giving a strong hint.
1567 when Storage_Error
=>
1568 Comperr
.Compiler_Abort
("Storage_Error");
1570 when Unrecoverable_Error
=>
1574 Comperr
.Compiler_Abort
("exception");
1580 -- The outer exception handler handles an unrecoverable error
1583 when Unrecoverable_Error
=>
1584 Errout
.Finalize
(Last_Call
=> True);
1585 Errout
.Output_Messages
;
1588 Write_Str
("compilation abandoned");
1591 Set_Standard_Output
;
1594 Exit_Program
(E_Errors
);