diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2023-04-07 00:26:19 +0200 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2023-05-29 10:23:21 +0200 |
commit | 8eb9a6b4c4b68fb39f02608787e2bd9836544cad (patch) | |
tree | 23acbbee3820a02ebc3c87d327afb8fd06287c1c /gcc/ada/exp_ch5.adb | |
parent | bbe40e766bf58158427f4c212655c376768b1c75 (diff) | |
download | gcc-8eb9a6b4c4b68fb39f02608787e2bd9836544cad.zip gcc-8eb9a6b4c4b68fb39f02608787e2bd9836544cad.tar.gz gcc-8eb9a6b4c4b68fb39f02608787e2bd9836544cad.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/ada/exp_ch5.adb')
-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 30af98b..2be6e7e 100644 --- a/gcc/ada/exp_ch5.adb +++ b/gcc/ada/exp_ch5.adb @@ -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. |