[gcc r10-8446] RISC-V: Fix compilation failed for frflags builtin in C++ mode

Kito Cheng kito@gcc.gnu.org
Thu Jul 9 07:25:24 GMT 2020


https://gcc.gnu.org/g:130c3827e509b7986cce8727581ecab5f6d1f614

commit r10-8446-g130c3827e509b7986cce8727581ecab5f6d1f614
Author: Kito Cheng <kito.cheng@sifive.com>
Date:   Fri Jun 19 14:07:39 2020 +0800

    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.
    
    (cherry picked from commit 33d9794b7277a64543914bfbbfd567505e72da6c)

Diff:
---
 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(-)

diff --git a/gcc/config/riscv/riscv-builtins.c b/gcc/config/riscv/riscv-builtins.c
index a45108e0355..bc959389c76 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 5edeb481a72..1c6bc4e9dce 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 00000000000..6353044dcf7
--- /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();
+}


More information about the Gcc-cvs mailing list