1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1997-2022, 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 Types
; use Types
;
37 -- The following type classifies the various enclosing levels used in ABE
40 type Enclosing_Level_Kind
is
42 -- A construct is at the "declaration level" when it appears within the
43 -- declarations of a block statement, an entry body, a subprogram body,
44 -- or a task body, ignoring enclosing packages. Example:
47 -- procedure Proc is -- subprogram body
48 -- package Nested is -- enclosing package ignored
49 -- X ... -- at declaration level
53 -- A construct is at the "generic level" when it appears in a
54 -- generic package library unit, ignoring enclosing packages. Example:
57 -- package Pack is -- generic package spec
58 -- package Nested is -- enclosing package ignored
59 -- X ... -- at generic library level
62 -- A construct is at the "instantiation library level" when it appears
63 -- in a library unit which is also an instantiation. Example:
65 -- package Inst is new Gen; -- at instantiation level
69 -- A construct is at the "library level" when it appears in a package
70 -- library unit, ignoring enclosing packages. Example:
72 -- package body Pack is -- package body
73 -- package Nested is -- enclosing package ignored
74 -- X ... -- at library level
77 -- This value is used to indicate that none of the levels above are in
80 subtype Generic_Level
is Enclosing_Level_Kind
range
84 subtype Library_Level
is Enclosing_Level_Kind
range
88 subtype Library_Or_Instantiation_Level
is Enclosing_Level_Kind
range
89 Instantiation_Level
..
92 procedure Build_Call_Marker
(N
: Node_Id
);
93 pragma Inline
(Build_Call_Marker
);
94 -- Create a call marker for call or requeue statement N and record it for
95 -- later processing by the ABE mechanism.
97 procedure Build_Variable_Reference_Marker
101 pragma Inline
(Build_Variable_Reference_Marker
);
102 -- Create a variable reference marker for arbitrary node N if it mentions a
103 -- variable, and record it for later processing by the ABE mechanism. Flag
104 -- Read should be set when the reference denotes a read. Flag Write should
105 -- be set when the reference denotes a write.
107 procedure Check_Elaboration_Scenarios
;
108 -- Examine each scenario recorded during analysis/resolution and apply the
109 -- Ada or SPARK elaboration rules taking into account the model in effect.
110 -- This processing detects and diagnoses ABE issues, installs conditional
111 -- ABE checks or guaranteed ABE failures, and ensures the elaboration of
114 function Find_Enclosing_Level
(N
: Node_Id
) return Enclosing_Level_Kind
;
115 pragma Inline
(Find_Enclosing_Level
);
116 -- Determine the enclosing level of arbitrary node N
118 procedure Initialize
;
119 pragma Inline
(Initialize
);
120 -- Initialize the internal structures of this unit
122 procedure Kill_Elaboration_Scenario
(N
: Node_Id
);
123 -- Determine whether arbitrary node N denotes a scenario which requires
124 -- ABE diagnostics or runtime checks and eliminate it from a region with
127 procedure Record_Elaboration_Scenario
(N
: Node_Id
);
128 pragma Inline
(Record_Elaboration_Scenario
);
129 -- Determine whether atribtray node N denotes a scenario which requires
130 -- ABE diagnostics or runtime checks. If this is the case, store N for
133 ---------------------------------------------------------------------------
135 -- 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 --
137 -- M E C H A N I S M --
139 ---------------------------------------------------------------------------
141 -- This section contains the implementation of the pre-18.x Legacy ABE
142 -- Mechanism. The mechanism can be activated using switch -gnatH (legacy
143 -- elaboration checking mode enabled).
145 procedure Check_Elab_Assign
(N
: Node_Id
);
146 -- N is either the left side of an assignment, or a procedure argument for
147 -- a mode OUT or IN OUT formal. This procedure checks for a possible case
148 -- of access to an entity from elaboration code before the entity has been
149 -- initialized, and issues appropriate warnings.
151 procedure Check_Elab_Call
153 Outer_Scope
: Entity_Id
:= Empty
;
154 In_Init_Proc
: Boolean := False);
155 -- Check a call for possible elaboration problems. The node N is either an
156 -- N_Function_Call or N_Procedure_Call_Statement node or an access
157 -- attribute reference whose prefix is a subprogram.
159 -- If SPARK_Mode is On, then N can also be a variable reference, since
160 -- SPARK requires the use of Elaborate_All for references to variables
161 -- in other packages.
163 -- The Outer_Scope argument indicates whether this is an outer level
164 -- call from Sem_Res (Outer_Scope set to Empty), or an internal recursive
165 -- call (Outer_Scope set to entity of outermost call, see body). The flag
166 -- In_Init_Proc should be set whenever the current context is a type
169 -- Note: this might better be called Check_Elab_Reference (to recognize
170 -- the SPARK case), but we prefer to keep the original name, since this
171 -- is primarily used for checking for calls that could generate an ABE).
173 procedure Check_Elab_Calls
;
174 -- Not all the processing for Check_Elab_Call can be done at the time
175 -- of calls to Check_Elab_Call. This is because for internal calls, we
176 -- need to wait to complete the check until all generic bodies have been
177 -- instantiated. The Check_Elab_Calls procedure cleans up these waiting
178 -- checks. It is called once after the completion of instantiation.
180 procedure Check_Elab_Instantiation
182 Outer_Scope
: Entity_Id
:= Empty
);
183 -- Check an instantiation for possible elaboration problems. N is an
184 -- instantiation node (N_Package_Instantiation, N_Function_Instantiation,
185 -- or N_Procedure_Instantiation), and Outer_Scope indicates if this is
186 -- an outer level call from Sem_Ch12 (Outer_Scope set to Empty), or an
187 -- internal recursive call (Outer_Scope set to scope of outermost call,
188 -- see body for further details). The returned value is relevant only
189 -- for an outer level call, and is set to False if an elaboration error
190 -- is bound to occur on the instantiation, and True otherwise. This is
191 -- used by the caller to signal that the body of the instance should
192 -- not be generated (see detailed description in body).
194 procedure Check_Task_Activation
(N
: Node_Id
);
195 -- At the point at which tasks are activated in a package body, check
196 -- that the bodies of the tasks are elaborated.