[Ada] Fix bogus compilation error with Elaborate_Body and -gnatN
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 19 Aug 2019 08:37:28 +0000 (08:37 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Mon, 19 Aug 2019 08:37:28 +0000 (08:37 +0000)
This fixes a bogus compilation error when a unit with SPARK_Mode
containing a pragma Elaborate_Body is with-ed by a generic unit
containing an inlined subprogram, and front-end inlining is enabled.

2019-08-19  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

* sem_prag.adb (Is_Before_First_Decl): Deal with rewritten
pragmas.

gcc/testsuite/

* gnat.dg/elab8.adb, gnat.dg/elab8_gen.adb,
gnat.dg/elab8_gen.ads, gnat.dg/elab8_pkg.adb,
gnat.dg/elab8_pkg.ads: New testcase.

From-SVN: r274664

gcc/ada/ChangeLog
gcc/ada/sem_prag.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/elab8.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/elab8_gen.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/elab8_gen.ads [new file with mode: 0644]
gcc/testsuite/gnat.dg/elab8_pkg.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/elab8_pkg.ads [new file with mode: 0644]

index 84c2239d209d5d758b613cb1bd1689c266c15e71..f01e411b037bf19725f8fa0b0a5755362e9f4037 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-19  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * sem_prag.adb (Is_Before_First_Decl): Deal with rewritten
+       pragmas.
+
 2019-08-19  Bob Duff  <duff@adacore.com>
 
        * sem_warn.adb (Warn_On_Unreferenced_Entity): Suppress warning
index 035b0eee1f41daeeca80e6239c9c7d2aee80ca34..993a419df090e6a3f4691334b6011b9642e84ed6 100644 (file)
@@ -7146,10 +7146,11 @@ package body Sem_Prag is
          Item : Node_Id := First (Decls);
 
       begin
-         --  Only other pragmas can come before this pragma
+         --  Only other pragmas can come before this pragma, but they might
+         --  have been rewritten so check the original node.
 
          loop
-            if No (Item) or else Nkind (Item) /= N_Pragma then
+            if No (Item) or else Nkind (Original_Node (Item)) /= N_Pragma then
                return False;
 
             elsif Item = Pragma_Node then
index 5bafa9d636f65738a15e2023de7f8079fc2402ca..f20c466ffadebe0a0505baaa5741655df2f0ec96 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-19  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/elab8.adb, gnat.dg/elab8_gen.adb,
+       gnat.dg/elab8_gen.ads, gnat.dg/elab8_pkg.adb,
+       gnat.dg/elab8_pkg.ads: New testcase.
+
 2019-08-19  Bob Duff  <duff@adacore.com>
 
        * gnat.dg/warn29.adb, gnat.dg/warn29.ads: New testcase.
diff --git a/gcc/testsuite/gnat.dg/elab8.adb b/gcc/testsuite/gnat.dg/elab8.adb
new file mode 100644 (file)
index 0000000..a54ba9d
--- /dev/null
@@ -0,0 +1,12 @@
+--  { dg-do compile }
+--  { dg-options "-gnatN" }
+
+with Elab8_Gen;
+
+procedure Elab8 is
+
+  package My_G is new Elab8_Gen  (Integer);
+
+begin
+  My_G.Compare (0, 1);
+end;
diff --git a/gcc/testsuite/gnat.dg/elab8_gen.adb b/gcc/testsuite/gnat.dg/elab8_gen.adb
new file mode 100644 (file)
index 0000000..fbb09b9
--- /dev/null
@@ -0,0 +1,12 @@
+with Elab8_Pkg;
+
+package body Elab8_Gen is
+
+  procedure Compare (Arg1, Arg2 : T) is
+  begin
+    if Arg1 = Arg2 then
+      raise Program_Error;
+    end if;
+  end;
+
+end Elab8_Gen;
diff --git a/gcc/testsuite/gnat.dg/elab8_gen.ads b/gcc/testsuite/gnat.dg/elab8_gen.ads
new file mode 100644 (file)
index 0000000..8125407
--- /dev/null
@@ -0,0 +1,8 @@
+generic
+  type T is private;
+package Elab8_Gen is
+
+  procedure Compare (Arg1, Arg2 : T);
+  pragma Inline (Compare);
+
+end Elab8_Gen;
diff --git a/gcc/testsuite/gnat.dg/elab8_pkg.adb b/gcc/testsuite/gnat.dg/elab8_pkg.adb
new file mode 100644 (file)
index 0000000..451d4e4
--- /dev/null
@@ -0,0 +1,5 @@
+package body Elab8_Pkg is
+
+  procedure Dummy is null;
+
+end Elab8_Pkg;
diff --git a/gcc/testsuite/gnat.dg/elab8_pkg.ads b/gcc/testsuite/gnat.dg/elab8_pkg.ads
new file mode 100644 (file)
index 0000000..8bf4603
--- /dev/null
@@ -0,0 +1,5 @@
+package Elab8_Pkg with SPARK_Mode is
+
+  pragma Elaborate_Body;
+
+end Elab8_Pkg;