aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2020-04-01 11:43:39 +0200
committerPierre-Marie de Rodat <derodat@adacore.com>2020-06-15 04:04:36 -0400
commit63e96d44215b7b86eb2eb754dcf139437e40d850 (patch)
treee71f2ef95b68d36acfbff6f2f3e8e7791c59e89a
parenta7837c085aa5538430cdc9ffc04fcfa1f581656f (diff)
downloadgcc-63e96d44215b7b86eb2eb754dcf139437e40d850.zip
gcc-63e96d44215b7b86eb2eb754dcf139437e40d850.tar.gz
gcc-63e96d44215b7b86eb2eb754dcf139437e40d850.tar.bz2
[Ada] Fix analysis of Relaxed_Initialization for bodies-as-specs
2020-06-15 Piotr Trojanek <trojanek@adacore.com> gcc/ada/ * sem_ch13.adb (Analyze_Aspect_Relaxed_Initialization): Fix dealing with scopes on subprogram bodies that act as specs. * sem_util.adb (Has_Relaxed_Initialization): Fix trivial mistake.
-rw-r--r--gcc/ada/sem_ch13.adb32
-rw-r--r--gcc/ada/sem_util.adb3
2 files changed, 24 insertions, 11 deletions
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 3bdc39a..19a0780 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -2203,6 +2203,10 @@ package body Sem_Ch13 is
-- Items that appear in the relaxed initialization aspect
-- expression of a subprogram; for detecting duplicates.
+ Restore_Scope : Boolean;
+ -- Will be set to True if we need to restore the scope table
+ -- after analyzing the aspect expression.
+
-- Start of processing for Analyze_Aspect_Relaxed_Initialization
begin
@@ -2231,17 +2235,23 @@ package body Sem_Ch13 is
elsif Is_Subprogram (E) then
if Present (Expr) then
- -- Subprogram and its formal parameters must be visible
- -- when analyzing the aspect expression.
-
- pragma Assert (not In_Open_Scopes (E));
+ -- If we analyze subprogram body that acts as its own
+ -- spec, then the subprogram itself and its formals are
+ -- already installed; otherwise, we need to install them,
+ -- as they must be visible when analyzing the aspect
+ -- expression.
- Push_Scope (E);
-
- if Is_Generic_Subprogram (E) then
- Install_Generic_Formals (E);
+ if In_Open_Scopes (E) then
+ Restore_Scope := False;
else
- Install_Formals (E);
+ Restore_Scope := True;
+ Push_Scope (E);
+
+ if Is_Generic_Subprogram (E) then
+ Install_Generic_Formals (E);
+ else
+ Install_Formals (E);
+ end if;
end if;
-- Aspect expression is either an aggregate with list of
@@ -2281,7 +2291,9 @@ package body Sem_Ch13 is
Analyze_Relaxed_Parameter (E, Expr, Seen);
end if;
- End_Scope;
+ if Restore_Scope then
+ End_Scope;
+ end if;
else
Error_Msg_N ("missing expression for aspect %", N);
end if;
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 31e03fd..a3dbaaf 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -12511,7 +12511,8 @@ package body Sem_Util is
if Has_Aspect (Subp_Id, Aspect_Relaxed_Initialization) then
Aspect_Expr :=
- Find_Value_Of_Aspect (E, Aspect_Relaxed_Initialization);
+ Find_Value_Of_Aspect
+ (Subp_Id, Aspect_Relaxed_Initialization);
-- Aspect expression is either an aggregate, e.g.:
--