Oh I missed the -mabi in testcase, v2 patch attached, same as V1 but add -mabi flag to testcase.
On Fri, Jun 19, 2020 at 3:08 PM Kito Cheng <kito.ch...@sifive.com> wrote: > > - g++ will complain too few arguments for frflags builtin like bellow > message: > > error: too few arguments to function 'unsigned int > __builtin_riscv_frflags(void)' > > - However it's no arguments needed, it because we declare the function > type with VOID arguments, that seems like require a VOID argument > in the c++ front-end when GCC tried to resolve the function. > > gcc/ChangeLog > > * config/riscv/riscv-builtins.c (RISCV_FTYPE_NAME0): New. > (RISCV_FTYPE_ATYPES0): New. > (riscv_builtins): Using RISCV_USI_FTYPE for frflags. > * config/riscv/riscv-ftypes.def: Remove VOID argument. > > gcc/testsuite/ChangeLog > > * g++.target/riscv/frflags.C: New. > --- > gcc/config/riscv/riscv-builtins.c | 5 ++++- > gcc/config/riscv/riscv-ftypes.def | 2 +- > gcc/testsuite/g++.target/riscv/frflags.C | 7 +++++++ > 3 files changed, 12 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/g++.target/riscv/frflags.C > > diff --git a/gcc/config/riscv/riscv-builtins.c > b/gcc/config/riscv/riscv-builtins.c > index a45108e03557..bc959389c76c 100644 > --- a/gcc/config/riscv/riscv-builtins.c > +++ b/gcc/config/riscv/riscv-builtins.c > @@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see > #include "langhooks.h" > > /* Macros to create an enumeration identifier for a function prototype. */ > +#define RISCV_FTYPE_NAME0(A) RISCV_##A##_FTYPE > #define RISCV_FTYPE_NAME1(A, B) RISCV_##A##_FTYPE_##B > > /* Classifies the prototype of a built-in function. */ > @@ -121,11 +122,13 @@ AVAIL (hard_float, TARGET_HARD_FLOAT) > > /* RISCV_FTYPE_ATYPESN takes N RISCV_FTYPES-like type codes and lists > their associated RISCV_ATYPEs. */ > +#define RISCV_FTYPE_ATYPES0(A) \ > + RISCV_ATYPE_##A > #define RISCV_FTYPE_ATYPES1(A, B) \ > RISCV_ATYPE_##A, RISCV_ATYPE_##B > > static const struct riscv_builtin_description riscv_builtins[] = { > - DIRECT_BUILTIN (frflags, RISCV_USI_FTYPE_VOID, hard_float), > + DIRECT_BUILTIN (frflags, RISCV_USI_FTYPE, hard_float), > DIRECT_NO_TARGET_BUILTIN (fsflags, RISCV_VOID_FTYPE_USI, hard_float) > }; > > diff --git a/gcc/config/riscv/riscv-ftypes.def > b/gcc/config/riscv/riscv-ftypes.def > index 5edeb481a72d..1c6bc4e9dce1 100644 > --- a/gcc/config/riscv/riscv-ftypes.def > +++ b/gcc/config/riscv/riscv-ftypes.def > @@ -26,5 +26,5 @@ along with GCC; see the file COPYING3. If not see > LIST contains the return-type code followed by the codes for each > argument type. */ > > -DEF_RISCV_FTYPE (1, (USI, VOID)) > +DEF_RISCV_FTYPE (0, (USI)) > DEF_RISCV_FTYPE (1, (VOID, USI)) > diff --git a/gcc/testsuite/g++.target/riscv/frflags.C > b/gcc/testsuite/g++.target/riscv/frflags.C > new file mode 100644 > index 000000000000..be0bd4db01c3 > --- /dev/null > +++ b/gcc/testsuite/g++.target/riscv/frflags.C > @@ -0,0 +1,7 @@ > +/* { dg-options "-O2 -march=rv32if" } */ > +/* { dg-do compile } */ > + > +int f() > +{ > + return __builtin_riscv_frflags(); > +} > -- > 2.27.0 >
From 6a84ffed89eb8c2a42ccbc29b93df996d0e5d6c9 Mon Sep 17 00:00:00 2001 From: Kito Cheng <kito.ch...@sifive.com> Date: Fri, 19 Jun 2020 14:07:39 +0800 Subject: [PATCH] RISC-V: Fix compilation failed for frflags builtin in C++ mode - g++ will complain too few arguments for frflags builtin like bellow message: error: too few arguments to function 'unsigned int __builtin_riscv_frflags(void)' - However it's no arguments needed, it because we declare the function type with VOID arguments, that seems like require a VOID argument in the c++ front-end when GCC tried to resolve the function. gcc/ChangeLog * config/riscv/riscv-builtins.c (RISCV_FTYPE_NAME0): New. (RISCV_FTYPE_ATYPES0): New. (riscv_builtins): Using RISCV_USI_FTYPE for frflags. * config/riscv/riscv-ftypes.def: Remove VOID argument. gcc/testsuite/ChangeLog * g++.target/riscv/frflags.C: New. --- gcc/config/riscv/riscv-builtins.c | 5 ++++- gcc/config/riscv/riscv-ftypes.def | 2 +- gcc/testsuite/g++.target/riscv/frflags.C | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.target/riscv/frflags.C diff --git a/gcc/config/riscv/riscv-builtins.c b/gcc/config/riscv/riscv-builtins.c index a45108e03557..bc959389c76c 100644 --- a/gcc/config/riscv/riscv-builtins.c +++ b/gcc/config/riscv/riscv-builtins.c @@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" /* Macros to create an enumeration identifier for a function prototype. */ +#define RISCV_FTYPE_NAME0(A) RISCV_##A##_FTYPE #define RISCV_FTYPE_NAME1(A, B) RISCV_##A##_FTYPE_##B /* Classifies the prototype of a built-in function. */ @@ -121,11 +122,13 @@ AVAIL (hard_float, TARGET_HARD_FLOAT) /* RISCV_FTYPE_ATYPESN takes N RISCV_FTYPES-like type codes and lists their associated RISCV_ATYPEs. */ +#define RISCV_FTYPE_ATYPES0(A) \ + RISCV_ATYPE_##A #define RISCV_FTYPE_ATYPES1(A, B) \ RISCV_ATYPE_##A, RISCV_ATYPE_##B static const struct riscv_builtin_description riscv_builtins[] = { - DIRECT_BUILTIN (frflags, RISCV_USI_FTYPE_VOID, hard_float), + DIRECT_BUILTIN (frflags, RISCV_USI_FTYPE, hard_float), DIRECT_NO_TARGET_BUILTIN (fsflags, RISCV_VOID_FTYPE_USI, hard_float) }; diff --git a/gcc/config/riscv/riscv-ftypes.def b/gcc/config/riscv/riscv-ftypes.def index 5edeb481a72d..1c6bc4e9dce1 100644 --- a/gcc/config/riscv/riscv-ftypes.def +++ b/gcc/config/riscv/riscv-ftypes.def @@ -26,5 +26,5 @@ along with GCC; see the file COPYING3. If not see LIST contains the return-type code followed by the codes for each argument type. */ -DEF_RISCV_FTYPE (1, (USI, VOID)) +DEF_RISCV_FTYPE (0, (USI)) DEF_RISCV_FTYPE (1, (VOID, USI)) diff --git a/gcc/testsuite/g++.target/riscv/frflags.C b/gcc/testsuite/g++.target/riscv/frflags.C new file mode 100644 index 000000000000..6353044dcf71 --- /dev/null +++ b/gcc/testsuite/g++.target/riscv/frflags.C @@ -0,0 +1,7 @@ +/* { dg-options "-O2 -march=rv32if -mabi=ilp32f" } */ +/* { dg-do compile } */ + +int f() +{ + return __builtin_riscv_frflags(); +} -- 2.27.0