From: Iain Buclaw Date: Sun, 29 Jan 2023 20:25:40 +0000 (+0100) Subject: d: Only handle the left-to-right evaluation of a call expression during gimplify X-Git-Tag: basepoints/gcc-14~945 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e9dd9de169034810b92d47bf78284db731fa5da;p=thirdparty%2Fgcc.git d: Only handle the left-to-right evaluation of a call expression during gimplify 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. --- diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 920b45d0480b..0e8e07366ee0 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -2172,7 +2172,6 @@ d_build_call (TypeFunction *tf, tree callable, tree object, /* Build the argument list for the call. */ vec *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. diff --git a/gcc/d/d-gimplify.cc b/gcc/d/d-gimplify.cc index 4072a3d92cf7..04cb631244cd 100644 --- a/gcc/d/d-gimplify.cc +++ b/gcc/d/d-gimplify.cc @@ -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++) {