public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "palmer at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/114175] [13/14] RISC-V: Execution test failures on gcc.dg/c23-stdarg-6.c
Date: Thu, 29 Feb 2024 22:20:29 +0000	[thread overview]
Message-ID: <bug-114175-4-VcbFLuNDW5@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114175-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #15 from palmer at gcc dot gnu.org ---
It's a little easier to see from the float version of the code.

$ cat gcc/testsuite/gcc.dg/c23-stdarg-6.c 
/* Test C23 variadic functions with no named parameters, or last named
   parameter with a declaration not allowed in C17.  Execution tests.  */
/* { dg-do run } */
/* { dg-options "-std=c23 -pedantic-errors" } */

#include <stdarg.h>
#include <stdio.h>

extern void abort (void);
extern void exit (int);
struct s { char c[1000]; };

struct s
f (...)
{
  va_list ap;
  va_start (ap);
  int r = va_arg (ap, double);
  va_end (ap);
  struct s ret = {};
  ret.c[0] = r;
  ret.c[999] = 42;
  return ret;
}

int
main ()
{
  struct s x = f (1.0);
  fprintf(stderr, "%d\n", x.c[0]);
  if (x.c[0] != 1)
    abort ();
  exit (0);
}
$ riscv64-unknown-linux-gnu-gcc gcc/testsuite/gcc.dg/c23-stdarg-6.c -o test
-std=c2x -static -O3
$ riscv64-unknown-linux-gnu-objdump -d test
...
0000000000010412 <main>:
...
   1042e:       850a                    mv      a0,sp
...
   10438:       112000ef                jal     1054a <f>
...
000000000001054a <f>:
   1054a:       f20507d3                fmv.d.x fa5,a0

The psABI says

    A callee with variadic arguments is responsible for copying the contents
    of registers used to pass variadic arguments to the vararg save area,
    which must be contiguous with arguments passed on the stack.

which I'm taking to mean the "1.0" is meant to be passed in a register.  It
also says

    Values are returned in the same manner as a first named argument of the
    same type would be passed. If such an argument would have been passed by
    reference, the caller allocates memory for the return value, and passes
    the address as an implicit first parameter.

So I think we're screwing up both ends of this one: the caller is passing the
return struct in a0 (losing the first arg), which the callee is obtaining the
first argument from a0 (losing the return struct).

That all very much seems like a backend bug to me.

  parent reply	other threads:[~2024-02-29 22:20 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 17:45 [Bug target/114175] New: [14] RISC-V: Execution tests " ewlu at rivosinc dot com
2024-02-29 17:51 ` [Bug target/114175] [14] RISC-V: Execution test failures " jakub at gcc dot gnu.org
2024-02-29 18:49 ` ewlu at rivosinc dot com
2024-02-29 18:53 ` jakub at gcc dot gnu.org
2024-02-29 18:57 ` ewlu at rivosinc dot com
2024-02-29 18:59 ` jakub at gcc dot gnu.org
2024-02-29 19:01 ` jakub at gcc dot gnu.org
2024-02-29 19:56 ` [Bug target/114175] [13/14] " jakub at gcc dot gnu.org
2024-02-29 20:03 ` jakub at gcc dot gnu.org
2024-02-29 20:07 ` palmer at gcc dot gnu.org
2024-02-29 20:09 ` jakub at gcc dot gnu.org
2024-02-29 20:09 ` jakub at gcc dot gnu.org
2024-02-29 20:20 ` jakub at gcc dot gnu.org
2024-02-29 20:22 ` jakub at gcc dot gnu.org
2024-02-29 21:28 ` palmer at gcc dot gnu.org
2024-02-29 22:20 ` palmer at gcc dot gnu.org [this message]
2024-02-29 22:46 ` ewlu at rivosinc dot com
2024-02-29 23:33 ` palmer at gcc dot gnu.org
2024-02-29 23:58 ` palmer at gcc dot gnu.org
2024-03-11 23:32 ` ewlu at rivosinc dot com
2024-03-13  2:30 ` xry111 at gcc dot gnu.org
2024-03-13  2:32 ` sjames at gcc dot gnu.org
2024-03-13  2:34 ` xry111 at gcc dot gnu.org
2024-03-15 21:46 ` sjames at gcc dot gnu.org
2024-03-15 23:10 ` jakub at gcc dot gnu.org
2024-03-16 14:17 ` cvs-commit at gcc dot gnu.org
2024-03-17 10:54 ` xry111 at gcc dot gnu.org
2024-03-18 10:16 ` [Bug target/114175] [13/14] Execution test failures on gcc.dg/c23-stdarg-6.c on multiple targets jakub at gcc dot gnu.org
2024-03-18 10:18 ` xry111 at gcc dot gnu.org
2024-03-18 10:54 ` jakub at gcc dot gnu.org
2024-03-18 11:37 ` jakub at gcc dot gnu.org
2024-03-18 12:16 ` jakub at gcc dot gnu.org
2024-03-18 18:56 ` ewlu at rivosinc dot com
2024-03-19  8:15 ` cvs-commit at gcc dot gnu.org
2024-03-19  8:15 ` cvs-commit at gcc dot gnu.org
2024-03-19  8:38 ` cvs-commit at gcc dot gnu.org
2024-03-19  8:45 ` xry111 at gcc dot gnu.org
2024-03-19  8:51 ` cvs-commit at gcc dot gnu.org
2024-03-19  8:53 ` jakub at gcc dot gnu.org
2024-03-19 16:56 ` cvs-commit at gcc dot gnu.org
2024-03-20  7:13 ` xry111 at gcc dot gnu.org
2024-03-20 16:01 ` cvs-commit at gcc dot gnu.org
2024-03-20 16:01 ` cvs-commit at gcc dot gnu.org
2024-03-20 16:01 ` cvs-commit at gcc dot gnu.org
2024-03-20 16:01 ` cvs-commit at gcc dot gnu.org
2024-03-20 16:02 ` cvs-commit at gcc dot gnu.org
2024-03-20 16:02 ` cvs-commit at gcc dot gnu.org
2024-03-20 16:02 ` cvs-commit at gcc dot gnu.org
2024-03-30  2:14 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:54 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:54 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:54 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:54 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:54 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:54 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:54 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:55 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:55 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:55 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:55 ` cvs-commit at gcc dot gnu.org
2024-03-30  5:49 ` cvs-commit at gcc dot gnu.org
2024-03-30  5:49 ` cvs-commit at gcc dot gnu.org
2024-04-04 16:26 ` cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114175-4-VcbFLuNDW5@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).