https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114175

--- Comment #2 from Edwin Lu <ewlu at rivosinc dot com> ---
(In reply to Jakub Jelinek from comment #1)
> Does the
> https://gcc.gnu.org/pipermail/gcc-patches/2024-February/646882.html
> patch fix that?
> The test was committed ahead exactly to find out what targets have a problem
> with that.

Applied the patch on top of r14-9243-g02ca9d3f0c5. Looks like the problem is
still there.

ewlu@ewlu:/scratch/ewlu/ci/triage/compare/build-patched$
./build-gcc-linux-stage2/gcc/xgcc -B./build-gcc-linux-stage2/gcc/ 
../gcc/gcc/testsuite/gcc.dg/c23-stdarg-6.c  -march=rv64gc -mabi=lp64d
-mtune=rocket -mcmodel=medlow   -fdiagnostics-plain-output   -std=c23
-pedantic-errors      -lm  -o ./c23-stdarg-6.exe -g
ewlu@ewlu:/scratch/ewlu/ci/triage/compare/build-patched$ QEMU_CPU=rv64
bin/qemu-riscv64 c23-stdarg-6.exe
Aborted (core dumped)

ewlu@ewlu:/scratch/ewlu/ci/triage/compare/gcc$ git diff HEAD~1
diff --git a/gcc/calls.cc b/gcc/calls.cc
index 01f44734743..21d78f9779f 100644
--- a/gcc/calls.cc
+++ b/gcc/calls.cc
@@ -2938,7 +2938,7 @@ expand_call (tree exp, rtx target, int ignore)
         /* Count the struct value address, if it is passed as a parm.  */
         + structure_value_addr_parm);
   else if (TYPE_NO_NAMED_ARGS_STDARG_P (funtype))
-    n_named_args = 0;
+    n_named_args = structure_value_addr_parm;
   else
     /* If we know nothing, treat all args as named.  */
     n_named_args = num_actuals;
@@ -2970,14 +2970,15 @@ expand_call (tree exp, rtx target, int ignore)
      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
+  if ((type_arg_types != 0 || TYPE_NO_NAMED_ARGS_STDARG_P (funtype))
       && targetm.calls.strict_argument_naming (args_so_far))
     ;
   else if (type_arg_types != 0
           && ! targetm.calls.pretend_outgoing_varargs_named (args_so_far))
     /* Don't include the last named arg.  */
     --n_named_args;
-  else if (TYPE_NO_NAMED_ARGS_STDARG_P (funtype))
+  else if (TYPE_NO_NAMED_ARGS_STDARG_P (funtype)
+          && ! targetm.calls.pretend_outgoing_varargs_named (args_so_far))
     n_named_args = 0;
   else
     /* Treat all args as named.  */

Reply via email to