[Ada] Bad expansion with -gnato2 and if expression

Message ID 20210506075812.GA125720@adacore.com
State New
Headers show
Series
  • [Ada] Bad expansion with -gnato2 and if expression
Related show

Commit Message

Pierre-Marie de Rodat May 6, 2021, 7:58 a.m.
When dealing with -gnato2 inside an if expression, we might drop on the
floor the If or Else_Nodes.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* exp_ch4.adb (Expand_N_If_Expression):
	Apply_Arithmetic_Overflow_Check will not deal with
	Then/Else_Actions so skip minimizing overflow checks if any
	actions are present.

Patch

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -5915,9 +5915,14 @@  package body Exp_Ch4 is
    --  Start of processing for Expand_N_If_Expression
 
    begin
-      --  Check for MINIMIZED/ELIMINATED overflow mode
+      --  Check for MINIMIZED/ELIMINATED overflow mode.
+      --  Apply_Arithmetic_Overflow_Check will not deal with Then/Else_Actions
+      --  so skip this step if any actions are present.
 
-      if Minimized_Eliminated_Overflow_Check (N) then
+      if Minimized_Eliminated_Overflow_Check (N)
+        and then No (Then_Actions (N))
+        and then No (Else_Actions (N))
+      then
          Apply_Arithmetic_Overflow_Check (N);
          return;
       end if;