When post-call actions need to be inserted in an expression context, an
N_Expression_With_Actions node is used.  That's not done here for the
condition of an if-expression, so the change adds this case.

It also deals with the case of a call to a primitive of a tagged type
written in prefixed notation, which was also missing.

No functional changes.

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

2020-06-10  Eric Botcazou  <ebotca...@adacore.com>

gcc/ada/

        * exp_ch6.adb (Insert_Post_Call_Actions): Deal with the context
        of an if-expression and with a call written in prefixed notation.
--- gcc/ada/exp_ch6.adb
+++ gcc/ada/exp_ch6.adb
@@ -7810,12 +7810,15 @@ package body Exp_Ch6 is
          return;
       end if;
 
-      --  Cases where the call is not a member of a statement list. This
-      --  includes the case where the call is an actual in another function
-      --  call or indexing, i.e. an expression context as well.
+      --  Cases where the call is not a member of a statement list. This also
+      --  includes the cases where the call is an actual in another function
+      --  call, or is an index, or is an operand of an if-expression, i.e. is
+      --  in an expression context.
 
       if not Is_List_Member (N)
-        or else Nkind_In (Context, N_Function_Call, N_Indexed_Component)
+        or else Nkind_In (Context, N_Function_Call,
+                                   N_If_Expression,
+                                   N_Indexed_Component)
       then
          --  In Ada 2012 the call may be a function call in an expression
          --  (since OUT and IN OUT parameters are now allowed for such calls).
@@ -7823,7 +7826,9 @@ package body Exp_Ch6 is
          --  but the constraint checks generated when subtypes of formal and
          --  actual don't match must be inserted in the form of assignments.
 
-         if Nkind (Original_Node (N)) = N_Function_Call then
+         if Nkind (N) = N_Function_Call
+           or else Nkind (Original_Node (N)) = N_Function_Call
+         then
             pragma Assert (Ada_Version >= Ada_2012);
             --  Functions with '[in] out' parameters are only allowed in Ada
             --  2012.

Reply via email to