diff mbox series

RISC-V: Fix compilation failed for frflags builtin in C++ mode

Message ID 20200619070801.8462-1-kito.cheng@sifive.com
State New
Headers show
Series RISC-V: Fix compilation failed for frflags builtin in C++ mode | expand

Commit Message

Kito Cheng June 19, 2020, 7:08 a.m. UTC
- 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

Comments

Kito Cheng June 19, 2020, 10:01 a.m. UTC | #1
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.cheng@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
>
Jason Merrill June 19, 2020, 3:59 p.m. UTC | #2
On 6/19/20 3:08 AM, Kito Cheng 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.

Yes, G++ expects a parameter list to end with void_list_node 
specifically, not any TREE_LIST with void_type_node.

> 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.

You should also be able to remove

> #define RISCV_ATYPE_VOID void_type_node

OK with that change.

Jason
Kito Cheng June 22, 2020, 2:49 a.m. UTC | #3
Hi Jason:

Committed, thanks for your review :)

> You should also be able to remove
>
> > #define RISCV_ATYPE_VOID void_type_node

That's still used for builtin functions without return value :)
diff mbox series

Patch

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();
+}