diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2023-04-07 00:26:19 +0200 |
---|---|---|
committer | Eric Botcazou <ebotcazou@adacore.com> | 2023-09-27 10:16:26 +0200 |
commit | 15467940a5b17193a4650567d856c7b30b7f1f34 (patch) | |
tree | 537a69acb8ca3d13ae36871e5cfc33066b102af5 /gcc | |
parent | 5ac700a00ffe73f4b7eb11f691c63a56a17c49c4 (diff) | |
download | gcc-15467940a5b17193a4650567d856c7b30b7f1f34.zip gcc-15467940a5b17193a4650567d856c7b30b7f1f34.tar.gz gcc-15467940a5b17193a4650567d856c7b30b7f1f34.tar.bz2 |
ada: Fix wrong finalization for case expression in expression function
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/exp_ch5.adb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb index d605f75..4eb9ade 100644 --- a/gcc/ada/exp_ch5.adb +++ b/gcc/ada/exp_ch5.adb @@ -4079,11 +4079,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. |