expand_call has /* Now possibly adjust the number of named args. Normally, don't include the last named arg if anonymous args follow. We do include the last named arg if targetm.calls.strict_argument_naming() returns nonzero. (If no anonymous args follow, the result of list_length is actually one too large. This is harmless.)
If targetm.calls.pretend_outgoing_varargs_named() returns nonzero, and targetm.calls.strict_argument_naming() returns zero, this machine will be able to place unnamed args that were passed in registers into the stack. So treat all args as named. This allows the insns emitting for a specific argument list to be independent of the function declaration. If targetm.calls.pretend_outgoing_varargs_named() returns zero, we do not have any reliable way to pass unnamed args in registers, so we must force them into memory. */ if ((type_arg_types != 0 || TYPE_NO_NAMED_ARGS_STDARG_P (funtype)) && targetm.calls.strict_argument_naming (args_so_far)) ; For non-variadic function, the number of named args is one too large. Don't include the last named argument for non-variadic function so that the accurate number of named args can be used. PR middle-end/117387 * calls.cc (expand_call): Don't include the last named argument for non-variadic function. -- H.J.
From df38212c7b7943feed38f94bf450bd2dbefda245 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.to...@gmail.com> Date: Fri, 1 Nov 2024 07:40:13 +0800 Subject: [PATCH] Exclude the last named argument for non-variadic function expand_call has /* Now possibly adjust the number of named args. Normally, don't include the last named arg if anonymous args follow. We do include the last named arg if targetm.calls.strict_argument_naming() returns nonzero. (If no anonymous args follow, the result of list_length is actually one too large. This is harmless.) If targetm.calls.pretend_outgoing_varargs_named() returns nonzero, and targetm.calls.strict_argument_naming() returns zero, this machine will be able to place unnamed args that were passed in registers into the stack. So treat all args as named. This allows the insns emitting for a specific argument list to be independent of the function declaration. If targetm.calls.pretend_outgoing_varargs_named() returns zero, we do not have any reliable way to pass unnamed args in registers, so we must force them into memory. */ if ((type_arg_types != 0 || TYPE_NO_NAMED_ARGS_STDARG_P (funtype)) && targetm.calls.strict_argument_naming (args_so_far)) ; For non-variadic function, the number of named args is one too large. Don't include the last named argument for non-variadic function so that the accurate number of named args can be used. PR middle-end/117387 * calls.cc (expand_call): Don't include the last named argument for non-variadic function. Signed-off-by: H.J. Lu <hjl.to...@gmail.com> --- gcc/calls.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gcc/calls.cc b/gcc/calls.cc index f67067acad4..1df064dcef6 100644 --- a/gcc/calls.cc +++ b/gcc/calls.cc @@ -2992,8 +2992,6 @@ expand_call (tree exp, rtx target, int ignore) Normally, don't include the last named arg if anonymous args follow. We do include the last named arg if targetm.calls.strict_argument_naming() returns nonzero. - (If no anonymous args follow, the result of list_length is actually - one too large. This is harmless.) If targetm.calls.pretend_outgoing_varargs_named() returns nonzero, and targetm.calls.strict_argument_naming() returns zero, @@ -3008,7 +3006,8 @@ expand_call (tree exp, rtx target, int ignore) if ((type_arg_types != 0 || TYPE_NO_NAMED_ARGS_STDARG_P (funtype)) && targetm.calls.strict_argument_naming (args_so_far)) - ; + /* Don't include the last named arg for non-variadic function. */ + n_named_args -= !stdarg_p (funtype); else if (type_arg_types != 0 && ! targetm.calls.pretend_outgoing_varargs_named (args_so_far)) /* Don't include the last named arg. */ -- 2.47.0