aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJavier Miranda <miranda@adacore.com>2025-01-10 19:08:39 +0000
committerMarc Poulhiès <dkm@gcc.gnu.org>2025-01-13 11:52:59 +0100
commit5fd925bf732c889d020f2a575591648f990adb4f (patch)
tree4c2062b426a0fb90ab13722d0c3eccd7df73d4e2 /gcc
parent686bd4e0bc484f9612038d51d07708ff8a4ff75b (diff)
downloadgcc-5fd925bf732c889d020f2a575591648f990adb4f.zip
gcc-5fd925bf732c889d020f2a575591648f990adb4f.tar.gz
gcc-5fd925bf732c889d020f2a575591648f990adb4f.tar.bz2
ada: Cleanup preanalysis of static expressions (part 4)
Fix regression in the SPARK 2014 testsuite. gcc/ada/ChangeLog: * sem_util.adb (Build_Actual_Subtype_Of_Component): No action under preanalysis. * sem_ch5.adb (Set_Assignment_Type): If the right-hand side contains target names, expansion has been disabled to prevent expansion that might move target names out of the context of the assignment statement. Restore temporarily the current compilation mode so that the actual subtype can be built.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/sem_ch5.adb25
-rw-r--r--gcc/ada/sem_util.adb5
2 files changed, 23 insertions, 7 deletions
diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index 432debf..12d6426 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -121,6 +121,9 @@ package body Sem_Ch5 is
Lhs : constant Node_Id := Name (N);
Rhs : constant Node_Id := Expression (N);
+ Save_Full_Analysis : Boolean := False;
+ -- Force initialization to facilitate static analysis
+
procedure Diagnose_Non_Variable_Lhs (N : Node_Id);
-- N is the node for the left hand side of an assignment, and it is not
-- a variable. This routine issues an appropriate diagnostic.
@@ -318,7 +321,24 @@ package body Sem_Ch5 is
and then No (Actual_Designated_Subtype (Opnd))))
and then not Is_Unchecked_Union (Opnd_Type)
then
- Decl := Build_Actual_Subtype_Of_Component (Opnd_Type, Opnd);
+ -- If the right-hand side contains target names, expansion has
+ -- been disabled to prevent expansion that might move target
+ -- names out of the context of the assignment statement. Restore
+ -- temporarily the current compilation mode so that the actual
+ -- subtype can be built.
+
+ if Nkind (N) = N_Assignment_Statement
+ and then Has_Target_Names (N)
+ and then Present (Current_Assignment)
+ then
+ Expander_Mode_Restore;
+ Full_Analysis := Save_Full_Analysis;
+ Decl := Build_Actual_Subtype_Of_Component (Opnd_Type, Opnd);
+ Expander_Mode_Save_And_Set (False);
+ Full_Analysis := False;
+ else
+ Decl := Build_Actual_Subtype_Of_Component (Opnd_Type, Opnd);
+ end if;
if Present (Decl) then
Insert_Action (N, Decl);
@@ -366,9 +386,6 @@ package body Sem_Ch5 is
T1 : Entity_Id;
T2 : Entity_Id;
- Save_Full_Analysis : Boolean := False;
- -- Force initialization to facilitate static analysis
-
-- Start of processing for Analyze_Assignment
begin
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 058c868..0e1505b 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -1467,10 +1467,9 @@ package body Sem_Util is
-- Start of processing for Build_Actual_Subtype_Of_Component
begin
- -- The subtype does not need to be created for a selected component
- -- in a Spec_Expression.
+ -- The subtype does not need to be created during preanalysis
- if In_Spec_Expression then
+ if Preanalysis_Active then
return Empty;
-- More comments for the rest of this body would be good ???