diff mbox series

[Ada] ACATS 4.1R-c611a04: Class-wide preconditions in dispatching calls

Message ID 20210616084355.GA94809@adacore.com
State New
Headers show
Series [Ada] ACATS 4.1R-c611a04: Class-wide preconditions in dispatching calls | expand

Commit Message

Pierre-Marie de Rodat June 16, 2021, 8:43 a.m. UTC
Completing previous patch since it introduced a regression on ACATS
c611a03 under certified runtime.

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

gcc/ada/

	* exp_disp.adb (Build_Class_Wide_Check): Ensure that evaluation
	of actuals is side effects free (since the check duplicates
	actuals).
diff mbox series

Patch

diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb
--- a/gcc/ada/exp_disp.adb
+++ b/gcc/ada/exp_disp.adb
@@ -868,6 +868,7 @@  package body Exp_Disp is
 
          Str_Loc : constant String := Build_Location_String (Loc);
 
+         A    : Node_Id;
          Cond : Node_Id;
          Msg  : Node_Id;
          Prec : Node_Id;
@@ -900,6 +901,15 @@  package body Exp_Disp is
                return;
             end if;
 
+            --  Ensure that the evaluation of the actuals will not produce side
+            --  effects (since the check will use a copy of the actuals).
+
+            A := First_Actual (Call_Node);
+            while Present (A) loop
+               Remove_Side_Effects (A);
+               Next_Actual (A);
+            end loop;
+
             --  The expression for the precondition is analyzed within the
             --  generated pragma. The message text is the last parameter of
             --  the generated pragma, indicating source of precondition.