Exclude the last named argument for non-variadic function

Message ID CAMe9rOpv=m3g4WJPR7HJpUBALm4Od-30dgAs9m6akwmg6AzAYw@mail.gmail.com
State New
Headers
Series Exclude the last named argument for non-variadic function |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed

Commit Message

H.J. Lu Nov. 1, 2024, 6:53 a.m. UTC
  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.
  

Comments

Jeff Law Dec. 1, 2024, 10:20 p.m. UTC | #1
On 11/1/24 12:53 AM, H.J. Lu wrote:
> 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.
I'm not comfortable changing this in stage3.  I realize the patch was 
submitted while we were still in stage1, but just barely.  I'd like to 
see this resubmitted early in gcc-16 stage1 and with testing beyond just 
x86 since there's potentially ABI implications here.

jeff
  
H.J. Lu Dec. 1, 2024, 10:47 p.m. UTC | #2
On Mon, Dec 2, 2024 at 6:20 AM Jeff Law <jeffreyalaw@gmail.com> wrote:
>
>
>
> On 11/1/24 12:53 AM, H.J. Lu wrote:
> > 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.
> I'm not comfortable changing this in stage3.  I realize the patch was
> submitted while we were still in stage1, but just barely.  I'd like to
> see this resubmitted early in gcc-16 stage1 and with testing beyond just
> x86 since there's potentially ABI implications here.
>
> jeff

I am dropping this patch since it is no longer needed.

Thanks.
  

Patch

From df38212c7b7943feed38f94bf450bd2dbefda245 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@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.tools@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