From 236f10422f47f0c98e42db420b98ab84e0ac548f Mon Sep 17 00:00:00 2001
From: Arnaud Charlet <charlet@gcc.gnu.org>
Date: Fri, 5 Oct 2012 16:33:42 +0200
Subject: [PATCH] [multiple changes]

2012-10-05  Robert Dewar  <dewar@adacore.com>

	* sem_ch7.adb: Minor reformatting.

2012-10-05  Ed Schonberg  <schonberg@adacore.com>

	* sem_prag.adb (Analyze_Pragma, case Persistent_BSS): check for
	a duplicate pragma before Rep_Item_Too_Late to prevent spurious
	messages about duplicate pragmas.

2012-10-05  Ed Schonberg  <schonberg@adacore.com>

	* exp_util.adb (Find_Init_Call): If the successor of the
	object declaration is a block, check whether it contains the
	initialization call, because it may have been created by actuals
	that use the secondary stack.

From-SVN: r192130
---
 gcc/ada/ChangeLog    | 17 +++++++++++++++++
 gcc/ada/exp_util.adb | 21 ++++++++++++++++++++-
 gcc/ada/sem_ch7.adb  |  4 +++-
 gcc/ada/sem_prag.adb |  7 +++++--
 4 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index ea4667f..1a9ff91 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,20 @@
+2012-10-05  Robert Dewar  <dewar@adacore.com>
+
+	* sem_ch7.adb: Minor reformatting.
+
+2012-10-05  Ed Schonberg  <schonberg@adacore.com>
+
+	* sem_prag.adb (Analyze_Pragma, case Persistent_BSS): check for
+	a duplicate pragma before Rep_Item_Too_Late to prevent spurious
+	messages about duplicate pragmas.
+
+2012-10-05  Ed Schonberg  <schonberg@adacore.com>
+
+	* exp_util.adb (Find_Init_Call): If the successor of the
+	object declaration is a block, check whether it contains the
+	initialization call, because it may have been created by actuals
+	that use the secondary stack.
+
 2012-10-05  Thomas Quinot  <quinot@adacore.com>
 
 	* sem_dim.adb, errout.adb, errout.ads (Analyze_Dimension_Call): Add
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 82b054a..cc3213d 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -2166,6 +2166,7 @@ package body Exp_Util is
      (Var        : Entity_Id;
       Rep_Clause : Node_Id) return Node_Id
    is
+      Par : constant Node_Id   := Parent (Var);
       Typ : constant Entity_Id := Etype (Var);
 
       Init_Proc : Entity_Id;
@@ -2204,6 +2205,7 @@ package body Exp_Util is
 
    begin
       if not Has_Non_Null_Base_Init_Proc (Typ) then
+
          --  No init proc for the type, so obviously no call to be found
 
          return Empty;
@@ -2213,7 +2215,7 @@ package body Exp_Util is
 
       --  First scan the list containing the declaration of Var
 
-      Init_Call := Find_Init_Call_In_List (From => Next (Parent (Var)));
+      Init_Call := Find_Init_Call_In_List (From => Next (Par));
 
       --  If not found, also look on Var's freeze actions list, if any, since
       --  the init call may have been moved there (case of an address clause
@@ -2224,6 +2226,23 @@ package body Exp_Util is
            Find_Init_Call_In_List (First (Actions (Freeze_Node (Var))));
       end if;
 
+      --  If the initialization call has actuals that use the secondary stack,
+      --  the call may have been wrapped into a temporary block, in which case
+      --  the block itself has to be removed.
+
+      if No (Init_Call) and then Nkind (Next (Par)) = N_Block_Statement then
+         declare
+            Blk : constant Node_Id := Next (Par);
+         begin
+            if Present
+                 (Find_Init_Call_In_List
+                   (First (Statements (Handled_Statement_Sequence (Blk)))))
+            then
+               Init_Call := Blk;
+            end if;
+         end;
+      end if;
+
       return Init_Call;
    end Find_Init_Call;
 
diff --git a/gcc/ada/sem_ch7.adb b/gcc/ada/sem_ch7.adb
index 103aa5b..a25e328 100644
--- a/gcc/ada/sem_ch7.adb
+++ b/gcc/ada/sem_ch7.adb
@@ -1390,11 +1390,13 @@ package body Sem_Ch7 is
          then
             declare
                ASN : Node_Id;
+
             begin
                ASN := First (Aspect_Specifications (Parent (E)));
                while Present (ASN) loop
                   if Chars (Identifier (ASN)) = Name_Invariant
-                    or else Chars (Identifier (ASN)) = Name_Type_Invariant
+                       or else
+                     Chars (Identifier (ASN)) = Name_Type_Invariant
                   then
                      Build_Invariant_Procedure (E, N);
                      exit;
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 1739673..2c9d518 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -12130,6 +12130,11 @@ package body Sem_Prag is
                Ent := Entity (Get_Pragma_Arg (Arg1));
                Decl := Parent (Ent);
 
+               --  Check for duplication before inserting in list of
+               --  representation items.
+
+               Check_Duplicate_Pragma (Ent);
+
                if Rep_Item_Too_Late (Ent, N) then
                   return;
                end if;
@@ -12145,8 +12150,6 @@ package body Sem_Prag is
                      Arg1);
                end if;
 
-               Check_Duplicate_Pragma (Ent);
-
                Prag :=
                  Make_Linker_Section_Pragma
                    (Ent, Sloc (N), ".persistent.bss");
--
libgit2 0.26.0