From 8fafa0b42000f5fa0284f8e3308f233a41843461 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Mon, 19 Aug 2019 08:37:28 +0000 Subject: [PATCH] [Ada] Fix bogus compilation error with Elaborate_Body and -gnatN 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 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 | 5 +++++ gcc/ada/sem_prag.adb | 5 +++-- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gnat.dg/elab8.adb | 12 ++++++++++++ gcc/testsuite/gnat.dg/elab8_gen.adb | 12 ++++++++++++ gcc/testsuite/gnat.dg/elab8_gen.ads | 8 ++++++++ gcc/testsuite/gnat.dg/elab8_pkg.adb | 5 +++++ gcc/testsuite/gnat.dg/elab8_pkg.ads | 5 +++++ 8 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/elab8.adb create mode 100644 gcc/testsuite/gnat.dg/elab8_gen.adb create mode 100644 gcc/testsuite/gnat.dg/elab8_gen.ads create mode 100644 gcc/testsuite/gnat.dg/elab8_pkg.adb create mode 100644 gcc/testsuite/gnat.dg/elab8_pkg.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 84c2239d209..f01e411b037 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2019-08-19 Eric Botcazou + + * sem_prag.adb (Is_Before_First_Decl): Deal with rewritten + pragmas. + 2019-08-19 Bob Duff * sem_warn.adb (Warn_On_Unreferenced_Entity): Suppress warning diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index 035b0eee1f4..993a419df09 100644 --- a/gcc/ada/sem_prag.adb +++ b/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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5bafa9d636f..f20c466ffad 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-08-19 Eric Botcazou + + * 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 * 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 index 00000000000..a54ba9d53f8 --- /dev/null +++ b/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; diff --git a/gcc/testsuite/gnat.dg/elab8_gen.adb b/gcc/testsuite/gnat.dg/elab8_gen.adb new file mode 100644 index 00000000000..fbb09b91f3c --- /dev/null +++ b/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; diff --git a/gcc/testsuite/gnat.dg/elab8_gen.ads b/gcc/testsuite/gnat.dg/elab8_gen.ads new file mode 100644 index 00000000000..8125407c45b --- /dev/null +++ b/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; diff --git a/gcc/testsuite/gnat.dg/elab8_pkg.adb b/gcc/testsuite/gnat.dg/elab8_pkg.adb new file mode 100644 index 00000000000..451d4e434c3 --- /dev/null +++ b/gcc/testsuite/gnat.dg/elab8_pkg.adb @@ -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 index 00000000000..8bf46036a36 --- /dev/null +++ b/gcc/testsuite/gnat.dg/elab8_pkg.ads @@ -0,0 +1,5 @@ +package Elab8_Pkg with SPARK_Mode is + + pragma Elaborate_Body; + +end Elab8_Pkg; -- 2.30.2