From dba246bfabc54c9a97304f4ab65fda62bd2936c8 Mon Sep 17 00:00:00 2001 From: Bob Duff Date: Wed, 14 Aug 2019 09:52:24 +0000 Subject: [Ada] Incorrect error on inline protected function This patch fixes a bug where if a protected function has a pragma Inline, and has no local variables, and the body consists of a single extended_return_statement, and the result type is an indefinite composite subtype, and inlining is enabled, the compiler gives an error, even though the program is legal. 2019-08-14 Bob Duff gcc/ada/ * inline.adb (Check_And_Split_Unconstrained_Function): Ignore protected functions to get rid of spurious error. The transformation done by this procedure triggers legality errors in the generated code in this case. gcc/testsuite/ * gnat.dg/inline19.adb, gnat.dg/inline19.ads: New testcase. From-SVN: r274467 --- gcc/ada/ChangeLog | 7 +++++++ gcc/ada/inline.adb | 14 ++++++++++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/inline19.adb | 17 +++++++++++++++++ gcc/testsuite/gnat.dg/inline19.ads | 8 ++++++++ 5 files changed, 50 insertions(+) create mode 100644 gcc/testsuite/gnat.dg/inline19.adb create mode 100644 gcc/testsuite/gnat.dg/inline19.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 4e7daba..4063f93 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,5 +1,12 @@ 2019-08-14 Bob Duff + * inline.adb (Check_And_Split_Unconstrained_Function): Ignore + protected functions to get rid of spurious error. The + transformation done by this procedure triggers legality errors + in the generated code in this case. + +2019-08-14 Bob Duff + * sem_prag.adb (Process_Compile_Time_Warning_Or_Error): Defer processing to the back end in all cases where the pragma's condition is not known at compile time during the front end diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb index 05830e1..5dbd9a1 100644 --- a/gcc/ada/inline.adb +++ b/gcc/ada/inline.adb @@ -2041,6 +2041,8 @@ package body Inline is Original_Body : Node_Id; Body_To_Analyze : Node_Id; + -- Start of processing for Build_Body_To_Inline + begin pragma Assert (Current_Scope = Spec_Id); @@ -2448,6 +2450,18 @@ package body Inline is elsif Present (Body_To_Inline (Decl)) then return; + -- Do not generate a body to inline for protected functions, because the + -- transformation generates a call to a protected procedure, causing + -- spurious errors. We don't inline protected operations anyway, so + -- this is no loss. We might as well ignore intrinsics and foreign + -- conventions as well -- just allow Ada conventions. + + elsif not (Convention (Spec_Id) = Convention_Ada + or else Convention (Spec_Id) = Convention_Ada_Pass_By_Copy + or else Convention (Spec_Id) = Convention_Ada_Pass_By_Reference) + then + return; + -- Check excluded declarations elsif Present (Declarations (N)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cff4e5e..8575052 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-08-14 Bob Duff + + * gnat.dg/inline19.adb, gnat.dg/inline19.ads: New testcase. + 2019-08-14 Gary Dismukes * gnat.dg/equal11.adb, gnat.dg/equal11_interface.ads, diff --git a/gcc/testsuite/gnat.dg/inline19.adb b/gcc/testsuite/gnat.dg/inline19.adb new file mode 100644 index 0000000..01be738 --- /dev/null +++ b/gcc/testsuite/gnat.dg/inline19.adb @@ -0,0 +1,17 @@ +-- { dg-do compile } +-- { dg-options "-O2" } + +package body Inline19 is + + S : String := "Hello"; + + protected body P is + function F return String is + begin + return Result : constant String := S do + null; + end return; + end F; + end P; + +end Inline19; diff --git a/gcc/testsuite/gnat.dg/inline19.ads b/gcc/testsuite/gnat.dg/inline19.ads new file mode 100644 index 0000000..7a2d35c --- /dev/null +++ b/gcc/testsuite/gnat.dg/inline19.ads @@ -0,0 +1,8 @@ +package Inline19 is + + protected P is + function F return String; + pragma Inline (F); + end P; + +end Inline19; -- cgit v1.1