https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100854
Bug ID: 100854 Summary: TS 18661-3 and backwards-incompatible setting of __FLT_EVAL_METHOD__ Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: acoplan at gcc dot gnu.org Target Milestone: --- GCC implements TS 18661-3. On arm and aarch64, this means that an -march string that includes fp16 results in GCC defining __FLT_EVAL_METHOD__ to 16. This is backwards-incompatible with libraries conforming to C99 which interpret values other than 0, 1, or 2 as implementation defined. See newlib's use of __FLT_EVAL_METHOD__ in math.h: https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=newlib/libc/include/math.h;h=ba1a8a17ef4368eabb7a0d116f50b6a7d34546ce;hb=HEAD#l144 On AArch64, we define three variants of __FLT_EVAL_METHOD__: $ aarch64-linux-gnu-gcc -xc /dev/null -E -dM | grep FLT_EVAL #define __FLT_EVAL_METHOD__ 0 #define __FLT_EVAL_METHOD_TS_18661_3__ 0 #define __FLT_EVAL_METHOD_C99__ 0 Adding fp16 to the -march, we see that all three of these macros take the value 16: $ aarch64-linux-gnu-gcc -march=armv8.2-a+fp16 -xc /dev/null -E -dM | grep FLT_EVAL #define __FLT_EVAL_METHOD__ 16 #define __FLT_EVAL_METHOD_TS_18661_3__ 16 #define __FLT_EVAL_METHOD_C99__ 16 This is a little surprising. Based on the name of __FLT_EVAL_METHOD_C99__, you might expect it to only take values defined by C99. Forcing -std=c99, we see that __FLT_EVAL_METHOD__ itself takes a C99-conforming value, but the others do not: $ aarch64-linux-gnu-gcc -march=armv8.2-a+fp16 -std=c99 -xc /dev/null -E -dM | grep FLT_EVAL #define __FLT_EVAL_METHOD__ 0 #define __FLT_EVAL_METHOD_TS_18661_3__ 16 #define __FLT_EVAL_METHOD_C99__ 16 It seems that the behaviour of __FLT_EVAL_METHOD_C99__ is the exact opposite of what the name suggests. Notably the __FLT_EVAL_METHOD_C99__ macro is AArch64-specific. It isn't implemented on the arm port: $ ./arm-eabi-gcc -xc /dev/null -E -dM -march=armv8-a+simd | grep FLT_EVAL #define __FLT_EVAL_METHOD__ 0 #define __FLT_EVAL_METHOD_TS_18661_3__ 0 $ ./arm-eabi-gcc -xc /dev/null -E -dM -march=armv8.2-a+fp16 | grep FLT_EVAL #define __FLT_EVAL_METHOD__ 16 #define __FLT_EVAL_METHOD_TS_18661_3__ 16 $ ./arm-eabi-gcc -xc /dev/null -E -dM -march=armv8.2-a+fp16 -std=c99 | grep FLT_EVAL #define __FLT_EVAL_METHOD__ 0 #define __FLT_EVAL_METHOD_TS_18661_3__ 16 It would be useful if GCC provided a portable pre-defined __FLT_EVAL_METHOD__ variant that was guaranteed to only take values defined by C99/C11. As it stands, GCC with -march=armv8.2-a+fp16 (or any -mcpu/-march that implies fp16) on arm and aarch64 fails to compile any file that includes newlib's math.h. This could be considered a bug in TS 18661-3 which stipulates that __FLT_EVAL_METHOD__ take backwards-incompatible values. Either way, it seems that GCC should provide a way to recover a conforming __FLT_EVAL_METHOD__ without forcing the user to compile everything in a strict standards-conforming mode (-std=c{99,11}). At a minimum, the __FLT_EVAL_METHOD_C99__ builtin macro should probably be removed from the AArch64 backend as its current behaviour is entirely unhelpful. Ideally, GCC would define a new macro (portable across all architectures implementing fp16) which is guaranteed to only take values defined by C99/C11.