aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch6.adb
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2023-04-03 10:53:30 +0200
committerMarc Poulhiès <poulhies@adacore.com>2023-05-29 10:23:20 +0200
commit21b0ecb9853071f0642ee1fba7861e69789d0727 (patch)
treec05f35cbc92b42a2ad587c7224d5fb254c4a23cd /gcc/ada/sem_ch6.adb
parent4017d7fddda521dda5f0bc2c89942246d0aeedab (diff)
downloadgcc-21b0ecb9853071f0642ee1fba7861e69789d0727.zip
gcc-21b0ecb9853071f0642ee1fba7861e69789d0727.tar.gz
gcc-21b0ecb9853071f0642ee1fba7861e69789d0727.tar.bz2
ada: Fix wrong finalization for call to BIP function in conditional expression
This happens when the call is a dependent expression of the conditional expression, and the conditional expression is either the expression of a simple return statement or the return expression of an expression function. The reason is that the special processing of "tail calls" for BIP functions, i.e. calls that are the expression of simple return statements or the return expression of expression functions, is not applied. This change makes sure that it is applied by distributing the simple return statements enclosing conditional expressions into the dependent expressions of the conditional expressions in almost all cases. As a side effect, this elides a temporary in the nonlimited by-reference case, as well as a pair of calls to Adjust/Finalize in the nonlimited controlled case. gcc/ada/ * exp_ch4.adb (Expand_N_Case_Expression): Distribute simple return statements enclosing the conditional expression into the dependent expressions in almost all cases. (Expand_N_If_Expression): Likewise. (Process_Transient_In_Expression): Adjust to the above distribution. * exp_ch6.adb (Expand_Ctrl_Function_Call): Deal with calls in the dependent expressions of a conditional expression. * sem_ch6.adb (Analyze_Function_Return): Deal with the rewriting of a simple return statement during the resolution of its expression.
Diffstat (limited to 'gcc/ada/sem_ch6.adb')
-rw-r--r--gcc/ada/sem_ch6.adb12
1 files changed, 9 insertions, 3 deletions
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index c58a548..495e8b1 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -857,6 +857,14 @@ package body Sem_Ch6 is
end if;
Resolve (Expr, R_Type);
+
+ -- The expansion of the expression may have rewritten the return
+ -- statement itself, e.g. when it is a conditional expression.
+
+ if Nkind (N) /= N_Simple_Return_Statement then
+ return;
+ end if;
+
Check_Limited_Return (N, Expr, R_Type);
Check_Return_Construct_Accessibility (N, Stm_Entity);
@@ -952,9 +960,7 @@ package body Sem_Ch6 is
-- Defend against previous errors
- if Nkind (Expr) = N_Empty
- or else No (Etype (Expr))
- then
+ if Nkind (Expr) = N_Empty or else No (Etype (Expr)) then
return;
end if;