From ec62ba1eb087a73e748a808067b96af5d512f6ae Mon Sep 17 00:00:00 2001 From: Ronan Desplanques Date: Thu, 19 Dec 2024 11:10:12 +0100 Subject: [PATCH] ada: Fix abort deferral for finally parts This patch fixes two problems with how abort was deferred in finally parts. First, calls to runtime subprograms are now omitted when aborting is disallowed by active restrictions. Second, Abort_Undefer is now correctly called when the finally part propagates an exception. gcc/ada/ChangeLog: * exp_ch11.adb (Expand_N_Handled_Sequence_Of_Statements): Fix abort deferral. --- gcc/ada/exp_ch11.adb | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb index 66f386710089..189e0911fc4d 100644 --- a/gcc/ada/exp_ch11.adb +++ b/gcc/ada/exp_ch11.adb @@ -1302,14 +1302,25 @@ package body Exp_Ch11 is Expand_Cleanup_Actions (Parent (N)); end if; - if Present (Finally_Statements (N)) then - Prepend_To - (Finally_Statements (N), - Build_Runtime_Call (Sloc (N), RE_Abort_Defer)); - - Append_To - (Finally_Statements (N), - Build_Runtime_Call (Sloc (N), RE_Abort_Undefer)); + if Present (Finally_Statements (N)) and then Abort_Allowed then + if Exceptions_OK then + Set_Finally_Statements + (N, + New_List + (Build_Runtime_Call (Sloc (N), RE_Abort_Defer), + Build_Abort_Undefer_Block + (Sloc (N), + Stmts => Finally_Statements (N), + Context => N))); + else + Prepend_To + (Finally_Statements (N), + Build_Runtime_Call (Sloc (N), RE_Abort_Defer)); + + Append_To + (Finally_Statements (N), + Build_Runtime_Call (Sloc (N), RE_Abort_Undefer)); + end if; Analyze_List (Finally_Statements (N)); end if; -- 2.47.2