+2018-05-25 Ed Schonberg <schonberg@adacore.com>
+
+ * exp_unst.adb (Visit_Node): Restrict check for uplevel references in
+ prefixes of array attributes, to prefixes that are entity names whose
+ type is constrained.
+ (Note_Uplevel_Bound): Verify that the bound is declared in an enclosing
+ subprogram, as itype created for loops in pre/postcondition may appear
+ in loops at the library level.
+
2018-05-25 Ed Schonberg <schonberg@adacore.com>
* sem_ch13.adb (Build_Predicate_Functions): The predicate function
procedure Note_Uplevel_Bound (N : Node_Id) is
begin
-- Entity name case
+ -- Make sure that that the entity is declared in a
+ -- subprogram. THis may not be the case for an type
+ -- in a loop appearing in a precondition.
if Is_Entity_Name (N) then
- if Present (Entity (N)) then
+ if Present (Entity (N))
+ and then Present (Enclosing_Subprogram (Entity (N)))
+ then
Note_Uplevel_Ref
(E => Entity (N),
Caller => Current_Subprogram,
| Attribute_Last
| Attribute_Length
=>
- declare
- DT : Boolean := False;
- begin
- Check_Static_Type (Etype (Prefix (N)), DT);
- end;
+ -- Special-case attributes of array objects
+ -- whose bounds may be uplevel references.
+ -- More complex prefixes are handled during
+ -- full traversal. Note that if the nominal
+ -- subtype of the prefix is unconstrained, the
+ -- bound must be obtained from the object, not
+ -- from the (possibly) uplevel reference,
+
+ if Is_Entity_Name (Prefix (N))
+ and then Is_Constrained (Etype (Prefix (N)))
+ then
+ declare
+ DT : Boolean := False;
+ begin
+ Check_Static_Type (Etype (Prefix (N)), DT);
+ end;
+
+ return OK;
+ end if;
when others =>
null;