[Ada] Hang on cond expression as actual for anonymous access formal
authorJustin Squirek <squirek@adacore.com>
Tue, 21 Jul 2020 19:06:37 +0000 (15:06 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 20 Oct 2020 07:21:43 +0000 (03:21 -0400)
gcc/ada/

* exp_ch6.adb (Expand_Call_Helper): Properly handle the case
where the condition of a conditional expression has been
optimized out when calculating the value of an extra
accessibility parameter.

gcc/ada/exp_ch6.adb

index 5d8e48b..dd555a2 100644 (file)
@@ -4014,20 +4014,23 @@ package body Exp_Ch6 is
                               --  Find the relevant statement in the actions
 
                               Cond := First (Actions (Branch));
-                              loop
+                              while Present (Cond) loop
                                  exit when Nkind (Cond) in
                                              N_Case_Statement | N_If_Statement;
 
                                  Next (Cond);
-
-                                 if No (Cond) then
-                                    raise Program_Error;
-                                 end if;
                               end loop;
 
+                              --  The conditional expression may have been
+                              --  optimized away, so examine the actions in
+                              --  the branch.
+
+                              if No (Cond) then
+                                 Expand_Branch (Last (Actions (Branch)));
+
                               --  Iterate through if expression branches
 
-                              if Nkind (Cond) = N_If_Statement then
+                              elsif Nkind (Cond) = N_If_Statement then
                                  Expand_Branch (Last (Then_Statements (Cond)));
                                  Expand_Branch (Last (Else_Statements (Cond)));