From 57966b4d2f8adaf0d9af12e07a8ee32cd4184bcc Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Fri, 16 Oct 2020 19:53:40 +0200 Subject: [PATCH] [Ada] Fix couple of minor issues with local exception propagation gcc/ada/ * exp_ch11.adb (Expand_N_Raise_Statement): Use Is_Entity_Name consistently in tests on the name of the statement. * exp_prag.adb (Expand_Pragma_Check): In the local propagation case, wrap the raise statement in a block statement. --- gcc/ada/exp_ch11.adb | 6 +++--- gcc/ada/exp_prag.adb | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb index abc91a2f131..ddd69dfce98 100644 --- a/gcc/ada/exp_ch11.adb +++ b/gcc/ada/exp_ch11.adb @@ -1553,7 +1553,7 @@ package body Exp_Ch11 is begin -- Processing for locally handled exception (exclude reraise case) - if Present (Name (N)) and then Nkind (Name (N)) = N_Identifier then + if Present (Name (N)) and then Is_Entity_Name (Name (N)) then if Debug_Flag_Dot_G or else Restriction_Active (No_Exception_Propagation) then @@ -1657,7 +1657,7 @@ package body Exp_Ch11 is -- but this is also faster in all modes). Propagate Comes_From_Source -- flag to the new node. - if Present (Name (N)) and then Nkind (Name (N)) = N_Identifier then + if Present (Name (N)) and then Is_Entity_Name (Name (N)) then Src := Comes_From_Source (N); if Entity (Name (N)) = Standard_Constraint_Error then @@ -1689,7 +1689,7 @@ package body Exp_Ch11 is -- where location_string identifies the file/line of the raise - if Present (Name (N)) then + if Present (Name (N)) and then Is_Entity_Name (Name (N)) then declare Id : Entity_Id := Entity (Name (N)); Buf : Bounded_String; diff --git a/gcc/ada/exp_prag.adb b/gcc/ada/exp_prag.adb index 53e2d97cd75..9a227c693d7 100644 --- a/gcc/ada/exp_prag.adb +++ b/gcc/ada/exp_prag.adb @@ -425,7 +425,12 @@ package body Exp_Prag is -- Generate the appropriate if statement. Note that we consider this to -- be an explicit conditional in the source, not an implicit if, so we - -- do not call Make_Implicit_If_Statement. + -- do not call Make_Implicit_If_Statement. Note also that we wrap the + -- raise statement in a block statement so that, if the condition is + -- evaluated at compile time to False, then the rewriting of the if + -- statement will not involve the raise but the block statement, and + -- thus not leave a dangling reference to the raise statement in the + -- Local_Raise_Statements list of the handler. -- Case where we generate a direct raise @@ -438,8 +443,14 @@ package body Exp_Prag is Make_If_Statement (Loc, Condition => Make_Op_Not (Loc, Right_Opnd => Cond), Then_Statements => New_List ( - Make_Raise_Statement (Loc, - Name => New_Occurrence_Of (RTE (RE_Assert_Failure), Loc))))); + Make_Block_Statement (Loc, + Handled_Statement_Sequence => + Make_Handled_Sequence_Of_Statements (Loc, + Statements => New_List ( + Make_Raise_Statement (Loc, + Name => + New_Occurrence_Of (RTE (RE_Assert_Failure), + Loc)))))))); -- Case where we call the procedure -- 2.30.2