From: Javier Miranda <mira...@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch5.adb  | 25 +++++++++++++++++++++----
 gcc/ada/sem_util.adb |  5 ++---
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index 432debf3e25..12d6426671e 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 058c868aa07..0e1505bbdbe 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 ???
-- 
2.43.0

Reply via email to