[Ada] Internal error on inlined renaming of subprogram instance
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 9 Oct 2018 15:06:11 +0000 (15:06 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Tue, 9 Oct 2018 15:06:11 +0000 (15:06 +0000)
This fixes a recent regression introduced in the compiler for the
inlined renaming of a subprogram instantiated in a package body.  It was
wrongly clearing the Is_Public flag on the entity associated with the
body.

2018-10-09  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

* sem_ch7.adb (Has_Referencer): Add comment for the
N_Freeze_Entity case.  Do not rely on
Has_Referencer_Of_Non_Subprograms to clear the Is_Public flag on
subprogram entities.

gcc/testsuite/

* gnat.dg/inline14.adb, gnat.dg/inline14_pkg.adb,
gnat.dg/inline14_pkg.ads: New testcase.

From-SVN: r264975

gcc/ada/ChangeLog
gcc/ada/sem_ch7.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/inline14.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/inline14_pkg.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/inline14_pkg.ads [new file with mode: 0644]

index 04b506e92a99f70d988538d1c87f5f4601bf4481..2c0bce6a54c1165ec64173003c42c9c5a11a1530 100644 (file)
@@ -1,3 +1,10 @@
+2018-10-09  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * sem_ch7.adb (Has_Referencer): Add comment for the
+       N_Freeze_Entity case.  Do not rely on
+       Has_Referencer_Of_Non_Subprograms to clear the Is_Public flag on
+       subprogram entities.
+
 2018-10-09  Ed Schonberg  <schonberg@adacore.com>
 
        * exp_unst.adb (In_Synchronized_Call): Handle properly private
index 8aebb0f1b68c929b9786b105c488a0431e8c3f35..6e9f531573356a4625fed595c6e6ccadc9becdce 100644 (file)
@@ -441,7 +441,13 @@ package body Sem_Ch7 is
                      Discard : Boolean;
                      pragma Unreferenced (Discard);
                   begin
-                     --  Inspect the actions to find references to subprograms
+                     --  Inspect the actions to find references to subprograms.
+                     --  We assume that the actions do not contain other kinds
+                     --  of references and, therefore, we do not stop the scan
+                     --  or set Has_Referencer_Of_Non_Subprograms here. Doing
+                     --  it would pessimize common cases for which the actions
+                     --  contain the declaration of an init procedure, since
+                     --  such a procedure is automatically marked inline.
 
                      Discard :=
                        Has_Referencer (Actions (Decl),
@@ -470,7 +476,8 @@ package body Sem_Ch7 is
                     and then not Is_Exported (Decl_Id)
                     and then No (Interface_Name (Decl_Id))
                     and then
-                      (not Has_Referencer_Of_Non_Subprograms
+                      ((Nkind (Decl) /= N_Subprogram_Declaration
+                         and then not Has_Referencer_Of_Non_Subprograms)
                         or else (Nkind (Decl) = N_Subprogram_Declaration
                                   and then not Subprogram_Table.Get (Decl_Id)))
                   then
index 8f84ace89c0bf5e8bd3370ee24076b83249d8d49..87368c7301da7c1ecd1102911b871e09374718de 100644 (file)
@@ -1,3 +1,8 @@
+2018-10-09  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/inline14.adb, gnat.dg/inline14_pkg.adb,
+       gnat.dg/inline14_pkg.ads: New testcase.
+
 2018-10-09  Ed Schonberg  <schonberg@adacore.com>
 
        * gnat.dg/warn18.adb: New testcase.
diff --git a/gcc/testsuite/gnat.dg/inline14.adb b/gcc/testsuite/gnat.dg/inline14.adb
new file mode 100644 (file)
index 0000000..5bf9aa6
--- /dev/null
@@ -0,0 +1,9 @@
+--  { dg-do compile }
+--  { dg-options "-O -gnatn" }
+
+with Inline14_Pkg; use Inline14_Pkg;
+
+procedure Inline14 is
+begin
+  Proc;
+end;
diff --git a/gcc/testsuite/gnat.dg/inline14_pkg.adb b/gcc/testsuite/gnat.dg/inline14_pkg.adb
new file mode 100644 (file)
index 0000000..0b71928
--- /dev/null
@@ -0,0 +1,16 @@
+package body Inline14_Pkg is
+
+  I : Integer;
+
+  generic procedure Inner;
+
+  procedure Inner is
+  begin
+    I := 0;
+  end;
+
+  procedure My_Inner is new Inner;
+
+  procedure Proc renames My_Inner;
+
+end Inline14_Pkg;
diff --git a/gcc/testsuite/gnat.dg/inline14_pkg.ads b/gcc/testsuite/gnat.dg/inline14_pkg.ads
new file mode 100644 (file)
index 0000000..d9c6dff
--- /dev/null
@@ -0,0 +1,6 @@
+package Inline14_Pkg is
+
+  procedure Proc;
+  pragma Inline (Proc);
+
+end Inline14_Pkg;