Hi! For MIPS_SI_FTYPE_VOID and MIPS_USI_FTYPE_VOID which are meant for functions which return (SImode) int or unsigned int and have (void) arguments the MIPS backend creates those using case MIPS_SI_FTYPE_VOID: types[(int) type] = build_function_type_list (intSI_type_node, void_type_node, NULL_TREE); break; case MIPS_USI_FTYPE_VOID: types[(int) type] = build_function_type_list (unsigned_intSI_type_node, void_type_node, NULL_TREE); break; That is wrong, because functions which don't take any arguments (i.e. (void) or C23/C++ ()) should be using void_list_node as TYPE_ARG_TYPES, not a TREE_LIST with void_type_node TREE_VALUE and TREE_CHAIN being that void_list_node. Although void_list_node also has TREE_VALUE of void_type_node, various places in the C++ FE as well as in the middle-end rely on void_list_node to be unique, compare it using pointer comparison. The following testcase strangely happens to compile fine when compiled in C, but fails in C++ (which reports wrong number of arguments due to this bug).
The following simple patch just arranges those 0 argument functions to have the MIPS_*_FTYPE_VOID enumerators be named as before, but in the build_function_type_list call omit that ", void_type_node" part, so it creates correct 0 arguments FUNCTION_TYPE. Tested using cross from x86_64-linux to mips, I don't have a setup to test this further. Ok for trunk/16.2? 2026-07-30 Jakub Jelinek <[email protected]> PR target/126484 * config/mips/mips-ftypes.def (MIPS_SI_FTYPE_VOID, MIPS_USI_FTYPE_VOID): Use DEF_MIPS_FTYPE with 0 as first argument rather than 1 and leave out ", VOID" from second argument. * config/mips/mips.cc (MIPS_FTYPE_NAME0): Define. (MIPS_FTYPE_ATYPES0): Define. * g++.target/mips/pr126484.C: New test. --- gcc/config/mips/mips-ftypes.def.jj 2026-07-29 23:02:55.847962234 +0200 +++ gcc/config/mips/mips-ftypes.def 2026-07-30 14:57:37.157545562 +0200 @@ -75,7 +75,7 @@ DEF_MIPS_FTYPE (1, (SI, V4QI)) DEF_MIPS_FTYPE (2, (SI, V4QI, V4QI)) DEF_MIPS_FTYPE (2, (SI, V4SI, UQI)) DEF_MIPS_FTYPE (2, (SI, V8HI, UQI)) -DEF_MIPS_FTYPE (1, (SI, VOID)) +DEF_MIPS_FTYPE (0, (SI)) DEF_MIPS_FTYPE (2, (UDI, UDI, UDI)) DEF_MIPS_FTYPE (2, (UDI, UV2SI, UV2SI)) @@ -84,7 +84,7 @@ DEF_MIPS_FTYPE (2, (UDI, V2DI, UQI)) DEF_MIPS_FTYPE (2, (USI, V16QI, UQI)) DEF_MIPS_FTYPE (2, (USI, V4SI, UQI)) DEF_MIPS_FTYPE (2, (USI, V8HI, UQI)) -DEF_MIPS_FTYPE (1, (USI, VOID)) +DEF_MIPS_FTYPE (0, (USI)) DEF_MIPS_FTYPE (2, (UV16QI, UV16QI, UQI)) DEF_MIPS_FTYPE (2, (UV16QI, UV16QI, UV16QI)) --- gcc/config/mips/mips.cc.jj 2026-07-29 23:02:55.856962123 +0200 +++ gcc/config/mips/mips.cc 2026-07-30 14:59:58.251806304 +0200 @@ -211,6 +211,7 @@ enum mips_ucbranch_type }; /* Macros to create an enumeration identifier for a function prototype. */ +#define MIPS_FTYPE_NAME0(A) MIPS_##A##_FTYPE_VOID #define MIPS_FTYPE_NAME1(A, B) MIPS_##A##_FTYPE_##B #define MIPS_FTYPE_NAME2(A, B, C) MIPS_##A##_FTYPE_##B##_##C #define MIPS_FTYPE_NAME3(A, B, C, D) MIPS_##A##_FTYPE_##B##_##C##_##D @@ -17137,6 +17138,9 @@ mips_build_cvpointer_type (void) /* MIPS_FTYPE_ATYPESN takes N MIPS_FTYPES-like type codes and lists their associated MIPS_ATYPEs. */ +#define MIPS_FTYPE_ATYPES0(A) \ + MIPS_ATYPE_##A + #define MIPS_FTYPE_ATYPES1(A, B) \ MIPS_ATYPE_##A, MIPS_ATYPE_##B --- gcc/testsuite/g++.target/mips/pr126484.C.jj 2026-07-30 15:03:43.880003854 +0200 +++ gcc/testsuite/g++.target/mips/pr126484.C 2026-07-30 15:04:04.168751854 +0200 @@ -0,0 +1,8 @@ +// PR target/126484 +// { dg-do compile } + +int +foo () +{ + return __builtin_mips_get_fcsr (); +} Jakub
