[Ada] Infinite loop with concatenation and aspect
authorBob Duff <duff@adacore.com>
Thu, 19 Sep 2019 08:12:56 +0000 (08:12 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Thu, 19 Sep 2019 08:12:56 +0000 (08:12 +0000)
This patch fixes a bug where an array object initialized with a
concatenation, and that has an aspect_specification for Alignment,
causes the compiler goes into an infinite loop.

2019-09-19  Bob Duff  <duff@adacore.com>

gcc/ada/

* exp_ch3.adb (Rewrite_As_Renaming): Return False if there are
any aspect specifications, because otherwise Insert_Actions
blows up.

gcc/testsuite/

* gnat.dg/concat3.adb: New testcase.

From-SVN: r275934

gcc/ada/ChangeLog
gcc/ada/exp_ch3.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/concat3.adb [new file with mode: 0644]

index 78b1c0b7db5de02727412dd2bf43076ad73ae20f..7d867bfd5eabf00db17a6befd7563a66b2d74935 100644 (file)
@@ -1,3 +1,9 @@
+2019-09-19  Bob Duff  <duff@adacore.com>
+
+       * exp_ch3.adb (Rewrite_As_Renaming): Return False if there are
+       any aspect specifications, because otherwise Insert_Actions
+       blows up.
+
 2019-09-19  Eric Botcazou  <ebotcazou@adacore.com>
 
        * exp_ch6.adb (Add_Simple_Call_By_Copy_Code): Add
index b08f51c31da2ff7eb5817e66404c4d1e47829feb..18c6aafe294087a13a413bed0cde05e0b2cef2a5 100644 (file)
@@ -6318,7 +6318,8 @@ package body Exp_Ch3 is
       -------------------------
 
       function Rewrite_As_Renaming return Boolean is
-      begin
+         Result : constant Boolean :=
+
          --  If the object declaration appears in the form
 
          --    Obj : Ctrl_Typ := Func (...);
@@ -6336,12 +6337,12 @@ package body Exp_Ch3 is
 
          --  This part is disabled for now, because it breaks GPS builds
 
-         return (False -- ???
-             and then Nkind (Expr_Q) = N_Explicit_Dereference
-             and then not Comes_From_Source (Expr_Q)
-             and then Nkind (Original_Node (Expr_Q)) = N_Function_Call
-             and then Nkind (Object_Definition (N)) in N_Has_Entity
-             and then (Needs_Finalization (Entity (Object_Definition (N)))))
+         (False -- ???
+            and then Nkind (Expr_Q) = N_Explicit_Dereference
+            and then not Comes_From_Source (Expr_Q)
+            and then Nkind (Original_Node (Expr_Q)) = N_Function_Call
+            and then Nkind (Object_Definition (N)) in N_Has_Entity
+            and then (Needs_Finalization (Entity (Object_Definition (N)))))
 
            --  If the initializing expression is for a variable with attribute
            --  OK_To_Rename set, then transform:
@@ -6362,6 +6363,14 @@ package body Exp_Ch3 is
                and then Ekind (Entity (Expr_Q)) = E_Variable
                and then OK_To_Rename (Entity (Expr_Q))
                and then Is_Entity_Name (Obj_Def));
+      begin
+         --  Return False if there are any aspect specifications, because
+         --  otherwise we duplicate that corresponding implicit attribute
+         --  definition, and call Insert_Action, which has no place to insert
+         --  the attribute definition. The attribute definition is stored in
+         --  Aspect_Rep_Item, which is not a list.
+
+         return Result and then No (Aspect_Specifications (N));
       end Rewrite_As_Renaming;
 
       --  Local variables
index 1e0262892490d50baa99ae00247598ca7d643ab7..3755221c56bcae2ee940579b3011614370ab10e6 100644 (file)
@@ -1,3 +1,7 @@
+2019-09-19  Bob Duff  <duff@adacore.com>
+
+       * gnat.dg/concat3.adb: New testcase.
+
 2019-09-19  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/pack26.adb: New testcase.
diff --git a/gcc/testsuite/gnat.dg/concat3.adb b/gcc/testsuite/gnat.dg/concat3.adb
new file mode 100644 (file)
index 0000000..b4df3fd
--- /dev/null
@@ -0,0 +1,14 @@
+--  { dg-do run }
+--  { dg-options "-g -O0 -gnata" }
+
+procedure Concat3 is
+   procedure Show_Bug (S : in String)
+   is
+      Str : constant String := S & "-" with Alignment => 4;
+   begin
+      null;
+   end Show_Bug;
+
+begin
+   Show_Bug ("BUG");
+end Concat3;
\ No newline at end of file