Hi! As mentioned in the PR, right now on powerpc* __SIZEOF_{FLOAT,IBM}128__ macros are predefined unconditionally, because {ieee,ibm}128_float_type_node is always non-NULL, doesn't reflect whether __ieee128 or __ibm128 are actually supported or not.
The following patch: 1) makes those {ieee,ibm}128_float_type_node trees NULL if we don't really support them instead of equal to long_double_type_node 2) adjusts the builtins code to use ibm128_float_type_node ? ibm128_float_type_node : long_double_type_node for the 2 builtins, so that we don't ICE during builtins creation if ibm128_float_type_node is NULL (using error_mark_node instead of long_double_type_node sounds more risky to me) 3) in rs6000_type_string will not match NULL as __ibm128, and adds a __ieee128 case 4) removes the clearly unused ptr_{ieee,ibm}128_float_type_node trees; if something needs them in the future, they can be easily added back, but wasting GTY just in case... 5) actually syncs __SIZEOF_FLOAT128__ with the __float128 macro being defined in addition to __ieee128 being usable Now, in the PR Segher said he doesn't like 5), but I think it is better to match the reality and get this PR fixed and if we want to rethink how __float128 is defined (whether it is a macro, or perhaps another builtin type like __ieee128 which could be easily done by lang_hooks.types.register_builtin_type (ieee128_float_type_node, "__ieee128"); lang_hooks.types.register_builtin_type (ieee128_float_type_node, "__float128"); perhaps under some conditions, rethink if the -mfloat128 option exists and what it does etc., it can be done incrementally and the rs6000-c.cc hunks in the patch can be easily reverted (appart from the formatting fix). Bootstrapped/regtested on powerpc{64le,64}-linux, on powerpc64-linux with -m32/-m64 testing, ok for trunk? 2022-03-05 Jakub Jelinek <ja...@redhat.com> PR target/99708 * config/rs6000/rs6000.h (enum rs6000_builtin_type_index): Remove RS6000_BTI_ptr_ieee128_float and RS6000_BTI_ptr_ibm128_float. (ptr_ieee128_float_type_node, ptr_ibm128_float_type_node): Remove. * config/rs6000/rs6000-builtin.cc (rs6000_type_string): Return "unknown" if type_node is NULL first. Handle ieee128_float_type_node. (rs6000_init_builtins): Don't initialize ptr_ieee128_float_type_node and ptr_ibm128_float_type_node. Set ibm128_float_type_node and ieee128_float_type_node to NULL rather than long_double_type_node if they aren't supported. * config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): Define __SIZEOF_FLOAT128__ here and only if __float128 macro is defined. (rs6000_cpu_cpp_builtins): Don't define __SIZEOF_FLOAT128__ here. Formatting fix. * config/rs6000/rs6000-gen-builtins.cc (TYPE_MAP_SIZE): Set to 85 instead of 86. (type_map): For "if" use ibm128_float_type_node only if it is non-NULL, otherwise fall back to long_double_type_node. Remove "pif" entry. * gcc.dg/pr99708.c: New test. * gcc.target/powerpc/pr99708-2.c: New test. --- gcc/config/rs6000/rs6000.h.jj 2022-02-04 14:36:54.546611710 +0100 +++ gcc/config/rs6000/rs6000.h 2022-03-04 16:45:59.962329746 +0100 @@ -2444,8 +2444,6 @@ enum rs6000_builtin_type_index RS6000_BTI_ptr_long_double, RS6000_BTI_ptr_dfloat64, RS6000_BTI_ptr_dfloat128, - RS6000_BTI_ptr_ieee128_float, - RS6000_BTI_ptr_ibm128_float, RS6000_BTI_ptr_vector_pair, RS6000_BTI_ptr_vector_quad, RS6000_BTI_ptr_long_long, @@ -2541,8 +2539,6 @@ enum rs6000_builtin_type_index #define ptr_long_double_type_node (rs6000_builtin_types[RS6000_BTI_ptr_long_double]) #define ptr_dfloat64_type_node (rs6000_builtin_types[RS6000_BTI_ptr_dfloat64]) #define ptr_dfloat128_type_node (rs6000_builtin_types[RS6000_BTI_ptr_dfloat128]) -#define ptr_ieee128_float_type_node (rs6000_builtin_types[RS6000_BTI_ptr_ieee128_float]) -#define ptr_ibm128_float_type_node (rs6000_builtin_types[RS6000_BTI_ptr_ibm128_float]) #define ptr_vector_pair_type_node (rs6000_builtin_types[RS6000_BTI_ptr_vector_pair]) #define ptr_vector_quad_type_node (rs6000_builtin_types[RS6000_BTI_ptr_vector_quad]) #define ptr_long_long_integer_type_node (rs6000_builtin_types[RS6000_BTI_ptr_long_long]) --- gcc/config/rs6000/rs6000-builtin.cc.jj 2022-02-04 14:36:54.499612366 +0100 +++ gcc/config/rs6000/rs6000-builtin.cc 2022-03-04 16:46:07.978218984 +0100 @@ -402,7 +402,9 @@ rs6000_vector_type (const char *name, tr static const char *rs6000_type_string (tree type_node) { - if (type_node == void_type_node) + if (type_node == NULL_TREE) + return "unknown"; + else if (type_node == void_type_node) return "void"; else if (type_node == long_integer_type_node) return "long"; @@ -432,6 +434,8 @@ const char *rs6000_type_string (tree typ return "ss"; else if (type_node == ibm128_float_type_node) return "__ibm128"; + else if (type_node == ieee128_float_type_node) + return "__ieee128"; else if (type_node == opaque_V4SI_type_node) return "opaque"; else if (POINTER_TYPE_P (type_node)) @@ -721,7 +725,6 @@ rs6000_init_builtins (void) layout_type (ibm128_float_type_node); } t = build_qualified_type (ibm128_float_type_node, TYPE_QUAL_CONST); - ptr_ibm128_float_type_node = build_pointer_type (t); lang_hooks.types.register_builtin_type (ibm128_float_type_node, "__ibm128"); @@ -730,13 +733,11 @@ rs6000_init_builtins (void) else ieee128_float_type_node = float128_type_node; t = build_qualified_type (ieee128_float_type_node, TYPE_QUAL_CONST); - ptr_ieee128_float_type_node = build_pointer_type (t); lang_hooks.types.register_builtin_type (ieee128_float_type_node, "__ieee128"); } - else - ieee128_float_type_node = ibm128_float_type_node = long_double_type_node; + ieee128_float_type_node = ibm128_float_type_node = NULL_TREE; /* Vector pair and vector quad support. */ vector_pair_type_node = make_node (OPAQUE_TYPE); --- gcc/config/rs6000/rs6000-c.cc.jj 2022-03-03 22:09:11.987942537 +0100 +++ gcc/config/rs6000/rs6000-c.cc 2022-03-04 16:22:50.616681130 +0100 @@ -584,6 +584,10 @@ rs6000_target_modify_macros (bool define rs6000_define_or_undefine_macro (true, "__float128=__ieee128"); else rs6000_define_or_undefine_macro (false, "__float128"); + if (ieee128_float_type_node && define_p) + rs6000_define_or_undefine_macro (true, "__SIZEOF_FLOAT128__=16"); + else + rs6000_define_or_undefine_macro (false, "__SIZEOF_FLOAT128__"); } /* OPTION_MASK_FLOAT128_HARDWARE can be turned on if -mcpu=power9 is used or via the target attribute/pragma. */ @@ -623,11 +627,9 @@ rs6000_cpu_cpp_builtins (cpp_reader *pfi if (TARGET_FRSQRTES) builtin_define ("__RSQRTEF__"); if (TARGET_FLOAT128_TYPE) - builtin_define ("__FLOAT128_TYPE__"); + builtin_define ("__FLOAT128_TYPE__"); if (ibm128_float_type_node) builtin_define ("__SIZEOF_IBM128__=16"); - if (ieee128_float_type_node) - builtin_define ("__SIZEOF_FLOAT128__=16"); #ifdef TARGET_LIBC_PROVIDES_HWCAP_IN_TCB builtin_define ("__BUILTIN_CPU_SUPPORTS__"); #endif --- gcc/config/rs6000/rs6000-gen-builtins.cc.jj 2022-02-04 14:36:54.515612143 +0100 +++ gcc/config/rs6000/rs6000-gen-builtins.cc 2022-03-04 16:45:50.454461123 +0100 @@ -492,7 +492,7 @@ struct typemap maps tokens from a fntype string to a tree type. For example, in "si_ftype_hi" we would map "si" to "intSI_type_node" and map "hi" to "intHI_type_node". */ -#define TYPE_MAP_SIZE 86 +#define TYPE_MAP_SIZE 85 static typemap type_map[TYPE_MAP_SIZE] = { { "bi", "bool_int" }, @@ -506,7 +506,9 @@ static typemap type_map[TYPE_MAP_SIZE] = { "df", "double" }, { "di", "long_long_integer" }, { "hi", "intHI" }, - { "if", "ibm128_float" }, + { "if", "ibm128_float_type_node " + "? ibm128_float_type_node " + ": long_double" }, { "ld", "long_double" }, { "lg", "long_integer" }, { "pbv16qi", "ptr_bool_V16QI" }, @@ -519,7 +521,6 @@ static typemap type_map[TYPE_MAP_SIZE] = { "pdf", "ptr_double" }, { "pdi", "ptr_long_long_integer" }, { "phi", "ptr_intHI" }, - { "pif", "ptr_ibm128_float" }, { "pld", "ptr_long_double" }, { "plg", "ptr_long_integer" }, { "pqi", "ptr_intQI" }, --- gcc/testsuite/gcc.dg/pr99708.c.jj 2022-03-04 18:34:21.603828608 +0100 +++ gcc/testsuite/gcc.dg/pr99708.c 2022-03-04 18:34:30.089709852 +0100 @@ -0,0 +1,7 @@ +/* PR target/99708 */ +/* { dg-do compile } */ + +#ifdef __SIZEOF_FLOAT128__ +__float128 f = 1.0; +#endif +long double l = 1.0; --- gcc/testsuite/gcc.target/powerpc/pr99708-2.c.jj 2022-03-04 18:35:29.393879918 +0100 +++ gcc/testsuite/gcc.target/powerpc/pr99708-2.c 2022-03-04 18:35:43.545681867 +0100 @@ -0,0 +1,7 @@ +/* PR target/99708 */ +/* { dg-do compile } */ + +#ifdef __SIZEOF_IBM128__ +__ibm128 f = 1.0; +#endif +long double l = 1.0; Jakub