]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Only handle the left-to-right evaluation of a call expression during gimplify
authorIain Buclaw <ibuclaw@gdcproject.org>
Sun, 29 Jan 2023 20:25:40 +0000 (21:25 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Tue, 21 Feb 2023 14:12:19 +0000 (15:12 +0100)
Removes an unnecessary rewriting of the front-end AST during lowering.

gcc/d/ChangeLog:

* d-codegen.cc (d_build_call): Remove front-end expansion of
side-effects in a call expression.
* d-gimplify.cc (d_gimplify_call_expr): Gimplify the callee before its
arguments.

gcc/d/d-codegen.cc
gcc/d/d-gimplify.cc

index 920b45d0480bd9db171443b66676871a214b1618..0e8e07366ee08c5a2bb5971214d311897e69260e 100644 (file)
@@ -2172,7 +2172,6 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
 
   /* Build the argument list for the call.  */
   vec <tree, va_gc> *args = NULL;
-  tree saved_args = NULL_TREE;
   bool noreturn_call = false;
 
   /* If this is a delegate call or a nested function being called as
@@ -2182,23 +2181,6 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
 
   if (arguments)
     {
-      /* First pass, evaluated expanded tuples in function arguments.  */
-      for (size_t i = 0; i < arguments->length; ++i)
-       {
-       Lagain:
-         Expression *arg = (*arguments)[i];
-         gcc_assert (arg->op != EXP::tuple);
-
-         if (arg->op == EXP::comma)
-           {
-             CommaExp *ce = arg->isCommaExp ();
-             tree tce = build_expr (ce->e1);
-             saved_args = compound_expr (saved_args, tce);
-             (*arguments)[i] = ce->e2;
-             goto Lagain;
-           }
-       }
-
       const size_t nparams = tf->parameterList.length ();
       /* if _arguments[] is the first argument.  */
       const size_t varargs = tf->isDstyleVariadic ();
@@ -2257,17 +2239,12 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
        }
     }
 
-  /* Evaluate the callee before calling it.  */
-  if (TREE_SIDE_EFFECTS (callee))
-    {
-      callee = d_save_expr (callee);
-      saved_args = compound_expr (callee, saved_args);
-    }
-
   /* If we saw a `noreturn` parameter, any unreachable argument evaluations
      after it are discarded, as well as the function call itself.  */
   if (noreturn_call)
     {
+      tree saved_args = NULL_TREE;
+
       if (TREE_SIDE_EFFECTS (callee))
        saved_args = compound_expr (callee, saved_args);
 
@@ -2297,7 +2274,7 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
       result = force_target_expr (result);
     }
 
-  return compound_expr (saved_args, result);
+  return result;
 }
 
 /* Build and return the correct call to fmod depending on TYPE.
index 4072a3d92cf759caa4adfe2875e4b3a8cdf63069..04cb631244cda8e9a72b59d47c32b77bf99946ac 100644 (file)
@@ -162,6 +162,15 @@ d_gimplify_call_expr (tree *expr_p, gimple_seq *pre_p)
   if (!has_side_effects)
     return GS_UNHANDLED;
 
+  /* Evaluate the callee before calling it.  */
+  tree new_call_fn = CALL_EXPR_FN (*expr_p);
+
+  if (gimplify_expr (&new_call_fn, pre_p, NULL,
+                    is_gimple_call_addr, fb_rvalue) == GS_ERROR)
+    return GS_ERROR;
+
+  CALL_EXPR_FN (*expr_p) = new_call_fn;
+
   /* Leave the last argument for gimplify_call_expr.  */
   for (int i = 0; i < nargs - 1; i++)
     {