]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Fix wrong finalization for call to BIP function in conditional expression
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 3 Apr 2023 08:53:30 +0000 (10:53 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 29 May 2023 08:23:20 +0000 (10:23 +0200)
commit21b0ecb9853071f0642ee1fba7861e69789d0727
treec05f35cbc92b42a2ad587c7224d5fb254c4a23cd
parent4017d7fddda521dda5f0bc2c89942246d0aeedab
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.
gcc/ada/exp_ch4.adb
gcc/ada/exp_ch6.adb
gcc/ada/sem_ch6.adb