[COMMITTED] ada: Fix small fallout of previous change

Message ID 20230529082927.2410269-1-poulhies@adacore.com
State Accepted
Headers
Series [COMMITTED] ada: Fix small fallout of previous change |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Marc Poulhiès May 29, 2023, 8:29 a.m. UTC
  From: Eric Botcazou <ebotcazou@adacore.com>

The same guard must be added to Expand_Simple_Function_Return as the one
that was added to Analyze_Function_Return.

gcc/ada/

	* exp_ch6.adb (Expand_Simple_Function_Return): Deal with a rewriting
	of the simple return during the adjustment of its expression.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch6.adb | 7 +++++++
 1 file changed, 7 insertions(+)
  

Patch

diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index bd4f4a1412d..87560462315 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -6641,6 +6641,13 @@  package body Exp_Ch6 is
       if Is_Boolean_Type (Exp_Typ) and then Nonzero_Is_True (Exp_Typ) then
          Adjust_Condition (Exp);
          Adjust_Result_Type (Exp, Exp_Typ);
+
+         --  The adjustment of the expression may have rewritten the return
+         --  statement itself, e.g. when it is turned into an if expression.
+
+         if Nkind (N) /= N_Simple_Return_Statement then
+            return;
+         end if;
       end if;
 
       --  Do validity check if enabled for returns