https://gcc.gnu.org/g:6a7849592d442563a799cff35f3b43fd4b828681
commit r15-5400-g6a7849592d442563a799cff35f3b43fd4b828681 Author: Eric Botcazou <ebotca...@adacore.com> Date: Thu Oct 31 11:21:56 2024 +0100 ada: Small cleanup and refactoring in expansion of asynchronous select The exception handler that catches Abort_Signal does nothing nowadays. This refactors the code to use Build_Abort_Block more consistently and also makes it simpler by dropping the identifier on the abort block. No functional changes. gcc/ada/ChangeLog: * exp_sel.ads (Build_Abort_Block): Remove second parameter and rename the third. (Build_Abort_Block_Handler): Fix description. * exp_sel.adb (Build_Abort_Block): Remove second parameter, rename the third and adjust accordingly. * exp_ch9.adb (Expand_N_Asynchronous_Select): Fix the description of the exception handler throughout. Remove Abort_Block_Ent and Hdle local variables. Call Build_Abort_Block consistently to build the abort block and adjust existing calls. Diff: --- gcc/ada/exp_ch9.adb | 117 ++++++++++++++++++++-------------------------------- gcc/ada/exp_sel.adb | 13 ++---- gcc/ada/exp_sel.ads | 13 +++--- 3 files changed, 53 insertions(+), 90 deletions(-) diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb index 9b82a9fcfdda..cf4d4d822562 100644 --- a/gcc/ada/exp_ch9.adb +++ b/gcc/ada/exp_ch9.adb @@ -6482,7 +6482,7 @@ package body Exp_Ch9 is -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions -- end; -- exception - -- when Abort_Signal => Abort_Undefer; + -- when Abort_Signal => null; -- end; -- parm := P.param; @@ -6545,7 +6545,7 @@ package body Exp_Ch9 is -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions -- end; -- exception - -- when Abort_Signal => Abort_Undefer; + -- when Abort_Signal => null; -- end; -- if not Cancelled (Bnn) then @@ -6626,7 +6626,7 @@ package body Exp_Ch9 is -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions -- end; -- exception - -- when Abort_Signal => Abort_Undefer; + -- when Abort_Signal => null; -- end; -- if not Cancelled (Bnn) then @@ -6659,7 +6659,7 @@ package body Exp_Ch9 is -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions -- end; -- exception - -- when Abort_Signal => Abort_Undefer; + -- when Abort_Signal => null; -- end; -- if not U then @@ -6693,7 +6693,6 @@ package body Exp_Ch9 is Abrt : constant Node_Id := Abortable_Part (N); Trig : constant Node_Id := Triggering_Alternative (N); - Abort_Block_Ent : Entity_Id; Abortable_Block : Node_Id; Actuals : List_Id; Astats : List_Id; @@ -6714,7 +6713,6 @@ package body Exp_Ch9 is Ename : Node_Id; Enqueue_Call : Node_Id; Formals : List_Id; - Hdle : List_Id; Index : Node_Id; Lim_Typ_Stmts : List_Id; N_Orig : Node_Id; @@ -6968,17 +6966,11 @@ package body Exp_Ch9 is -- begin -- Cleanup_Block -- exception - -- when Abort_Signal => Abort_Undefer; + -- when Abort_Signal => null; -- end; - Abort_Block_Ent := Make_Temporary (Loc, 'A'); - ProtE_Stmts := - New_List ( - Make_Implicit_Label_Declaration (Loc, - Defining_Identifier => Abort_Block_Ent), - - Build_Abort_Block - (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block)); + ProtE_Stmts := New_List ( + Build_Abort_Block (Loc, Cleanup_Block_Ent, Cleanup_Block)); -- Generate: -- if not Cancelled (Bnn) then @@ -7081,18 +7073,11 @@ package body Exp_Ch9 is -- begin -- Cleanup_Block -- exception - -- when Abort_Signal => Abort_Undefer; + -- when Abort_Signal => null; -- end; - Abort_Block_Ent := Make_Temporary (Loc, 'A'); - - Append_To (TaskE_Stmts, - Make_Implicit_Label_Declaration (Loc, - Defining_Identifier => Abort_Block_Ent)); - Append_To (TaskE_Stmts, - Build_Abort_Block - (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block)); + Build_Abort_Block (Loc, Cleanup_Block_Ent, Cleanup_Block)); -- Generate: -- if not T then @@ -7237,10 +7222,6 @@ package body Exp_Ch9 is Prefix => New_Occurrence_Of (Dblock_Ent, Loc), Attribute_Name => Name_Unchecked_Access)); - -- Create the inner block to protect the abortable part - - Hdle := New_List (Build_Abort_Block_Handler (Loc)); - Prepend_To (Astats, Build_Runtime_Call (Loc, RE_Abort_Undefer)); Abortable_Block := @@ -7252,6 +7233,18 @@ package body Exp_Ch9 is Has_Created_Identifier => True, Is_Asynchronous_Call_Block => True); + -- Wrap the abortable block in an exception handling block + + -- Generate: + -- begin + -- Abortable_Block + -- exception + -- when Abort_Signal => null; + -- end; + + Stmts := New_List ( + Build_Abort_Block (Loc, Blk_Ent, Abortable_Block)); + -- Append call to if Enqueue (When, DB'Unchecked_Access) then Rewrite (Ecall, @@ -7260,16 +7253,7 @@ package body Exp_Ch9 is Make_Function_Call (Loc, Name => Enqueue_Call, Parameter_Associations => Parameter_Associations (Ecall)), - Then_Statements => - New_List (Make_Block_Statement (Loc, - Handled_Statement_Sequence => - Make_Handled_Sequence_Of_Statements (Loc, - Statements => New_List ( - Make_Implicit_Label_Declaration (Loc, - Defining_Identifier => Blk_Ent, - Label_Construct => Abortable_Block), - Abortable_Block), - Exception_Handlers => Hdle))))); + Then_Statements => Stmts)); Stmts := New_List (Ecall); @@ -7387,31 +7371,21 @@ package body Exp_Ch9 is Has_Created_Identifier => True, Is_Asynchronous_Call_Block => True); - Stmts := New_List ( - Make_Block_Statement (Loc, - Handled_Statement_Sequence => - Make_Handled_Sequence_Of_Statements (Loc, - Statements => New_List ( - Make_Implicit_Label_Declaration (Loc, - Defining_Identifier => Blk_Ent, - Label_Construct => Abortable_Block), - Abortable_Block), - - -- exception + -- Wrap the abortable block in an exception handling block - Exception_Handlers => New_List ( - Make_Implicit_Exception_Handler (Loc, - - -- when Abort_Signal => - -- null; + -- Generate: + -- begin + -- Abortable_Block + -- exception + -- when Abort_Signal => null; + -- end; - Exception_Choices => - New_List (New_Occurrence_Of (Stand.Abort_Signal, Loc)), - Statements => New_List (Make_Null_Statement (Loc)))))), + Stmts := New_List ( + Build_Abort_Block (Loc, Blk_Ent, Abortable_Block), - -- if not Cancelled (Bnn) then - -- triggered statements - -- end if; + -- if not Cancelled (Bnn) then + -- triggered statements + -- end if; Make_Implicit_If_Statement (N, Condition => Make_Op_Not (Loc, @@ -7467,10 +7441,6 @@ package body Exp_Ch9 is Call := Stmt; - -- Create the inner block to protect the abortable part - - Hdle := New_List (Build_Abort_Block_Handler (Loc)); - if Abort_Allowed then Prepend_To (Astats, Build_Runtime_Call (Loc, RE_Abort_Undefer)); end if; @@ -7483,16 +7453,17 @@ package body Exp_Ch9 is Has_Created_Identifier => True, Is_Asynchronous_Call_Block => True); + -- Wrap the abortable block in an exception handling block + + -- Generate: + -- begin + -- Abortable_Block + -- exception + -- when Abort_Signal => null; + -- end; + Insert_After (Call, - Make_Block_Statement (Loc, - Handled_Statement_Sequence => - Make_Handled_Sequence_Of_Statements (Loc, - Statements => New_List ( - Make_Implicit_Label_Declaration (Loc, - Defining_Identifier => Blk_Ent, - Label_Construct => Abortable_Block), - Abortable_Block), - Exception_Handlers => Hdle))); + Build_Abort_Block (Loc, Blk_Ent, Abortable_Block)); -- Create new call statement diff --git a/gcc/ada/exp_sel.adb b/gcc/ada/exp_sel.adb index 3c04687db6bd..9acd81b04974 100644 --- a/gcc/ada/exp_sel.adb +++ b/gcc/ada/exp_sel.adb @@ -40,24 +40,19 @@ package body Exp_Sel is ----------------------- function Build_Abort_Block - (Loc : Source_Ptr; - Abr_Blk_Ent : Entity_Id; - Cln_Blk_Ent : Entity_Id; - Blk : Node_Id) return Node_Id + (Loc : Source_Ptr; + Blk_Ent : Entity_Id; + Blk : Node_Id) return Node_Id is begin return Make_Block_Statement (Loc, - Identifier => New_Occurrence_Of (Abr_Blk_Ent, Loc), - - Declarations => No_List, - Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List ( Make_Implicit_Label_Declaration (Loc, - Defining_Identifier => Cln_Blk_Ent, + Defining_Identifier => Blk_Ent, Label_Construct => Blk), Blk), diff --git a/gcc/ada/exp_sel.ads b/gcc/ada/exp_sel.ads index 47a49e6b78b1..b21087ee6580 100644 --- a/gcc/ada/exp_sel.ads +++ b/gcc/ada/exp_sel.ads @@ -31,24 +31,21 @@ with Types; use Types; package Exp_Sel is function Build_Abort_Block - (Loc : Source_Ptr; - Abr_Blk_Ent : Entity_Id; - Cln_Blk_Ent : Entity_Id; - Blk : Node_Id) return Node_Id; + (Loc : Source_Ptr; + Blk_Ent : Entity_Id; + Blk : Node_Id) return Node_Id; -- Generate: -- begin -- Blk -- exception -- when Abort_Signal => null; -- end; - -- Abr_Blk_Ent is the name of the generated block, Cln_Blk_Ent is the name - -- of the encapsulated cleanup block, Blk is the actual block name. + -- Blk_Ent is the identifier of Blk. -- The exception handler code is built by Build_Abort_Block_Handler. function Build_Abort_Block_Handler (Loc : Source_Ptr) return Node_Id; -- Generate: - -- when others => - -- null; + -- when Abort_Signal => null; -- This is an exception handler to stop propagation of aborts, without -- modifying the deferral level.