From patchwork Tue May 15 09:49:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 159281 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id C29D4B6FB4 for ; Tue, 15 May 2012 19:49:31 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1337680173; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=gGsjn8CjaqIhaH37MPgo ZvH87K8=; b=U4hvX/wN5ZPtEDj0EL6Mi1VT8IlgwO4WD/PCPP5hT/KXPUmncRYu K3UvFJotwzYexjnaQSAmk3irgu4FO3kQe7Q+p3h67QpqVBq6uhlpWUTlQYVVegvC DTIcYLixd1mFg5jng3ximRJJ/Mco1vE202LAS/dOYxQTGvwOoqzHQsU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=rFgmVCAW4pnuFn8oGBq7zJyDfkTnINzU6mclDfcsl23m0MZeCyc72Oq2x7G0NS NX8J6QoHCV5o1ZAu7Px6MO3VSK0V5oBRU78nOOH4kWopwT4cg1VqY+HHIpkW6BSA GDE+Dwj1A1e2QHnzXy8RCRO2ylRHu21pyLqyQwm9h5dJ4=; Received: (qmail 22785 invoked by alias); 15 May 2012 09:49:23 -0000 Received: (qmail 22739 invoked by uid 22791); 15 May 2012 09:49:21 -0000 X-SWARE-Spam-Status: No, hits=-3.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, TW_TM X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 15 May 2012 09:49:07 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 4E3001C65BC; Tue, 15 May 2012 05:49:06 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id oUU+OysyH8GB; Tue, 15 May 2012 05:49:06 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 120E21C65A8; Tue, 15 May 2012 05:49:06 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 121AF92BF6; Tue, 15 May 2012 05:49:06 -0400 (EDT) Date: Tue, 15 May 2012 05:49:06 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Tristan Gingold Subject: [Ada] Give full msg for finalize/adjust only if -gnateE. Message-ID: <20120515094905.GA9045@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The circuitery to save the first exception message (reraised as PE) in finalize or adjust operations has a distributed code size impact. This circuitery is now only enabled when then switch -gnateE is specified. Tested on x86_64-pc-linux-gnu, committed on trunk 2012-05-15 Tristan Gingold * exp_ch7.adb (Build_Exception_Handler): Save current occurrence only if -gnateE. (Build_Object_Declaration): Declare E_Id only if -gnateE. (Build_Raise_Statement): Call Raise_From_Controlled_Operation only if -gnateE (else raise PE). * s-soflin.adb (Save_Library_Occurrence): Handle null occurrence access. * a-except-2005.adb (Reraise_Library_Exception_If_Any): Call Raise_From_Controlled_Operation only if the saved occurrence is not null, otherwise raise PE. Index: exp_ch7.adb =================================================================== --- exp_ch7.adb (revision 187513) +++ exp_ch7.adb (working copy) @@ -717,63 +717,95 @@ Actuals : List_Id; Proc_To_Call : Entity_Id; Except : Node_Id; + Stmts : List_Id; begin - pragma Assert (Present (Data.E_Id)); pragma Assert (Present (Data.Raised_Id)); - -- Generate: + if Exception_Extra_Info + or else (For_Library and then not Restricted_Profile) + then + if Exception_Extra_Info then + -- Generate: - -- Get_Current_Excep.all + -- Get_Current_Excep.all - Except := - Make_Function_Call (Data.Loc, - Name => - Make_Explicit_Dereference (Data.Loc, - Prefix => - New_Reference_To (RTE (RE_Get_Current_Excep), Data.Loc))); + Except := + Make_Function_Call (Data.Loc, + Name => + Make_Explicit_Dereference (Data.Loc, + Prefix => + New_Reference_To (RTE (RE_Get_Current_Excep), + Data.Loc))); + else + -- Generate: - if For_Library and not Restricted_Profile then - Proc_To_Call := RTE (RE_Save_Library_Occurrence); - Actuals := New_List (Except); + -- null + + Except := Make_Null (Data.Loc); + end if; + + if For_Library and then not Restricted_Profile then + Proc_To_Call := RTE (RE_Save_Library_Occurrence); + Actuals := New_List (Except); + else + Proc_To_Call := RTE (RE_Save_Occurrence); + + -- The dereference occurs only when Exception_Extra_Info is true, + -- and therefore Except is not null. + + Actuals := New_List ( + New_Reference_To (Data.E_Id, Data.Loc), + Make_Explicit_Dereference (Data.Loc, Except)); + end if; + + -- Generate: + + -- when others => + -- if not Raised_Id then + -- Raised_Id := True; + + -- Save_Occurrence (E_Id, Get_Current_Excep.all.all); + -- or + -- Save_Library_Occurrence (Get_Current_Excep.all); + -- end if; + + Stmts := + New_List ( + Make_If_Statement (Data.Loc, + Condition => + Make_Op_Not (Data.Loc, + Right_Opnd => New_Reference_To (Data.Raised_Id, Data.Loc)), + + Then_Statements => New_List ( + Make_Assignment_Statement (Data.Loc, + Name => New_Reference_To (Data.Raised_Id, Data.Loc), + Expression => New_Reference_To (Standard_True, Data.Loc)), + + Make_Procedure_Call_Statement (Data.Loc, + Name => + New_Reference_To (Proc_To_Call, Data.Loc), + Parameter_Associations => Actuals)))); + else - Proc_To_Call := RTE (RE_Save_Occurrence); - Actuals := - New_List - (New_Reference_To (Data.E_Id, Data.Loc), - Make_Explicit_Dereference (Data.Loc, Except)); + -- Generate: + + -- Raised_Id := True; + + Stmts := New_List ( + Make_Assignment_Statement (Data.Loc, + Name => New_Reference_To (Data.Raised_Id, Data.Loc), + Expression => New_Reference_To (Standard_True, Data.Loc))); end if; -- Generate: -- when others => - -- if not Raised_Id then - -- Raised_Id := True; - -- Save_Occurrence (E_Id, Get_Current_Excep.all.all); - -- or - -- Save_Library_Occurrence (Get_Current_Excep.all); - -- end if; - return Make_Exception_Handler (Data.Loc, - Exception_Choices => - New_List (Make_Others_Choice (Data.Loc)), - Statements => New_List ( - Make_If_Statement (Data.Loc, - Condition => - Make_Op_Not (Data.Loc, - Right_Opnd => New_Reference_To (Data.Raised_Id, Data.Loc)), - - Then_Statements => New_List ( - Make_Assignment_Statement (Data.Loc, - Name => New_Reference_To (Data.Raised_Id, Data.Loc), - Expression => New_Reference_To (Standard_True, Data.Loc)), - - Make_Procedure_Call_Statement (Data.Loc, - Name => - New_Reference_To (Proc_To_Call, Data.Loc), - Parameter_Associations => Actuals))))); + Exception_Choices => New_List (Make_Others_Choice (Data.Loc)), + Statements => Stmts); end Build_Exception_Handler; ------------------------------- @@ -2998,8 +3030,6 @@ return; end if; - Data.Abort_Id := Make_Temporary (Loc, 'A'); - Data.E_Id := Make_Temporary (Loc, 'E'); Data.Raised_Id := Make_Temporary (Loc, 'R'); -- In certain scenarios, finalization can be triggered by an abort. If @@ -3019,35 +3049,44 @@ and then VM_Target = No_VM and then not For_Package then + Data.Abort_Id := Make_Temporary (Loc, 'A'); + A_Expr := New_Reference_To (RTE (RE_Triggered_By_Abort), Loc); - -- No abort, .NET/JVM or library-level finalizers + -- Generate: + -- Abort_Id : constant Boolean := ; + Append_To (Decls, + Make_Object_Declaration (Loc, + Defining_Identifier => Data.Abort_Id, + Constant_Present => True, + Object_Definition => New_Reference_To (Standard_Boolean, Loc), + Expression => A_Expr)); + else - A_Expr := New_Reference_To (Standard_False, Loc); + -- No abort, .NET/JVM or library-level finalizers + + Data.Abort_Id := Empty; end if; - -- Generate: - -- Abort_Id : constant Boolean := ; + if Exception_Extra_Info then + Data.E_Id := Make_Temporary (Loc, 'E'); - Append_To (Decls, - Make_Object_Declaration (Loc, - Defining_Identifier => Data.Abort_Id, - Constant_Present => True, - Object_Definition => New_Reference_To (Standard_Boolean, Loc), - Expression => A_Expr)); + -- Generate: + -- E_Id : Exception_Occurrence; - -- Generate: - -- E_Id : Exception_Occurrence; + E_Decl := + Make_Object_Declaration (Loc, + Defining_Identifier => Data.E_Id, + Object_Definition => + New_Reference_To (RTE (RE_Exception_Occurrence), Loc)); + Set_No_Initialization (E_Decl); - E_Decl := - Make_Object_Declaration (Loc, - Defining_Identifier => Data.E_Id, - Object_Definition => - New_Reference_To (RTE (RE_Exception_Occurrence), Loc)); - Set_No_Initialization (E_Decl); + Append_To (Decls, E_Decl); - Append_To (Decls, E_Decl); + else + Data.E_Id := Empty; + end if; -- Generate: -- Raised_Id : Boolean := False; @@ -3067,12 +3106,15 @@ (Data : Finalization_Exception_Data) return Node_Id is Stmt : Node_Id; + Expr : Node_Id; begin -- Standard run-time and .NET/JVM targets use the specialized routine -- Raise_From_Controlled_Operation. - if RTE_Available (RE_Raise_From_Controlled_Operation) then + if Exception_Extra_Info + and then RTE_Available (RE_Raise_From_Controlled_Operation) + then Stmt := Make_Procedure_Call_Statement (Data.Loc, Name => @@ -3092,6 +3134,21 @@ end if; -- Generate: + -- Raised_Id and then not Abort_Id + -- + -- Raised_Id + + Expr := New_Reference_To (Data.Raised_Id, Data.Loc); + + if Present (Data.Abort_Id) then + Expr := Make_And_Then (Data.Loc, + Left_Opnd => Expr, + Right_Opnd => + Make_Op_Not (Data.Loc, + Right_Opnd => New_Reference_To (Data.Abort_Id, Data.Loc))); + end if; + + -- Generate: -- if Raised_Id and then not Abort_Id then -- Raise_From_Controlled_Operation (E_Id); -- @@ -3100,13 +3157,7 @@ return Make_If_Statement (Data.Loc, - Condition => - Make_And_Then (Data.Loc, - Left_Opnd => New_Reference_To (Data.Raised_Id, Data.Loc), - Right_Opnd => - Make_Op_Not (Data.Loc, - Right_Opnd => New_Reference_To (Data.Abort_Id, Data.Loc))), - + Condition => Expr, Then_Statements => New_List (Stmt)); end Build_Raise_Statement; Index: s-soflin.adb =================================================================== --- s-soflin.adb (revision 187513) +++ s-soflin.adb (working copy) @@ -224,10 +224,13 @@ ----------------------------- procedure Save_Library_Occurrence (E : EOA) is + use Ada.Exceptions; begin if not Library_Exception_Set then Library_Exception_Set := True; - Ada.Exceptions.Save_Occurrence (Library_Exception, E.all); + if E /= null then + Ada.Exceptions.Save_Occurrence (Library_Exception, E.all); + end if; end if; end Save_Library_Occurrence; Index: a-except-2005.adb =================================================================== --- a-except-2005.adb (revision 187509) +++ a-except-2005.adb (working copy) @@ -1296,7 +1296,13 @@ begin if Library_Exception_Set then LE := Library_Exception; - Raise_From_Controlled_Operation (LE); + if LE.Id = Null_Id then + Raise_Exception_No_Defer + (E => Program_Error'Identity, + Message => "finalize/adjust raised exception"); + else + Raise_From_Controlled_Operation (LE); + end if; end if; end Reraise_Library_Exception_If_Any;