]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix wrong finalization for case expression in expression function
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 6 Apr 2023 22:26:19 +0000 (00:26 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 29 May 2023 08:23:21 +0000 (10:23 +0200)
This happens when the case expression contains a single alternative.

gcc/ada/

* exp_ch5.adb (Expand_N_Case_Statement): Do not remove the statement
if it is the node to be wrapped by a transient scope.

gcc/ada/exp_ch5.adb

index 30af98b3fc03bc53ceb8f63b95612e387f5b04ab..2be6e7e021e50f708e5a005e9dbff73d66f66372 100644 (file)
@@ -4127,11 +4127,15 @@ package body Exp_Ch5 is
 
          --  If there is only a single alternative, just replace it with the
          --  sequence of statements since obviously that is what is going to
-         --  be executed in all cases.
+         --  be executed in all cases, except if it is the node to be wrapped
+         --  by a transient scope, because this would cause the sequence of
+         --  statements to be leaked out of the transient scope.
 
          Len := List_Length (Alternatives (N));
 
-         if Len = 1 then
+         if Len = 1
+           and then not (Scope_Is_Transient and then Node_To_Be_Wrapped = N)
+         then
 
             --  We still need to evaluate the expression if it has any side
             --  effects.