]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Cleanup preanalysis of static expressions (part 4)
authorJavier Miranda <miranda@adacore.com>
Fri, 10 Jan 2025 19:08:39 +0000 (19:08 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 13 Jan 2025 10:52:59 +0000 (11:52 +0100)
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.

gcc/ada/sem_ch5.adb
gcc/ada/sem_util.adb

index 432debf3e25e6401de0f961b989fc03bcfad6747..12d6426671e777135dfd8ed412d41b598034168d 100644 (file)
@@ -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
index 058c868aa07bf34c21ae8234e5ac4c81e8b7348c..0e1505bbdbe65fa60a6dc88382ea8887194ddd01 100644 (file)
@@ -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 ???