Commit 5fe0b8c3 by Ed Schonberg Committed by Pierre-Marie de Rodat

[Ada] Refine checks for uplevel references

2018-05-25  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* 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.

From-SVN: r260717
parent 8218cfde
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
declaration is inserted into the tree and analyzed at that point, so
should not be reinserted when the body is constructed. Inside a
......
......@@ -401,9 +401,14 @@ package body Exp_Unst is
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,
......@@ -616,11 +621,25 @@ package body Exp_Unst is
| 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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment