]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix abort deferral for finally parts
authorRonan Desplanques <desplanques@adacore.com>
Thu, 19 Dec 2024 10:10:12 +0000 (11:10 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 7 Jan 2025 12:33:34 +0000 (13:33 +0100)
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

index 66f3867100894122bf7a58eb83847da57390d48c..189e0911fc4d43f51f6b6b02f9594a13375e0784 100644 (file)
@@ -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;