From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 2870D3851ABB; Wed, 13 Jul 2022 10:03:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2870D3851ABB MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1666] [Ada] Handle bodies-to-inline just like generic templates X-Act-Checkin: gcc X-Git-Author: Piotr Trojanek X-Git-Refname: refs/heads/master X-Git-Oldrev: 4621bae835be11ae4ec81d5842166e819826459c X-Git-Newrev: a714ca803cbf2f9e26ca214d7ddd7ed65bac2c26 Message-Id: <20220713100337.2870D3851ABB@sourceware.org> Date: Wed, 13 Jul 2022 10:03:37 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jul 2022 10:03:37 -0000 https://gcc.gnu.org/g:a714ca803cbf2f9e26ca214d7ddd7ed65bac2c26 commit r13-1666-ga714ca803cbf2f9e26ca214d7ddd7ed65bac2c26 Author: Piotr Trojanek Date: Wed Jul 6 09:37:15 2022 +0200 [Ada] Handle bodies-to-inline just like generic templates Originally bodies-to-inline created for the frontend inlining were analyzed with expansion disabled. Then, to facilitate inlining in GNATprove mode, the analysis was changed to preanalysis. However, preanalysis in this context works badly for calls in prefix notation, because preanalysis assigns entities and types to nodes but doesn't convert calls from prefix to ordinary notation. When the body-to-inline is actually inlined, the (re)analysis of calls in prefix notation fails. The proper solution is rather to handle bodies-to-inline just like generic templates. From the user point of view, this patch fixes spurious errors both in GNATprove (which uses frontend inlining by default) and in GNAT (where frontend inlining is typically explicitly requested with -gnatN and pragma Inline_Always). gcc/ada/ * inline.adb (Build_Body_To_Inline): Instead of manipulating the Full_Analysis flag, use the Inside_A_Generic flag (which is conveniently manipulated by Start_Generic/End_Generic, together with Expander_Active). * sem_attr.adb (Analyze_Attribute_Old_Result): Adapt comment and assertion to different flag that is set while building body-to-inline. Diff: --- gcc/ada/inline.adb | 12 ++---------- gcc/ada/sem_attr.adb | 4 ++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb index e0ff67a0649..e32df68152b 100644 --- a/gcc/ada/inline.adb +++ b/gcc/ada/inline.adb @@ -32,7 +32,6 @@ with Einfo.Entities; use Einfo.Entities; with Einfo.Utils; use Einfo.Utils; with Elists; use Elists; with Errout; use Errout; -with Expander; use Expander; with Exp_Ch6; use Exp_Ch6; with Exp_Ch7; use Exp_Ch7; with Exp_Tss; use Exp_Tss; @@ -1107,7 +1106,6 @@ package body Inline is procedure Build_Body_To_Inline (N : Node_Id; Spec_Id : Entity_Id) is Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id); - Analysis_Status : constant Boolean := Full_Analysis; Original_Body : Node_Id; Body_To_Analyze : Node_Id; Max_Size : constant := 10; @@ -1419,12 +1417,7 @@ package body Inline is Append (Body_To_Analyze, Declarations (N)); end if; - -- The body to inline is preanalyzed. In GNATprove mode we must disable - -- full analysis as well so that light expansion does not take place - -- either, and name resolution is unaffected. - - Expander_Mode_Save_And_Set (False); - Full_Analysis := False; + Start_Generic; Analyze (Body_To_Analyze); Push_Scope (Defining_Entity (Body_To_Analyze)); @@ -1432,8 +1425,7 @@ package body Inline is End_Scope; Remove (Body_To_Analyze); - Expander_Mode_Restore; - Full_Analysis := Analysis_Status; + End_Generic; -- Restore environment if previously saved diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index adeda43bd87..93bb6f42b6b 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -1508,9 +1508,9 @@ package body Sem_Attr is and then Chars (Spec_Id) = Name_uParent and then Chars (Scope (Spec_Id)) = Name_uPostconditions then - -- This situation occurs only when preanalyzing the inlined body + -- This situation occurs only when analyzing the body-to-inline - pragma Assert (not Full_Analysis); + pragma Assert (Inside_A_Generic); Spec_Id := Scope (Spec_Id); pragma Assert (Is_Inlined (Spec_Id));