[Ada] Fix bogus compilation error with Elaborate_Body and -gnatN
diff mbox series

Message ID 20190819083903.GA33570@adacore.com
State New
Headers show
Series
  • [Ada] Fix bogus compilation error with Elaborate_Body and -gnatN
Related show

Commit Message

Pierre-Marie de Rodat Aug. 19, 2019, 8:39 a.m. UTC
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.

Tested on x86_64-pc-linux-gnu, committed on trunk

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.

Patch
diff mbox series

--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -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

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/elab8.adb
@@ -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;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/elab8_gen.adb
@@ -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;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/elab8_gen.ads
@@ -0,0 +1,8 @@ 
+generic
+  type T is private;
+package Elab8_Gen is
+
+  procedure Compare (Arg1, Arg2 : T);
+  pragma Inline (Compare);
+
+end Elab8_Gen;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/elab8_pkg.adb
@@ -0,0 +1,5 @@ 
+package body Elab8_Pkg is
+
+  procedure Dummy is null;
+
+end Elab8_Pkg;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/elab8_pkg.ads
@@ -0,0 +1,5 @@ 
+package Elab8_Pkg with SPARK_Mode is
+
+  pragma Elaborate_Body;
+
+end Elab8_Pkg;