annotate gcc/ada/checks.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- C H E C K S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 -- Package containing routines used to deal with runtime checks. These
kono
parents:
diff changeset
27 -- routines are used both by the semantics and by the expander. In some
kono
parents:
diff changeset
28 -- cases, checks are enabled simply by setting flags for gigi, and in
kono
parents:
diff changeset
29 -- other cases the code for the check is expanded.
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 -- The approach used for range and length checks, in regards to suppressed
kono
parents:
diff changeset
32 -- checks, is to attempt to detect at compilation time that a constraint
kono
parents:
diff changeset
33 -- error will occur. If this is detected a warning or error is issued and the
kono
parents:
diff changeset
34 -- offending expression or statement replaced with a constraint error node.
kono
parents:
diff changeset
35 -- This always occurs whether checks are suppressed or not. Dynamic range
kono
parents:
diff changeset
36 -- checks are, of course, not inserted if checks are suppressed.
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 with Errout; use Errout;
kono
parents:
diff changeset
39 with Namet; use Namet;
kono
parents:
diff changeset
40 with Table;
kono
parents:
diff changeset
41 with Types; use Types;
kono
parents:
diff changeset
42 with Uintp; use Uintp;
kono
parents:
diff changeset
43 with Urealp; use Urealp;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 package Checks is
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 procedure Initialize;
kono
parents:
diff changeset
48 -- Called for each new main source program, to initialize internal
kono
parents:
diff changeset
49 -- variables used in the package body of the Checks unit.
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 function Access_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
52 function Accessibility_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
53 function Alignment_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
54 function Allocation_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
55 function Atomic_Synchronization_Disabled (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
56 function Discriminant_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
57 function Division_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
58 function Duplicated_Tag_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
59 function Elaboration_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
60 function Index_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
61 function Length_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
62 function Overflow_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
63 function Predicate_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
64 function Range_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
65 function Storage_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
66 function Tag_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
67 function Validity_Checks_Suppressed (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
68 -- These functions check to see if the named check is suppressed, either
kono
parents:
diff changeset
69 -- by an active scope suppress setting, or because the check has been
kono
parents:
diff changeset
70 -- specifically suppressed for the given entity. If no entity is relevant
kono
parents:
diff changeset
71 -- for the current check, then Empty is used as an argument. Note: the
kono
parents:
diff changeset
72 -- reason we insist on specifying Empty is to force the caller to think
kono
parents:
diff changeset
73 -- about whether there is any relevant entity that should be checked.
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 function Is_Check_Suppressed (E : Entity_Id; C : Check_Id) return Boolean;
kono
parents:
diff changeset
76 -- This function is called if Checks_May_Be_Suppressed (E) is True to
kono
parents:
diff changeset
77 -- determine whether check C is suppressed either on the entity E or
kono
parents:
diff changeset
78 -- as the result of a scope suppress pragma. If Checks_May_Be_Suppressed
kono
parents:
diff changeset
79 -- is False, then the status of the check can be determined simply by
kono
parents:
diff changeset
80 -- examining Scope_Suppress, so this routine is not called in that case.
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 function Overflow_Check_Mode return Overflow_Mode_Type;
kono
parents:
diff changeset
83 -- Returns current overflow checking mode, taking into account whether
kono
parents:
diff changeset
84 -- we are inside an assertion expression and the assertion policy.
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 -----------------------------------------
kono
parents:
diff changeset
87 -- Control of Alignment Check Warnings --
kono
parents:
diff changeset
88 -----------------------------------------
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 -- When we have address clauses, there is an issue of whether the address
kono
parents:
diff changeset
91 -- specified is appropriate to the alignment. In the general case where the
kono
parents:
diff changeset
92 -- address is dynamic, we generate a check and a possible warning (this
kono
parents:
diff changeset
93 -- warning occurs for example if we have a restricted run time with the
kono
parents:
diff changeset
94 -- restriction No_Exception_Propagation). We also issue this warning in
kono
parents:
diff changeset
95 -- the case where the address is static, but we don't know the alignment
kono
parents:
diff changeset
96 -- at the time we process the address clause. In such a case, we issue the
kono
parents:
diff changeset
97 -- warning, but we may be able to find out later (after the back end has
kono
parents:
diff changeset
98 -- annotated the actual alignment chosen) that the warning was not needed.
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 -- To deal with deleting these potentially annoying warnings, we save the
kono
parents:
diff changeset
101 -- warning information in a table, and then delete the waranings in the
kono
parents:
diff changeset
102 -- post compilation validation stage if we can tell that the check would
kono
parents:
diff changeset
103 -- never fail (in general the back end will also optimize away the check
kono
parents:
diff changeset
104 -- in such cases).
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 -- Table used to record information
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 type Alignment_Warnings_Record is record
kono
parents:
diff changeset
109 E : Entity_Id;
kono
parents:
diff changeset
110 -- Entity whose alignment possibly warrants a warning
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 A : Uint;
kono
parents:
diff changeset
113 -- Compile time known value of address clause for which the alignment
kono
parents:
diff changeset
114 -- is to be checked once we know the alignment.
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 W : Error_Msg_Id;
kono
parents:
diff changeset
117 -- Id of warning message we might delete
kono
parents:
diff changeset
118 end record;
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 package Alignment_Warnings is new Table.Table (
kono
parents:
diff changeset
121 Table_Component_Type => Alignment_Warnings_Record,
kono
parents:
diff changeset
122 Table_Index_Type => Int,
kono
parents:
diff changeset
123 Table_Low_Bound => 0,
kono
parents:
diff changeset
124 Table_Initial => 10,
kono
parents:
diff changeset
125 Table_Increment => 200,
kono
parents:
diff changeset
126 Table_Name => "Alignment_Warnings");
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 procedure Validate_Alignment_Check_Warnings;
kono
parents:
diff changeset
129 -- This routine is called after back annotation of type data to delete any
kono
parents:
diff changeset
130 -- alignment warnings that turn out to be false alarms, based on knowing
kono
parents:
diff changeset
131 -- the actual alignment, and a compile-time known alignment value.
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 -------------------------------------------
kono
parents:
diff changeset
134 -- Procedures to Activate Checking Flags --
kono
parents:
diff changeset
135 -------------------------------------------
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 procedure Activate_Division_Check (N : Node_Id);
kono
parents:
diff changeset
138 pragma Inline (Activate_Division_Check);
kono
parents:
diff changeset
139 -- Sets Do_Division_Check flag in node N, and handles possible local raise.
kono
parents:
diff changeset
140 -- Always call this routine rather than calling Set_Do_Division_Check to
kono
parents:
diff changeset
141 -- set an explicit value of True, to ensure handling the local raise case.
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 procedure Activate_Overflow_Check (N : Node_Id);
kono
parents:
diff changeset
144 pragma Inline (Activate_Overflow_Check);
kono
parents:
diff changeset
145 -- Sets Do_Overflow_Check flag in node N, and handles possible local raise.
kono
parents:
diff changeset
146 -- Always call this routine rather than calling Set_Do_Overflow_Check to
kono
parents:
diff changeset
147 -- set an explicit value of True, to ensure handling the local raise case.
kono
parents:
diff changeset
148 -- Note that for discrete types, this call has no effect for MOD, REM, and
kono
parents:
diff changeset
149 -- unary "+" for which overflow is never possible in any case.
kono
parents:
diff changeset
150 --
kono
parents:
diff changeset
151 -- Note: for the discrete-type case, it is legitimate to call this routine
kono
parents:
diff changeset
152 -- on an unanalyzed node where the Etype field is not set. However, for the
kono
parents:
diff changeset
153 -- floating-point case, Etype must be set (to a floating-point type).
kono
parents:
diff changeset
154 --
kono
parents:
diff changeset
155 -- For floating-point, we set the flag if we have automatic overflow checks
kono
parents:
diff changeset
156 -- on the target, or if Check_Float_Overflow mode is set. For the floating-
kono
parents:
diff changeset
157 -- point case, we ignore all the unary operators ("+", "-", and abs) since
kono
parents:
diff changeset
158 -- none of these can result in overflow. If there are no overflow checks on
kono
parents:
diff changeset
159 -- the target, and Check_Float_Overflow mode is not set, then the call has
kono
parents:
diff changeset
160 -- no effect, since in such cases we want to generate NaN's and infinities.
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 procedure Activate_Range_Check (N : Node_Id);
kono
parents:
diff changeset
163 pragma Inline (Activate_Range_Check);
kono
parents:
diff changeset
164 -- Sets Do_Range_Check flag in node N, and handles possible local raise
kono
parents:
diff changeset
165 -- Always call this routine rather than calling Set_Do_Range_Check to
kono
parents:
diff changeset
166 -- set an explicit value of True, to ensure handling the local raise case.
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 --------------------------------
kono
parents:
diff changeset
169 -- Procedures to Apply Checks --
kono
parents:
diff changeset
170 --------------------------------
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 -- General note on following checks. These checks are always active if
kono
parents:
diff changeset
173 -- Expander_Active and not Inside_A_Generic. They are inactive and have
kono
parents:
diff changeset
174 -- no effect Inside_A_Generic. In the case where not Expander_Active
kono
parents:
diff changeset
175 -- and not Inside_A_Generic, most of them are inactive, but some of them
kono
parents:
diff changeset
176 -- operate anyway since they may generate useful compile time warnings.
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 procedure Apply_Access_Check (N : Node_Id);
kono
parents:
diff changeset
179 -- Determines whether an expression node requires a runtime access
kono
parents:
diff changeset
180 -- check and if so inserts the appropriate run-time check.
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 procedure Apply_Accessibility_Check
kono
parents:
diff changeset
183 (N : Node_Id;
kono
parents:
diff changeset
184 Typ : Entity_Id;
kono
parents:
diff changeset
185 Insert_Node : Node_Id);
kono
parents:
diff changeset
186 -- Given a name N denoting an access parameter, emits a run-time
kono
parents:
diff changeset
187 -- accessibility check (if necessary), checking that the level of
kono
parents:
diff changeset
188 -- the object denoted by the access parameter is not deeper than the
kono
parents:
diff changeset
189 -- level of the type Typ. Program_Error is raised if the check fails.
kono
parents:
diff changeset
190 -- Insert_Node indicates the node where the check should be inserted.
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 procedure Apply_Address_Clause_Check (E : Entity_Id; N : Node_Id);
kono
parents:
diff changeset
193 -- E is the entity for an object which has an address clause. If checks
kono
parents:
diff changeset
194 -- are enabled, then this procedure generates a check that the specified
kono
parents:
diff changeset
195 -- address has an alignment consistent with the alignment of the object,
kono
parents:
diff changeset
196 -- raising PE if this is not the case. The resulting check (if one is
kono
parents:
diff changeset
197 -- generated) is prepended to the Actions list of N_Freeze_Entity node N.
kono
parents:
diff changeset
198 -- Note that the check references E'Alignment, so it cannot be emitted
kono
parents:
diff changeset
199 -- before N (its freeze node), otherwise this would cause an illegal
kono
parents:
diff changeset
200 -- access before elaboration error in GIGI. For the case of a clear overlay
kono
parents:
diff changeset
201 -- situation, we also check that the size of the overlaying object is not
kono
parents:
diff changeset
202 -- larger than the overlaid object.
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 procedure Apply_Arithmetic_Overflow_Check (N : Node_Id);
kono
parents:
diff changeset
205 -- Handle overflow checking for an arithmetic operator. Also handles the
kono
parents:
diff changeset
206 -- cases of ELIMINATED and MINIMIZED overflow checking mode. If the mode
kono
parents:
diff changeset
207 -- is one of the latter two, then this routine can also be called with
kono
parents:
diff changeset
208 -- an if or case expression node to make sure that we properly handle
kono
parents:
diff changeset
209 -- overflow checking for dependent expressions. This routine handles
kono
parents:
diff changeset
210 -- front end vs back end overflow checks (in the front end case it expands
kono
parents:
diff changeset
211 -- the necessary check). Note that divide is handled separately using
kono
parents:
diff changeset
212 -- Apply_Divide_Checks. Node N may or may not have Do_Overflow_Check.
kono
parents:
diff changeset
213 -- In STRICT mode, there is nothing to do if this flag is off, but in
kono
parents:
diff changeset
214 -- MINIMIZED/ELIMINATED mode we still have to deal with possible use
kono
parents:
diff changeset
215 -- of doing operations in Long_Long_Integer or Bignum mode.
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 procedure Apply_Constraint_Check
kono
parents:
diff changeset
218 (N : Node_Id;
kono
parents:
diff changeset
219 Typ : Entity_Id;
kono
parents:
diff changeset
220 No_Sliding : Boolean := False);
kono
parents:
diff changeset
221 -- Top-level procedure, calls all the others depending on the class of
kono
parents:
diff changeset
222 -- Typ. Checks that expression N satisfies the constraint of type Typ.
kono
parents:
diff changeset
223 -- No_Sliding is only relevant for constrained array types, if set to
kono
parents:
diff changeset
224 -- True, it checks that indexes are in range.
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 procedure Apply_Discriminant_Check
kono
parents:
diff changeset
227 (N : Node_Id;
kono
parents:
diff changeset
228 Typ : Entity_Id;
kono
parents:
diff changeset
229 Lhs : Node_Id := Empty);
kono
parents:
diff changeset
230 -- Given an expression N of a discriminated type, or of an access type
kono
parents:
diff changeset
231 -- whose designated type is a discriminanted type, generates a check to
kono
parents:
diff changeset
232 -- ensure that the expression can be converted to the subtype given as
kono
parents:
diff changeset
233 -- the second parameter. Lhs is empty except in the case of assignments,
kono
parents:
diff changeset
234 -- where the target object may be needed to determine the subtype to
kono
parents:
diff changeset
235 -- check against (such as the cases of unconstrained formal parameters
kono
parents:
diff changeset
236 -- and unconstrained aliased objects). For the case of unconstrained
kono
parents:
diff changeset
237 -- formals, the check is performed only if the corresponding actual is
kono
parents:
diff changeset
238 -- constrained, i.e., whether Lhs'Constrained is True.
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 procedure Apply_Divide_Checks (N : Node_Id);
kono
parents:
diff changeset
241 -- The node kind is N_Op_Divide, N_Op_Mod, or N_Op_Rem if either of the
kono
parents:
diff changeset
242 -- flags Do_Division_Check or Do_Overflow_Check is set, then this routine
kono
parents:
diff changeset
243 -- ensures that the appropriate checks are made. Note that overflow can
kono
parents:
diff changeset
244 -- occur in the signed case for the case of the largest negative number
kono
parents:
diff changeset
245 -- divided by minus one. This procedure only applies to Integer types.
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 procedure Apply_Parameter_Aliasing_Checks
kono
parents:
diff changeset
248 (Call : Node_Id;
kono
parents:
diff changeset
249 Subp : Entity_Id);
kono
parents:
diff changeset
250 -- Given a subprogram call Call, add a check to verify that none of the
kono
parents:
diff changeset
251 -- actuals overlap. Subp denotes the subprogram being called.
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 procedure Apply_Parameter_Validity_Checks (Subp : Entity_Id);
kono
parents:
diff changeset
254 -- Given a subprogram Subp, add both a pre and post condition pragmas that
kono
parents:
diff changeset
255 -- verify the proper initialization of scalars in parameters and function
kono
parents:
diff changeset
256 -- results.
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 procedure Apply_Predicate_Check
kono
parents:
diff changeset
259 (N : Node_Id;
kono
parents:
diff changeset
260 Typ : Entity_Id;
kono
parents:
diff changeset
261 Fun : Entity_Id := Empty);
kono
parents:
diff changeset
262 -- N is an expression to which a predicate check may need to be applied for
kono
parents:
diff changeset
263 -- Typ, if Typ has a predicate function. When N is an actual in a call, Fun
kono
parents:
diff changeset
264 -- is the function being called, which is used to generate a better warning
kono
parents:
diff changeset
265 -- if the call leads to an infinite recursion.
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 procedure Apply_Type_Conversion_Checks (N : Node_Id);
kono
parents:
diff changeset
268 -- N is an N_Type_Conversion node. A type conversion actually involves
kono
parents:
diff changeset
269 -- two sorts of checks. The first check is the checks that ensures that
kono
parents:
diff changeset
270 -- the operand in the type conversion fits onto the base type of the
kono
parents:
diff changeset
271 -- subtype it is being converted to (see RM 4.6 (28)-(50)). The second
kono
parents:
diff changeset
272 -- check is there to ensure that once the operand has been converted to
kono
parents:
diff changeset
273 -- a value of the target type, this converted value meets the
kono
parents:
diff changeset
274 -- constraints imposed by the target subtype (see RM 4.6 (51)).
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 procedure Apply_Universal_Integer_Attribute_Checks (N : Node_Id);
kono
parents:
diff changeset
277 -- The argument N is an attribute reference node intended for processing
kono
parents:
diff changeset
278 -- by gigi. The attribute is one that returns a universal integer, but
kono
parents:
diff changeset
279 -- the attribute reference node is currently typed with the expected
kono
parents:
diff changeset
280 -- result type. This routine deals with range and overflow checks needed
kono
parents:
diff changeset
281 -- to make sure that the universal result is in range.
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 function Build_Discriminant_Checks
kono
parents:
diff changeset
284 (N : Node_Id;
kono
parents:
diff changeset
285 T_Typ : Entity_Id)
kono
parents:
diff changeset
286 return Node_Id;
kono
parents:
diff changeset
287 -- Subsidiary routine for Apply_Discriminant_Check. Builds the expression
kono
parents:
diff changeset
288 -- that compares discriminants of the expression with discriminants of the
kono
parents:
diff changeset
289 -- type. Also used directly for membership tests (see Exp_Ch4.Expand_N_In).
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 function Convert_From_Bignum (N : Node_Id) return Node_Id;
kono
parents:
diff changeset
292 -- Returns result of converting node N from Bignum. The returned value is
kono
parents:
diff changeset
293 -- not analyzed, the caller takes responsibility for this. Node N must be
kono
parents:
diff changeset
294 -- a subexpression node of type Bignum. The result is Long_Long_Integer.
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 function Convert_To_Bignum (N : Node_Id) return Node_Id;
kono
parents:
diff changeset
297 -- Returns result of converting node N to Bignum. The returned value is not
kono
parents:
diff changeset
298 -- analyzed, the caller takes responsibility for this. Node N must be a
kono
parents:
diff changeset
299 -- subexpression node of a signed integer type or Bignum type (if it is
kono
parents:
diff changeset
300 -- already a Bignum, the returned value is Relocate_Node (N)).
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 procedure Determine_Range
kono
parents:
diff changeset
303 (N : Node_Id;
kono
parents:
diff changeset
304 OK : out Boolean;
kono
parents:
diff changeset
305 Lo : out Uint;
kono
parents:
diff changeset
306 Hi : out Uint;
kono
parents:
diff changeset
307 Assume_Valid : Boolean := False);
kono
parents:
diff changeset
308 -- N is a node for a subexpression. If N is of a discrete type with no
kono
parents:
diff changeset
309 -- error indications, and no other peculiarities (e.g. missing Etype),
kono
parents:
diff changeset
310 -- then OK is True on return, and Lo and Hi are set to a conservative
kono
parents:
diff changeset
311 -- estimate of the possible range of values of N. Thus if OK is True on
kono
parents:
diff changeset
312 -- return, the value of the subexpression N is known to lie in the range
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
313 -- Lo .. Hi (inclusive). For enumeration and character literals the values
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
314 -- returned are the Pos value in the relevant enumeration type. If the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
315 -- expression is not of a discrete type, or some kind of error condition
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
316 -- is detected, then OK is False on exit, and Lo/Hi are set to No_Uint.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
317 -- Thus the significance of OK being False on return is that no useful
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
318 -- information is available on the range of the expression. Assume_Valid
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
319 -- determines whether the processing is allowed to assume that values are
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
320 -- in range of their subtypes. If it is set to True, then this assumption
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
321 -- is valid, if False, then processing is done using base types to allow
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
322 -- invalid values.
111
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 procedure Determine_Range_R
kono
parents:
diff changeset
325 (N : Node_Id;
kono
parents:
diff changeset
326 OK : out Boolean;
kono
parents:
diff changeset
327 Lo : out Ureal;
kono
parents:
diff changeset
328 Hi : out Ureal;
kono
parents:
diff changeset
329 Assume_Valid : Boolean := False);
kono
parents:
diff changeset
330 -- Similar to Determine_Range, but for a node N of floating-point type. OK
kono
parents:
diff changeset
331 -- is True on return only for IEEE floating-point types and only if we do
kono
parents:
diff changeset
332 -- not have to worry about extended precision (i.e. on the x86, we must be
kono
parents:
diff changeset
333 -- using -msse2 -mfpmath=sse). At the current time, this is used only in
kono
parents:
diff changeset
334 -- GNATprove, though we could consider using it more generally in future.
kono
parents:
diff changeset
335 -- For that to happen, the possibility of arguments of infinite or NaN
kono
parents:
diff changeset
336 -- value should be taken into account, which is not the case currently.
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 procedure Install_Null_Excluding_Check (N : Node_Id);
kono
parents:
diff changeset
339 -- Determines whether an access node requires a runtime access check and
kono
parents:
diff changeset
340 -- if so inserts the appropriate run-time check.
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 procedure Install_Primitive_Elaboration_Check (Subp_Body : Node_Id);
kono
parents:
diff changeset
343 -- Insert a check which ensures that subprogram body Subp_Body has been
kono
parents:
diff changeset
344 -- properly elaborated. The check is installed only when Subp_Body is the
kono
parents:
diff changeset
345 -- body of a nonabstract library-level primitive of a tagged type. Further
kono
parents:
diff changeset
346 -- restrictions may apply, see the body for details.
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 function Make_Bignum_Block (Loc : Source_Ptr) return Node_Id;
kono
parents:
diff changeset
349 -- This function is used by top level overflow checking routines to do a
kono
parents:
diff changeset
350 -- mark/release operation on the secondary stack around bignum operations.
kono
parents:
diff changeset
351 -- The block created looks like:
kono
parents:
diff changeset
352 --
kono
parents:
diff changeset
353 -- declare
kono
parents:
diff changeset
354 -- M : Mark_Id := SS_Mark;
kono
parents:
diff changeset
355 -- begin
kono
parents:
diff changeset
356 -- SS_Release (M);
kono
parents:
diff changeset
357 -- end;
kono
parents:
diff changeset
358 --
kono
parents:
diff changeset
359 -- The idea is that the caller will insert any needed extra declarations
kono
parents:
diff changeset
360 -- after the declaration of M, and any needed statements (in particular
kono
parents:
diff changeset
361 -- the bignum operations) before the call to SS_Release, and then do an
kono
parents:
diff changeset
362 -- Insert_Action of the whole block (it is returned unanalyzed). The Loc
kono
parents:
diff changeset
363 -- parameter is used to supply Sloc values for the constructed tree.
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 procedure Minimize_Eliminate_Overflows
kono
parents:
diff changeset
366 (N : Node_Id;
kono
parents:
diff changeset
367 Lo : out Uint;
kono
parents:
diff changeset
368 Hi : out Uint;
kono
parents:
diff changeset
369 Top_Level : Boolean);
kono
parents:
diff changeset
370 -- This is the main routine for handling MINIMIZED and ELIMINATED overflow
kono
parents:
diff changeset
371 -- processing. On entry N is a node whose result is a signed integer
kono
parents:
diff changeset
372 -- subtype. The Do_Overflow_Check flag may or may not be set on N. If the
kono
parents:
diff changeset
373 -- node is an arithmetic operation, then a range analysis is carried out,
kono
parents:
diff changeset
374 -- and there are three possibilities:
kono
parents:
diff changeset
375 --
kono
parents:
diff changeset
376 -- The node is left unchanged (apart from expansion of an exponentiation
kono
parents:
diff changeset
377 -- operation). This happens if the routine can determine that the result
kono
parents:
diff changeset
378 -- is definitely in range. The Do_Overflow_Check flag is turned off in
kono
parents:
diff changeset
379 -- this case.
kono
parents:
diff changeset
380 --
kono
parents:
diff changeset
381 -- The node is transformed into an arithmetic operation with a result
kono
parents:
diff changeset
382 -- type of Long_Long_Integer.
kono
parents:
diff changeset
383 --
kono
parents:
diff changeset
384 -- The node is transformed into a function call that calls an appropriate
kono
parents:
diff changeset
385 -- function in the System.Bignums package to compute a Bignum result.
kono
parents:
diff changeset
386 --
kono
parents:
diff changeset
387 -- In the first two cases, Lo and Hi are set to the bounds of the possible
kono
parents:
diff changeset
388 -- range of results, computed as accurately as possible. In the third case
kono
parents:
diff changeset
389 -- Lo and Hi are set to No_Uint (there are some cases where we could get an
kono
parents:
diff changeset
390 -- advantage from keeping result ranges for Bignum values, but it could use
kono
parents:
diff changeset
391 -- a lot of space and is very unlikely to be valuable).
kono
parents:
diff changeset
392 --
kono
parents:
diff changeset
393 -- If the node is not an arithmetic operation, then it is unchanged but
kono
parents:
diff changeset
394 -- Lo and Hi are still set (to the bounds of the result subtype if nothing
kono
parents:
diff changeset
395 -- better can be determined).
kono
parents:
diff changeset
396 --
kono
parents:
diff changeset
397 -- Note: this function is recursive, if called with an arithmetic operator,
kono
parents:
diff changeset
398 -- recursive calls are made to process the operands using this procedure.
kono
parents:
diff changeset
399 -- So we end up doing things top down. Nothing happens to an arithmetic
kono
parents:
diff changeset
400 -- expression until this procedure is called on the top level node and
kono
parents:
diff changeset
401 -- then the recursive calls process all the children. We have to do it
kono
parents:
diff changeset
402 -- this way. If we try to do it bottom up in natural expansion order, then
kono
parents:
diff changeset
403 -- there are two problems. First, where do we stash the bounds, and more
kono
parents:
diff changeset
404 -- importantly, semantic processing will be messed up. Consider A+B+C where
kono
parents:
diff changeset
405 -- A,B,C are all of type integer, if we processed A+B before doing semantic
kono
parents:
diff changeset
406 -- analysis of the addition of this result to C, that addition could end up
kono
parents:
diff changeset
407 -- with a Long_Long_Integer left operand and an Integer right operand, and
kono
parents:
diff changeset
408 -- we would get a semantic error.
kono
parents:
diff changeset
409 --
kono
parents:
diff changeset
410 -- The routine is called in three situations if we are operating in either
kono
parents:
diff changeset
411 -- MINIMIZED or ELIMINATED modes.
kono
parents:
diff changeset
412 --
kono
parents:
diff changeset
413 -- Overflow processing applied to the top node of an expression tree when
kono
parents:
diff changeset
414 -- that node is an arithmetic operator. In this case the result is
kono
parents:
diff changeset
415 -- converted to the appropriate result type (there is special processing
kono
parents:
diff changeset
416 -- when the parent is a conversion, see body for details).
kono
parents:
diff changeset
417 --
kono
parents:
diff changeset
418 -- Overflow processing applied to the operands of a comparison operation.
kono
parents:
diff changeset
419 -- In this case, the comparison is done on the result Long_Long_Integer
kono
parents:
diff changeset
420 -- or Bignum values, without raising any exceptions.
kono
parents:
diff changeset
421 --
kono
parents:
diff changeset
422 -- Overflow processing applied to the left operand of a membership test.
kono
parents:
diff changeset
423 -- In this case no exception is raised if a Long_Long_Integer or Bignum
kono
parents:
diff changeset
424 -- result is outside the range of the type of that left operand (it is
kono
parents:
diff changeset
425 -- just that the result of IN is false in that case).
kono
parents:
diff changeset
426 --
kono
parents:
diff changeset
427 -- Note that if Bignum values appear, the caller must take care of doing
kono
parents:
diff changeset
428 -- the appropriate mark/release operations on the secondary stack.
kono
parents:
diff changeset
429 --
kono
parents:
diff changeset
430 -- Top_Level is used to avoid inefficient unnecessary transitions into the
kono
parents:
diff changeset
431 -- Bignum domain. If Top_Level is True, it means that the caller will have
kono
parents:
diff changeset
432 -- to convert any Bignum value back to Long_Long_Integer, possibly checking
kono
parents:
diff changeset
433 -- that the value is in range. This is the normal case for a top level
kono
parents:
diff changeset
434 -- operator in a subexpression. There is no point in going into Bignum mode
kono
parents:
diff changeset
435 -- to avoid an overflow just so we can check for overflow the next moment.
kono
parents:
diff changeset
436 -- For calls from comparisons and membership tests, and for all recursive
kono
parents:
diff changeset
437 -- calls, we do want to transition into the Bignum domain if necessary.
kono
parents:
diff changeset
438 -- Note that this setting is only relevant in ELIMINATED mode.
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 -------------------------------------------------------
kono
parents:
diff changeset
441 -- Control and Optimization of Range/Overflow Checks --
kono
parents:
diff changeset
442 -------------------------------------------------------
kono
parents:
diff changeset
443
kono
parents:
diff changeset
444 -- Range checks are controlled by the Do_Range_Check flag. The front end
kono
parents:
diff changeset
445 -- is responsible for setting this flag in relevant nodes. Originally
kono
parents:
diff changeset
446 -- the back end generated all corresponding range checks. But later on
kono
parents:
diff changeset
447 -- we decided to generate many range checks in the front end. We are now
kono
parents:
diff changeset
448 -- in the transitional phase where some of these checks are still done
kono
parents:
diff changeset
449 -- by the back end, but many are done by the front end. It is possible
kono
parents:
diff changeset
450 -- that in the future we might move all the checks to the front end. The
kono
parents:
diff changeset
451 -- main remaining back end checks are for subscript checking.
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 -- Overflow checks are similarly controlled by the Do_Overflow_Check flag.
kono
parents:
diff changeset
454 -- The difference here is that if back end overflow checks are inactive
kono
parents:
diff changeset
455 -- (Backend_Overflow_Checks_On_Target set False), then the actual overflow
kono
parents:
diff changeset
456 -- checks are generated by the front end, but if back end overflow checks
kono
parents:
diff changeset
457 -- are active (Backend_Overflow_Checks_On_Target set True), then the back
kono
parents:
diff changeset
458 -- end does generate the checks.
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 -- The following two routines are used to set these flags, they allow
kono
parents:
diff changeset
461 -- for the possibility of eliminating checks. Checks can be eliminated
kono
parents:
diff changeset
462 -- if an identical check has already been performed.
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 procedure Enable_Overflow_Check (N : Node_Id);
kono
parents:
diff changeset
465 -- First this routine determines if an overflow check is needed by doing
kono
parents:
diff changeset
466 -- an appropriate range check. If a check is not needed, then the call
kono
parents:
diff changeset
467 -- has no effect. If a check is needed then this routine sets the flag
kono
parents:
diff changeset
468 -- Do_Overflow_Check in node N to True, unless it can be determined that
kono
parents:
diff changeset
469 -- the check is not needed. The only condition under which this is the
kono
parents:
diff changeset
470 -- case is if there was an identical check earlier on.
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472 procedure Enable_Range_Check (N : Node_Id);
kono
parents:
diff changeset
473 -- Set Do_Range_Check flag in node N True, unless it can be determined
kono
parents:
diff changeset
474 -- that the check is not needed. The only condition under which this is
kono
parents:
diff changeset
475 -- the case is if there was an identical check earlier on. This routine
kono
parents:
diff changeset
476 -- is not responsible for doing range analysis to determine whether or
kono
parents:
diff changeset
477 -- not such a check is needed -- the caller is expected to do this. The
kono
parents:
diff changeset
478 -- one other case in which the request to set the flag is ignored is
kono
parents:
diff changeset
479 -- when Kill_Range_Check is set in an N_Unchecked_Conversion node.
kono
parents:
diff changeset
480
kono
parents:
diff changeset
481 -- The following routines are used to keep track of processing sequences
kono
parents:
diff changeset
482 -- of statements (e.g. the THEN statements of an IF statement). A check
kono
parents:
diff changeset
483 -- that appears within such a sequence can eliminate an identical check
kono
parents:
diff changeset
484 -- within this sequence of statements. However, after the end of the
kono
parents:
diff changeset
485 -- sequence of statements, such a check is no longer of interest, since
kono
parents:
diff changeset
486 -- it may not have been executed.
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 procedure Conditional_Statements_Begin;
kono
parents:
diff changeset
489 -- This call marks the start of processing of a sequence of statements.
kono
parents:
diff changeset
490 -- Every call to this procedure must be followed by a matching call to
kono
parents:
diff changeset
491 -- Conditional_Statements_End.
kono
parents:
diff changeset
492
kono
parents:
diff changeset
493 procedure Conditional_Statements_End;
kono
parents:
diff changeset
494 -- This call removes from consideration all saved checks since the
kono
parents:
diff changeset
495 -- corresponding call to Conditional_Statements_Begin. These two
kono
parents:
diff changeset
496 -- procedures operate in a stack like manner.
kono
parents:
diff changeset
497
kono
parents:
diff changeset
498 -- The mechanism for optimizing checks works by remembering checks
kono
parents:
diff changeset
499 -- that have already been made, but certain conditions, for example
kono
parents:
diff changeset
500 -- an assignment to a variable involved in a check, may mean that the
kono
parents:
diff changeset
501 -- remembered check is no longer valid, in the sense that if the same
kono
parents:
diff changeset
502 -- expression appears again, another check is required because the
kono
parents:
diff changeset
503 -- value may have changed.
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 -- The following routines are used to note conditions which may render
kono
parents:
diff changeset
506 -- some or all of the stored and remembered checks to be invalidated.
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 procedure Kill_Checks (V : Entity_Id);
kono
parents:
diff changeset
509 -- This procedure records an assignment or other condition that causes
kono
parents:
diff changeset
510 -- the value of the variable to be changed, invalidating any stored
kono
parents:
diff changeset
511 -- checks that reference the value. Note that all such checks must
kono
parents:
diff changeset
512 -- be discarded, even if they are not in the current statement range.
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 procedure Kill_All_Checks;
kono
parents:
diff changeset
515 -- This procedure kills all remembered checks
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517 -----------------------------
kono
parents:
diff changeset
518 -- Length and Range Checks --
kono
parents:
diff changeset
519 -----------------------------
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 -- In the following procedures, there are three arguments which have
kono
parents:
diff changeset
522 -- a common meaning as follows:
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524 -- Expr The expression to be checked. If a check is required,
kono
parents:
diff changeset
525 -- the appropriate flag will be placed on this node. Whether
kono
parents:
diff changeset
526 -- this node is further examined depends on the setting of
kono
parents:
diff changeset
527 -- the parameter Source_Typ, as described below.
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 -- ??? Apply_Length_Check and Apply_Range_Check do not have an Expr
kono
parents:
diff changeset
530 -- formal
kono
parents:
diff changeset
531
kono
parents:
diff changeset
532 -- ??? Apply_Length_Check and Apply_Range_Check have a Ck_Node formal
kono
parents:
diff changeset
533 -- which is undocumented, is it the same as Expr?
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 -- Target_Typ The target type on which the check is to be based. For
kono
parents:
diff changeset
536 -- example, if we have a scalar range check, then the check
kono
parents:
diff changeset
537 -- is that we are in range of this type.
kono
parents:
diff changeset
538
kono
parents:
diff changeset
539 -- Source_Typ Normally Empty, but can be set to a type, in which case
kono
parents:
diff changeset
540 -- this type is used for the check, see below.
kono
parents:
diff changeset
541
kono
parents:
diff changeset
542 -- The checks operate in one of two modes:
kono
parents:
diff changeset
543
kono
parents:
diff changeset
544 -- If Source_Typ is Empty, then the node Expr is examined, at the very
kono
parents:
diff changeset
545 -- least to get the source subtype. In addition for some of the checks,
kono
parents:
diff changeset
546 -- the actual form of the node may be examined. For example, a node of
kono
parents:
diff changeset
547 -- type Integer whose actual form is an Integer conversion from a type
kono
parents:
diff changeset
548 -- with range 0 .. 3 can be determined to have a value in range 0 .. 3.
kono
parents:
diff changeset
549
kono
parents:
diff changeset
550 -- If Source_Typ is given, then nothing can be assumed about the Expr,
kono
parents:
diff changeset
551 -- and indeed its contents are not examined. In this case the check is
kono
parents:
diff changeset
552 -- based on the assumption that Expr can be an arbitrary value of the
kono
parents:
diff changeset
553 -- given Source_Typ.
kono
parents:
diff changeset
554
kono
parents:
diff changeset
555 -- Currently, the only case in which a Source_Typ is explicitly supplied
kono
parents:
diff changeset
556 -- is for the case of Out and In_Out parameters, where, for the conversion
kono
parents:
diff changeset
557 -- on return (the Out direction), the types must be reversed. This is
kono
parents:
diff changeset
558 -- handled by the caller.
kono
parents:
diff changeset
559
kono
parents:
diff changeset
560 procedure Apply_Length_Check
kono
parents:
diff changeset
561 (Ck_Node : Node_Id;
kono
parents:
diff changeset
562 Target_Typ : Entity_Id;
kono
parents:
diff changeset
563 Source_Typ : Entity_Id := Empty);
kono
parents:
diff changeset
564 -- This procedure builds a sequence of declarations to do a length check
kono
parents:
diff changeset
565 -- that checks if the lengths of the two arrays Target_Typ and source type
kono
parents:
diff changeset
566 -- are the same. The resulting actions are inserted at Node using a call
kono
parents:
diff changeset
567 -- to Insert_Actions.
kono
parents:
diff changeset
568 --
kono
parents:
diff changeset
569 -- For access types, the Directly_Designated_Type is retrieved and
kono
parents:
diff changeset
570 -- processing continues as enumerated above, with a guard against null
kono
parents:
diff changeset
571 -- values.
kono
parents:
diff changeset
572 --
kono
parents:
diff changeset
573 -- Note: calls to Apply_Length_Check currently never supply an explicit
kono
parents:
diff changeset
574 -- Source_Typ parameter, but Apply_Length_Check takes this parameter and
kono
parents:
diff changeset
575 -- processes it as described above for consistency with the other routines
kono
parents:
diff changeset
576 -- in this section.
kono
parents:
diff changeset
577
kono
parents:
diff changeset
578 procedure Apply_Range_Check
kono
parents:
diff changeset
579 (Ck_Node : Node_Id;
kono
parents:
diff changeset
580 Target_Typ : Entity_Id;
kono
parents:
diff changeset
581 Source_Typ : Entity_Id := Empty);
kono
parents:
diff changeset
582 -- For a Node of kind N_Range, constructs a range check action that tests
kono
parents:
diff changeset
583 -- first that the range is not null and then that the range is contained in
kono
parents:
diff changeset
584 -- the Target_Typ range.
kono
parents:
diff changeset
585 --
kono
parents:
diff changeset
586 -- For scalar types, constructs a range check action that first tests that
kono
parents:
diff changeset
587 -- the expression is contained in the Target_Typ range. The difference
kono
parents:
diff changeset
588 -- between this and Apply_Scalar_Range_Check is that the latter generates
kono
parents:
diff changeset
589 -- the actual checking code against the Etype of the expression.
kono
parents:
diff changeset
590 --
kono
parents:
diff changeset
591 -- For constrained array types, construct series of range check actions
kono
parents:
diff changeset
592 -- to check that each Expr range is properly contained in the range of
kono
parents:
diff changeset
593 -- Target_Typ.
kono
parents:
diff changeset
594 --
kono
parents:
diff changeset
595 -- For a type conversion to an unconstrained array type, constructs a range
kono
parents:
diff changeset
596 -- check action to check that the bounds of the source type are within the
kono
parents:
diff changeset
597 -- constraints imposed by the Target_Typ.
kono
parents:
diff changeset
598 --
kono
parents:
diff changeset
599 -- For access types, the Directly_Designated_Type is retrieved and
kono
parents:
diff changeset
600 -- processing continues as enumerated above, with a guard against null
kono
parents:
diff changeset
601 -- values.
kono
parents:
diff changeset
602 --
kono
parents:
diff changeset
603 -- The source type is used by type conversions to unconstrained array
kono
parents:
diff changeset
604 -- types to retrieve the corresponding bounds.
kono
parents:
diff changeset
605
kono
parents:
diff changeset
606 procedure Apply_Static_Length_Check
kono
parents:
diff changeset
607 (Expr : Node_Id;
kono
parents:
diff changeset
608 Target_Typ : Entity_Id;
kono
parents:
diff changeset
609 Source_Typ : Entity_Id := Empty);
kono
parents:
diff changeset
610 -- Tries to determine statically whether the two array types source type
kono
parents:
diff changeset
611 -- and Target_Typ have the same length. If it can be determined at compile
kono
parents:
diff changeset
612 -- time that they do not, then an N_Raise_Constraint_Error node replaces
kono
parents:
diff changeset
613 -- Expr, and a warning message is issued.
kono
parents:
diff changeset
614
kono
parents:
diff changeset
615 procedure Apply_Scalar_Range_Check
kono
parents:
diff changeset
616 (Expr : Node_Id;
kono
parents:
diff changeset
617 Target_Typ : Entity_Id;
kono
parents:
diff changeset
618 Source_Typ : Entity_Id := Empty;
kono
parents:
diff changeset
619 Fixed_Int : Boolean := False);
kono
parents:
diff changeset
620 -- For scalar types, determines whether an expression node should be
kono
parents:
diff changeset
621 -- flagged as needing a runtime range check. If the node requires such a
kono
parents:
diff changeset
622 -- check, the Do_Range_Check flag is turned on. The Fixed_Int flag if set
kono
parents:
diff changeset
623 -- causes any fixed-point values to be treated as though they were discrete
kono
parents:
diff changeset
624 -- values (i.e. the underlying integer value is used).
kono
parents:
diff changeset
625
kono
parents:
diff changeset
626 type Check_Result is private;
kono
parents:
diff changeset
627 -- Type used to return result of Get_Range_Checks call, for later use in
kono
parents:
diff changeset
628 -- call to Insert_Range_Checks procedure.
kono
parents:
diff changeset
629
kono
parents:
diff changeset
630 function Get_Range_Checks
kono
parents:
diff changeset
631 (Ck_Node : Node_Id;
kono
parents:
diff changeset
632 Target_Typ : Entity_Id;
kono
parents:
diff changeset
633 Source_Typ : Entity_Id := Empty;
kono
parents:
diff changeset
634 Warn_Node : Node_Id := Empty) return Check_Result;
kono
parents:
diff changeset
635 -- Like Apply_Range_Check, except it does not modify anything. Instead
kono
parents:
diff changeset
636 -- it returns an encapsulated result of the check operations for later
kono
parents:
diff changeset
637 -- use in a call to Insert_Range_Checks. If Warn_Node is non-empty, its
kono
parents:
diff changeset
638 -- Sloc is used, in the static case, for the generated warning or error.
kono
parents:
diff changeset
639 -- Additionally, it is used rather than Expr (or Low/High_Bound of Expr)
kono
parents:
diff changeset
640 -- in constructing the check.
kono
parents:
diff changeset
641
kono
parents:
diff changeset
642 procedure Append_Range_Checks
kono
parents:
diff changeset
643 (Checks : Check_Result;
kono
parents:
diff changeset
644 Stmts : List_Id;
kono
parents:
diff changeset
645 Suppress_Typ : Entity_Id;
kono
parents:
diff changeset
646 Static_Sloc : Source_Ptr;
kono
parents:
diff changeset
647 Flag_Node : Node_Id);
kono
parents:
diff changeset
648 -- Called to append range checks as returned by a call to Get_Range_Checks.
kono
parents:
diff changeset
649 -- Stmts is a list to which either the dynamic check is appended or the
kono
parents:
diff changeset
650 -- raise Constraint_Error statement is appended (for static checks).
kono
parents:
diff changeset
651 -- Static_Sloc is the Sloc at which the raise CE node points, Flag_Node is
kono
parents:
diff changeset
652 -- used as the node at which to set the Has_Dynamic_Check flag. Checks_On
kono
parents:
diff changeset
653 -- is a boolean value that says if range and index checking is on or not.
kono
parents:
diff changeset
654
kono
parents:
diff changeset
655 procedure Insert_Range_Checks
kono
parents:
diff changeset
656 (Checks : Check_Result;
kono
parents:
diff changeset
657 Node : Node_Id;
kono
parents:
diff changeset
658 Suppress_Typ : Entity_Id;
kono
parents:
diff changeset
659 Static_Sloc : Source_Ptr := No_Location;
kono
parents:
diff changeset
660 Flag_Node : Node_Id := Empty;
kono
parents:
diff changeset
661 Do_Before : Boolean := False);
kono
parents:
diff changeset
662 -- Called to insert range checks as returned by a call to Get_Range_Checks.
kono
parents:
diff changeset
663 -- Node is the node after which either the dynamic check is inserted or
kono
parents:
diff changeset
664 -- the raise Constraint_Error statement is inserted (for static checks).
kono
parents:
diff changeset
665 -- Suppress_Typ is the type to check to determine if checks are suppressed.
kono
parents:
diff changeset
666 -- Static_Sloc, if passed, is the Sloc at which the raise CE node points,
kono
parents:
diff changeset
667 -- otherwise Sloc (Node) is used. The Has_Dynamic_Check flag is normally
kono
parents:
diff changeset
668 -- set at Node. If Flag_Node is present, then this is used instead as the
kono
parents:
diff changeset
669 -- node at which to set the Has_Dynamic_Check flag. Normally the check is
kono
parents:
diff changeset
670 -- inserted after, if Do_Before is True, the check is inserted before
kono
parents:
diff changeset
671 -- Node.
kono
parents:
diff changeset
672
kono
parents:
diff changeset
673 -----------------------
kono
parents:
diff changeset
674 -- Expander Routines --
kono
parents:
diff changeset
675 -----------------------
kono
parents:
diff changeset
676
kono
parents:
diff changeset
677 -- Some of the earlier processing for checks results in temporarily setting
kono
parents:
diff changeset
678 -- the Do_Range_Check flag rather than actually generating checks. Now we
kono
parents:
diff changeset
679 -- are moving the generation of such checks into the front end for reasons
kono
parents:
diff changeset
680 -- of efficiency and simplicity (there were difficulties in handling this
kono
parents:
diff changeset
681 -- in the back end when side effects were present in the expressions being
kono
parents:
diff changeset
682 -- checked).
kono
parents:
diff changeset
683
kono
parents:
diff changeset
684 -- Probably we could eliminate the Do_Range_Check flag entirely and
kono
parents:
diff changeset
685 -- generate the checks earlier, but this is a delicate area and it
kono
parents:
diff changeset
686 -- seemed safer to implement the following routines, which are called
kono
parents:
diff changeset
687 -- late on in the expansion process. They check the Do_Range_Check flag
kono
parents:
diff changeset
688 -- and if it is set, generate the actual checks and reset the flag.
kono
parents:
diff changeset
689
kono
parents:
diff changeset
690 procedure Generate_Range_Check
kono
parents:
diff changeset
691 (N : Node_Id;
kono
parents:
diff changeset
692 Target_Type : Entity_Id;
kono
parents:
diff changeset
693 Reason : RT_Exception_Code);
kono
parents:
diff changeset
694 -- This procedure is called to actually generate and insert a range check.
kono
parents:
diff changeset
695 -- A check is generated to ensure that the value of N lies within the range
kono
parents:
diff changeset
696 -- of the target type. Note that the base type of N may be different from
kono
parents:
diff changeset
697 -- the base type of the target type. This happens in the conversion case.
kono
parents:
diff changeset
698 -- The Reason parameter is the exception code to be used for the exception
kono
parents:
diff changeset
699 -- if raised.
kono
parents:
diff changeset
700 --
kono
parents:
diff changeset
701 -- Note: if the expander is not active, or if we are in GNATprove mode,
kono
parents:
diff changeset
702 -- then we do not generate explicit range code. Instead we just turn the
kono
parents:
diff changeset
703 -- Do_Range_Check flag on, since in these cases that's what we want to see
kono
parents:
diff changeset
704 -- in the tree (GNATprove in particular depends on this flag being set). If
kono
parents:
diff changeset
705 -- we generate the actual range check, then we make sure the flag is off,
kono
parents:
diff changeset
706 -- since the code we generate takes complete care of the check.
kono
parents:
diff changeset
707 --
kono
parents:
diff changeset
708 -- Historical note: We used to just pass on the Do_Range_Check flag to the
kono
parents:
diff changeset
709 -- back end to generate the check, but now in code-generation mode we never
kono
parents:
diff changeset
710 -- have this flag set, since the front end takes care of the check. The
kono
parents:
diff changeset
711 -- normal processing flow now is that the analyzer typically turns on the
kono
parents:
diff changeset
712 -- Do_Range_Check flag, and if it is set, this routine is called, which
kono
parents:
diff changeset
713 -- turns the flag off in code-generation mode.
kono
parents:
diff changeset
714
kono
parents:
diff changeset
715 procedure Generate_Index_Checks (N : Node_Id);
kono
parents:
diff changeset
716 -- This procedure is called to generate index checks on the subscripts for
kono
parents:
diff changeset
717 -- the indexed component node N. Each subscript expression is examined, and
kono
parents:
diff changeset
718 -- if the Do_Range_Check flag is set, an appropriate index check is
kono
parents:
diff changeset
719 -- generated and the flag is reset.
kono
parents:
diff changeset
720
kono
parents:
diff changeset
721 -- Similarly, we set the flag Do_Discriminant_Check in the semantic
kono
parents:
diff changeset
722 -- analysis to indicate that a discriminant check is required for selected
kono
parents:
diff changeset
723 -- component of a discriminated type. The following routine is called from
kono
parents:
diff changeset
724 -- the expander to actually generate the call.
kono
parents:
diff changeset
725
kono
parents:
diff changeset
726 procedure Generate_Discriminant_Check (N : Node_Id);
kono
parents:
diff changeset
727 -- N is a selected component for which a discriminant check is required to
kono
parents:
diff changeset
728 -- make sure that the discriminants have appropriate values for the
kono
parents:
diff changeset
729 -- selection. This is done by calling the appropriate discriminant checking
kono
parents:
diff changeset
730 -- routine for the selector.
kono
parents:
diff changeset
731
kono
parents:
diff changeset
732 -----------------------
kono
parents:
diff changeset
733 -- Validity Checking --
kono
parents:
diff changeset
734 -----------------------
kono
parents:
diff changeset
735
kono
parents:
diff changeset
736 -- In (RM 13.9.1(9-11)) we have the following rules on invalid values
kono
parents:
diff changeset
737
kono
parents:
diff changeset
738 -- If the representation of a scalar object does not represent value of
kono
parents:
diff changeset
739 -- the object's subtype (perhaps because the object was not initialized),
kono
parents:
diff changeset
740 -- the object is said to have an invalid representation. It is a bounded
kono
parents:
diff changeset
741 -- error to evaluate the value of such an object. If the error is
kono
parents:
diff changeset
742 -- detected, either Constraint_Error or Program_Error is raised.
kono
parents:
diff changeset
743 -- Otherwise, execution continues using the invalid representation. The
kono
parents:
diff changeset
744 -- rules of the language outside this subclause assume that all objects
kono
parents:
diff changeset
745 -- have valid representations. The semantics of operations on invalid
kono
parents:
diff changeset
746 -- representations are as follows:
kono
parents:
diff changeset
747 --
kono
parents:
diff changeset
748 -- 10 If the representation of the object represents a value of the
kono
parents:
diff changeset
749 -- object's type, the value of the type is used.
kono
parents:
diff changeset
750 --
kono
parents:
diff changeset
751 -- 11 If the representation of the object does not represent a value
kono
parents:
diff changeset
752 -- of the object's type, the semantics of operations on such
kono
parents:
diff changeset
753 -- representations is implementation-defined, but does not by
kono
parents:
diff changeset
754 -- itself lead to erroneous or unpredictable execution, or to
kono
parents:
diff changeset
755 -- other objects becoming abnormal.
kono
parents:
diff changeset
756
kono
parents:
diff changeset
757 -- We quote the rules in full here since they are quite delicate. Most
kono
parents:
diff changeset
758 -- of the time, we can just compute away with wrong values, and get a
kono
parents:
diff changeset
759 -- possibly wrong result, which is well within the range of allowed
kono
parents:
diff changeset
760 -- implementation defined behavior. The two tricky cases are subscripted
kono
parents:
diff changeset
761 -- array assignments, where we don't want to do wild stores, and case
kono
parents:
diff changeset
762 -- statements where we don't want to do wild jumps.
kono
parents:
diff changeset
763
kono
parents:
diff changeset
764 -- In GNAT, we control validity checking with a switch -gnatV that can take
kono
parents:
diff changeset
765 -- three parameters, n/d/f for None/Default/Full. These modes have the
kono
parents:
diff changeset
766 -- following meanings:
kono
parents:
diff changeset
767
kono
parents:
diff changeset
768 -- None (no validity checking)
kono
parents:
diff changeset
769
kono
parents:
diff changeset
770 -- In this mode, there is no specific checking for invalid values
kono
parents:
diff changeset
771 -- and the code generator assumes that all stored values are always
kono
parents:
diff changeset
772 -- within the bounds of the object subtype. The consequences are as
kono
parents:
diff changeset
773 -- follows:
kono
parents:
diff changeset
774
kono
parents:
diff changeset
775 -- For case statements, an out of range invalid value will cause
kono
parents:
diff changeset
776 -- Constraint_Error to be raised, or an arbitrary one of the case
kono
parents:
diff changeset
777 -- alternatives will be executed. Wild jumps cannot result even
kono
parents:
diff changeset
778 -- in this mode, since we always do a range check
kono
parents:
diff changeset
779
kono
parents:
diff changeset
780 -- For subscripted array assignments, wild stores will result in
kono
parents:
diff changeset
781 -- the expected manner when addresses are calculated using values
kono
parents:
diff changeset
782 -- of subscripts that are out of range.
kono
parents:
diff changeset
783
kono
parents:
diff changeset
784 -- It could perhaps be argued that this mode is still conformant with
kono
parents:
diff changeset
785 -- the letter of the RM, since implementation defined is a rather
kono
parents:
diff changeset
786 -- broad category, but certainly it is not in the spirit of the
kono
parents:
diff changeset
787 -- RM requirement, since wild stores certainly seem to be a case of
kono
parents:
diff changeset
788 -- erroneous behavior.
kono
parents:
diff changeset
789
kono
parents:
diff changeset
790 -- Default (default standard RM-compatible validity checking)
kono
parents:
diff changeset
791
kono
parents:
diff changeset
792 -- In this mode, which is the default, minimal validity checking is
kono
parents:
diff changeset
793 -- performed to ensure no erroneous behavior as follows:
kono
parents:
diff changeset
794
kono
parents:
diff changeset
795 -- For case statements, an out of range invalid value will cause
kono
parents:
diff changeset
796 -- Constraint_Error to be raised.
kono
parents:
diff changeset
797
kono
parents:
diff changeset
798 -- For subscripted array assignments, invalid out of range
kono
parents:
diff changeset
799 -- subscript values will cause Constraint_Error to be raised.
kono
parents:
diff changeset
800
kono
parents:
diff changeset
801 -- Full (Full validity checking)
kono
parents:
diff changeset
802
kono
parents:
diff changeset
803 -- In this mode, the protections guaranteed by the standard mode are
kono
parents:
diff changeset
804 -- in place, and the following additional checks are made:
kono
parents:
diff changeset
805
kono
parents:
diff changeset
806 -- For every assignment, the right side is checked for validity
kono
parents:
diff changeset
807
kono
parents:
diff changeset
808 -- For every call, IN and IN OUT parameters are checked for validity
kono
parents:
diff changeset
809
kono
parents:
diff changeset
810 -- For every subscripted array reference, both for stores and loads,
kono
parents:
diff changeset
811 -- all subscripts are checked for validity.
kono
parents:
diff changeset
812
kono
parents:
diff changeset
813 -- These checks are not required by the RM, but will in practice
kono
parents:
diff changeset
814 -- improve the detection of uninitialized variables, particularly
kono
parents:
diff changeset
815 -- if used in conjunction with pragma Normalize_Scalars.
kono
parents:
diff changeset
816
kono
parents:
diff changeset
817 -- In the above description, we talk about performing validity checks,
kono
parents:
diff changeset
818 -- but we don't actually generate a check in a case where the compiler
kono
parents:
diff changeset
819 -- can be sure that the value is valid. Note that this assurance must
kono
parents:
diff changeset
820 -- be achieved without assuming that any uninitialized value lies within
kono
parents:
diff changeset
821 -- the range of its type. The following are cases in which values are
kono
parents:
diff changeset
822 -- known to be valid. The flag Is_Known_Valid is used to keep track of
kono
parents:
diff changeset
823 -- some of these cases.
kono
parents:
diff changeset
824
kono
parents:
diff changeset
825 -- If all possible stored values are valid, then any uninitialized
kono
parents:
diff changeset
826 -- value must be valid.
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 -- Literals, including enumeration literals, are clearly always valid
kono
parents:
diff changeset
829
kono
parents:
diff changeset
830 -- Constants are always assumed valid, with a validity check being
kono
parents:
diff changeset
831 -- performed on the initializing value where necessary to ensure that
kono
parents:
diff changeset
832 -- this is the case.
kono
parents:
diff changeset
833
kono
parents:
diff changeset
834 -- For variables, the status is set to known valid if there is an
kono
parents:
diff changeset
835 -- initializing expression. Again a check is made on the initializing
kono
parents:
diff changeset
836 -- value if necessary to ensure that this assumption is valid. The
kono
parents:
diff changeset
837 -- status can change as a result of local assignments to a variable.
kono
parents:
diff changeset
838 -- If a known valid value is unconditionally assigned, then we mark
kono
parents:
diff changeset
839 -- the left side as known valid. If a value is assigned that is not
kono
parents:
diff changeset
840 -- known to be valid, then we mark the left side as invalid. This
kono
parents:
diff changeset
841 -- kind of processing does NOT apply to non-local variables since we
kono
parents:
diff changeset
842 -- are not following the flow graph (more properly the flow of actual
kono
parents:
diff changeset
843 -- processing only corresponds to the flow graph for local assignments).
kono
parents:
diff changeset
844 -- For non-local variables, we preserve the current setting, i.e. a
kono
parents:
diff changeset
845 -- validity check is performed when assigning to a knonwn valid global.
kono
parents:
diff changeset
846
kono
parents:
diff changeset
847 -- Note: no validity checking is required if range checks are suppressed
kono
parents:
diff changeset
848 -- regardless of the setting of the validity checking mode.
kono
parents:
diff changeset
849
kono
parents:
diff changeset
850 -- The following procedures are used in handling validity checking
kono
parents:
diff changeset
851
kono
parents:
diff changeset
852 procedure Apply_Subscript_Validity_Checks (Expr : Node_Id);
kono
parents:
diff changeset
853 -- Expr is the node for an indexed component. If validity checking and
kono
parents:
diff changeset
854 -- range checking are enabled, all subscripts for this indexed component
kono
parents:
diff changeset
855 -- are checked for validity.
kono
parents:
diff changeset
856
kono
parents:
diff changeset
857 procedure Check_Valid_Lvalue_Subscripts (Expr : Node_Id);
kono
parents:
diff changeset
858 -- Expr is a lvalue, i.e. an expression representing the target of an
kono
parents:
diff changeset
859 -- assignment. This procedure checks for this expression involving an
kono
parents:
diff changeset
860 -- assignment to an array value. We have to be sure that all the subscripts
kono
parents:
diff changeset
861 -- in such a case are valid, since according to the rules in (RM
kono
parents:
diff changeset
862 -- 13.9.1(9-11)) such assignments are not permitted to result in erroneous
kono
parents:
diff changeset
863 -- behavior in the case of invalid subscript values.
kono
parents:
diff changeset
864
kono
parents:
diff changeset
865 procedure Ensure_Valid
kono
parents:
diff changeset
866 (Expr : Node_Id;
kono
parents:
diff changeset
867 Holes_OK : Boolean := False;
kono
parents:
diff changeset
868 Related_Id : Entity_Id := Empty;
kono
parents:
diff changeset
869 Is_Low_Bound : Boolean := False;
kono
parents:
diff changeset
870 Is_High_Bound : Boolean := False);
kono
parents:
diff changeset
871 -- Ensure that Expr represents a valid value of its type. If this type
kono
parents:
diff changeset
872 -- is not a scalar type, then the call has no effect, since validity
kono
parents:
diff changeset
873 -- is only an issue for scalar types. The effect of this call is to
kono
parents:
diff changeset
874 -- check if the value is known valid, if so, nothing needs to be done.
kono
parents:
diff changeset
875 -- If this is not known, then either Expr is set to be range checked,
kono
parents:
diff changeset
876 -- or specific checking code is inserted so that an exception is raised
kono
parents:
diff changeset
877 -- if the value is not valid.
kono
parents:
diff changeset
878 --
kono
parents:
diff changeset
879 -- The optional argument Holes_OK indicates whether it is necessary to
kono
parents:
diff changeset
880 -- worry about enumeration types with non-standard representations leading
kono
parents:
diff changeset
881 -- to "holes" in the range of possible representations. If Holes_OK is
kono
parents:
diff changeset
882 -- True, then such values are assumed valid (this is used when the caller
kono
parents:
diff changeset
883 -- will make a separate check for this case anyway). If Holes_OK is False,
kono
parents:
diff changeset
884 -- then this case is checked, and code is inserted to ensure that Expr is
kono
parents:
diff changeset
885 -- valid, raising Constraint_Error if the value is not valid.
kono
parents:
diff changeset
886 --
kono
parents:
diff changeset
887 -- Related_Id denotes the entity of the context where Expr appears. Flags
kono
parents:
diff changeset
888 -- Is_Low_Bound and Is_High_Bound specify whether the expression to check
kono
parents:
diff changeset
889 -- is the low or the high bound of a range. These three optional arguments
kono
parents:
diff changeset
890 -- signal Remove_Side_Effects to create an external symbol of the form
kono
parents:
diff changeset
891 -- Chars (Related_Id)_FIRST/_LAST. For suggested use of these parameters
kono
parents:
diff changeset
892 -- see the warning in the body of Sem_Ch3.Process_Range_Expr_In_Decl.
kono
parents:
diff changeset
893
kono
parents:
diff changeset
894 function Expr_Known_Valid (Expr : Node_Id) return Boolean;
kono
parents:
diff changeset
895 -- This function tests it the value of Expr is known to be valid in the
kono
parents:
diff changeset
896 -- sense of RM 13.9.1(9-11). In the case of GNAT, it is only discrete types
kono
parents:
diff changeset
897 -- which are a concern, since for non-discrete types we simply continue
kono
parents:
diff changeset
898 -- computation with invalid values, which does not lead to erroneous
kono
parents:
diff changeset
899 -- behavior. Thus Expr_Known_Valid always returns True if the type of Expr
kono
parents:
diff changeset
900 -- is non-discrete. For discrete types the value returned is True only if
kono
parents:
diff changeset
901 -- it can be determined that the value is Valid. Otherwise False is
kono
parents:
diff changeset
902 -- returned.
kono
parents:
diff changeset
903
kono
parents:
diff changeset
904 procedure Insert_Valid_Check
kono
parents:
diff changeset
905 (Expr : Node_Id;
kono
parents:
diff changeset
906 Related_Id : Entity_Id := Empty;
kono
parents:
diff changeset
907 Is_Low_Bound : Boolean := False;
kono
parents:
diff changeset
908 Is_High_Bound : Boolean := False);
kono
parents:
diff changeset
909 -- Inserts code that will check for the value of Expr being valid, in the
kono
parents:
diff changeset
910 -- sense of the 'Valid attribute returning True. Constraint_Error will be
kono
parents:
diff changeset
911 -- raised if the value is not valid.
kono
parents:
diff changeset
912 --
kono
parents:
diff changeset
913 -- Related_Id denotes the entity of the context where Expr appears. Flags
kono
parents:
diff changeset
914 -- Is_Low_Bound and Is_High_Bound specify whether the expression to check
kono
parents:
diff changeset
915 -- is the low or the high bound of a range. These three optional arguments
kono
parents:
diff changeset
916 -- signal Remove_Side_Effects to create an external symbol of the form
kono
parents:
diff changeset
917 -- Chars (Related_Id)_FIRST/_LAST. For suggested use of these parameters
kono
parents:
diff changeset
918 -- see the warning in the body of Sem_Ch3.Process_Range_Expr_In_Decl.
kono
parents:
diff changeset
919
kono
parents:
diff changeset
920 procedure Null_Exclusion_Static_Checks
kono
parents:
diff changeset
921 (N : Node_Id;
kono
parents:
diff changeset
922 Comp : Node_Id := Empty;
kono
parents:
diff changeset
923 Array_Comp : Boolean := False);
kono
parents:
diff changeset
924 -- Ada 2005 (AI-231): Test for and warn on null-excluding objects or
kono
parents:
diff changeset
925 -- components that will raise an exception due to initialization by null.
kono
parents:
diff changeset
926 --
kono
parents:
diff changeset
927 -- When a value for Comp is supplied (as in the case of an uninitialized
kono
parents:
diff changeset
928 -- null-excluding component within a composite object), a reported warning
kono
parents:
diff changeset
929 -- will indicate the offending component instead of the object itself.
kono
parents:
diff changeset
930 -- Array_Comp being True indicates an array object with null-excluding
kono
parents:
diff changeset
931 -- components, and any reported warning will indicate that.
kono
parents:
diff changeset
932
kono
parents:
diff changeset
933 procedure Remove_Checks (Expr : Node_Id);
kono
parents:
diff changeset
934 -- Remove all checks from Expr except those that are only executed
kono
parents:
diff changeset
935 -- conditionally (on the right side of And Then/Or Else. This call
kono
parents:
diff changeset
936 -- removes only embedded checks (Do_Range_Check, Do_Overflow_Check).
kono
parents:
diff changeset
937
kono
parents:
diff changeset
938 procedure Validity_Check_Range
kono
parents:
diff changeset
939 (N : Node_Id;
kono
parents:
diff changeset
940 Related_Id : Entity_Id := Empty);
kono
parents:
diff changeset
941 -- If N is an N_Range node, then Ensure_Valid is called on its bounds, if
kono
parents:
diff changeset
942 -- validity checking of operands is enabled. Related_Id denotes the entity
kono
parents:
diff changeset
943 -- of the context where N appears.
kono
parents:
diff changeset
944
kono
parents:
diff changeset
945 -----------------------------
kono
parents:
diff changeset
946 -- Handling of Check Names --
kono
parents:
diff changeset
947 -----------------------------
kono
parents:
diff changeset
948
kono
parents:
diff changeset
949 -- The following table contains Name_Id's for recognized checks. The first
kono
parents:
diff changeset
950 -- entries (corresponding to the values of the subtype Predefined_Check_Id)
kono
parents:
diff changeset
951 -- contain the Name_Id values for the checks that are predefined, including
kono
parents:
diff changeset
952 -- All_Checks (see Types). Remaining entries are those that are introduced
kono
parents:
diff changeset
953 -- by pragma Check_Names.
kono
parents:
diff changeset
954
kono
parents:
diff changeset
955 package Check_Names is new Table.Table (
kono
parents:
diff changeset
956 Table_Component_Type => Name_Id,
kono
parents:
diff changeset
957 Table_Index_Type => Check_Id,
kono
parents:
diff changeset
958 Table_Low_Bound => 1,
kono
parents:
diff changeset
959 Table_Initial => 30,
kono
parents:
diff changeset
960 Table_Increment => 200,
kono
parents:
diff changeset
961 Table_Name => "Name_Check_Names");
kono
parents:
diff changeset
962
kono
parents:
diff changeset
963 function Get_Check_Id (N : Name_Id) return Check_Id;
kono
parents:
diff changeset
964 -- Function to search above table for matching name. If found returns the
kono
parents:
diff changeset
965 -- corresponding Check_Id value in the range 1 .. Check_Name.Last. If not
kono
parents:
diff changeset
966 -- found returns No_Check_Id.
kono
parents:
diff changeset
967
kono
parents:
diff changeset
968 private
kono
parents:
diff changeset
969
kono
parents:
diff changeset
970 type Check_Result is array (Positive range 1 .. 2) of Node_Id;
kono
parents:
diff changeset
971 -- There are two cases for the result returned by Range_Check:
kono
parents:
diff changeset
972 --
kono
parents:
diff changeset
973 -- For the static case the result is one or two nodes that should cause
kono
parents:
diff changeset
974 -- a Constraint_Error. Typically these will include Expr itself or the
kono
parents:
diff changeset
975 -- direct descendants of Expr, such as Low/High_Bound (Expr)). It is the
kono
parents:
diff changeset
976 -- responsibility of the caller to rewrite and substitute the nodes with
kono
parents:
diff changeset
977 -- N_Raise_Constraint_Error nodes.
kono
parents:
diff changeset
978 --
kono
parents:
diff changeset
979 -- For the non-static case a single N_Raise_Constraint_Error node with a
kono
parents:
diff changeset
980 -- non-empty Condition field is returned.
kono
parents:
diff changeset
981 --
kono
parents:
diff changeset
982 -- Unused entries in Check_Result, if any, are simply set to Empty For
kono
parents:
diff changeset
983 -- external clients, the required processing on this result is achieved
kono
parents:
diff changeset
984 -- using the Insert_Range_Checks routine.
kono
parents:
diff changeset
985
kono
parents:
diff changeset
986 pragma Inline (Apply_Length_Check);
kono
parents:
diff changeset
987 pragma Inline (Apply_Range_Check);
kono
parents:
diff changeset
988 pragma Inline (Apply_Static_Length_Check);
kono
parents:
diff changeset
989 end Checks;