1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1997-2024, 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 -- This package contains routines which handle access-before-elaboration
27 -- run-time checks and compile-time diagnostics. See the body for details.
29 with Namet
; use Namet
;
30 with Types
; use Types
;
38 -- The following type classifies the various enclosing levels used in ABE
41 type Enclosing_Level_Kind
is
43 -- A construct is at the "declaration level" when it appears within the
44 -- declarations of a block statement, an entry body, a subprogram body,
45 -- or a task body, ignoring enclosing packages. Example:
48 -- procedure Proc is -- subprogram body
49 -- package Nested is -- enclosing package ignored
50 -- X ... -- at declaration level
54 -- A construct is at the "generic level" when it appears in a
55 -- generic package library unit, ignoring enclosing packages. Example:
58 -- package Pack is -- generic package spec
59 -- package Nested is -- enclosing package ignored
60 -- X ... -- at generic library level
63 -- A construct is at the "instantiation library level" when it appears
64 -- in a library unit which is also an instantiation. Example:
66 -- package Inst is new Gen; -- at instantiation level
70 -- A construct is at the "library level" when it appears in a package
71 -- library unit, ignoring enclosing packages. Example:
73 -- package body Pack is -- package body
74 -- package Nested is -- enclosing package ignored
75 -- X ... -- at library level
78 -- This value is used to indicate that none of the levels above are in
81 subtype Generic_Level
is Enclosing_Level_Kind
range
85 subtype Library_Level
is Enclosing_Level_Kind
range
89 subtype Library_Or_Instantiation_Level
is Enclosing_Level_Kind
range
90 Instantiation_Level
..
93 procedure Build_Call_Marker
(N
: Node_Id
);
94 pragma Inline
(Build_Call_Marker
);
95 -- Create a call marker for call or requeue statement N and record it for
96 -- later processing by the ABE mechanism.
98 procedure Build_Variable_Reference_Marker
102 pragma Inline
(Build_Variable_Reference_Marker
);
103 -- Create a variable reference marker for arbitrary node N if it mentions a
104 -- variable, and record it for later processing by the ABE mechanism. Flag
105 -- Read should be set when the reference denotes a read. Flag Write should
106 -- be set when the reference denotes a write.
108 procedure Check_Elaboration_Scenarios
;
109 -- Examine each scenario recorded during analysis/resolution and apply the
110 -- Ada or SPARK elaboration rules taking into account the model in effect.
111 -- This processing detects and diagnoses ABE issues, installs conditional
112 -- ABE checks or guaranteed ABE failures, and ensures the elaboration of
115 function Find_Enclosing_Level
(N
: Node_Id
) return Enclosing_Level_Kind
;
116 pragma Inline
(Find_Enclosing_Level
);
117 -- Determine the enclosing level of arbitrary node N
119 procedure Initialize
;
120 pragma Inline
(Initialize
);
121 -- Initialize the internal structures of this unit
123 function Is_Controlled_Procedure
125 Nam
: Name_Id
) return Boolean;
126 -- Determine whether subprogram Id denotes controlled primitive operation
127 -- Adjust, Finalize, or Initialize as specified by Nam.
129 procedure Kill_Elaboration_Scenario
(N
: Node_Id
);
130 -- Determine whether arbitrary node N denotes a scenario which requires
131 -- ABE diagnostics or runtime checks and eliminate it from a region with
134 procedure Record_Elaboration_Scenario
(N
: Node_Id
);
135 pragma Inline
(Record_Elaboration_Scenario
);
136 -- Determine whether atribtray node N denotes a scenario which requires
137 -- ABE diagnostics or runtime checks. If this is the case, store N for
140 ---------------------------------------------------------------------------
142 -- L E G A C Y A C C E S S B E F O R E E L A B O R A T I O N --
144 -- M E C H A N I S M --
146 ---------------------------------------------------------------------------
148 -- This section contains the implementation of the pre-18.x Legacy ABE
149 -- Mechanism. The mechanism can be activated using switch -gnatH (legacy
150 -- elaboration checking mode enabled).
152 procedure Check_Elab_Assign
(N
: Node_Id
);
153 -- N is either the left side of an assignment, or a procedure argument for
154 -- a mode OUT or IN OUT formal. This procedure checks for a possible case
155 -- of access to an entity from elaboration code before the entity has been
156 -- initialized, and issues appropriate warnings.
158 procedure Check_Elab_Call
160 Outer_Scope
: Entity_Id
:= Empty
;
161 In_Init_Proc
: Boolean := False);
162 -- Check a call for possible elaboration problems. The node N is either an
163 -- N_Function_Call or N_Procedure_Call_Statement node or an access
164 -- attribute reference whose prefix is a subprogram.
166 -- If SPARK_Mode is On, then N can also be a variable reference, since
167 -- SPARK requires the use of Elaborate_All for references to variables
168 -- in other packages.
170 -- The Outer_Scope argument indicates whether this is an outer level
171 -- call from Sem_Res (Outer_Scope set to Empty), or an internal recursive
172 -- call (Outer_Scope set to entity of outermost call, see body). The flag
173 -- In_Init_Proc should be set whenever the current context is a type
176 -- Note: this might better be called Check_Elab_Reference (to recognize
177 -- the SPARK case), but we prefer to keep the original name, since this
178 -- is primarily used for checking for calls that could generate an ABE).
180 procedure Check_Elab_Calls
;
181 -- Not all the processing for Check_Elab_Call can be done at the time
182 -- of calls to Check_Elab_Call. This is because for internal calls, we
183 -- need to wait to complete the check until all generic bodies have been
184 -- instantiated. The Check_Elab_Calls procedure cleans up these waiting
185 -- checks. It is called once after the completion of instantiation.
187 procedure Check_Elab_Instantiation
189 Outer_Scope
: Entity_Id
:= Empty
);
190 -- Check an instantiation for possible elaboration problems. N is an
191 -- instantiation node (N_Package_Instantiation, N_Function_Instantiation,
192 -- or N_Procedure_Instantiation), and Outer_Scope indicates if this is
193 -- an outer level call from Sem_Ch12 (Outer_Scope set to Empty), or an
194 -- internal recursive call (Outer_Scope set to scope of outermost call,
195 -- see body for further details). The returned value is relevant only
196 -- for an outer level call, and is set to False if an elaboration error
197 -- is bound to occur on the instantiation, and True otherwise. This is
198 -- used by the caller to signal that the body of the instance should
199 -- not be generated (see detailed description in body).
201 procedure Check_Task_Activation
(N
: Node_Id
);
202 -- At the point at which tasks are activated in a package body, check
203 -- that the bodies of the tasks are elaborated.