llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.53k stars 11.79k forks source link

Defining a literal suffix breaks Clang's breestanding INTxx_C macros #85995

Open nerd4code-git opened 7 months ago

nerd4code-git commented 7 months ago

Clang’s freestanding <stdint.h> uses the __[U]INTxx_C_SUFFIX__ predefines to construct literals in the INTxx_C macros it defines. This requires the -C_SUFFIX__ predefines to be fully expanded; e.g., via

#define __int_c_join(a, b) a ## b
#define __int_c(v, suffix) __int_c_join(v, suffix)
#define __uint_c(v, suffix) __int_c_join(v##U, suffix)

Unfortunately, this means if I

#define L %
#define UL %
#define LL %
#define ULL %

the INTxx_C macro will attempt to token-paste % onto the literal.

Ideally the user should be able to define unprefixed one-to-three-letter macro names without breaking core functionality. My suggestion would be to do what GCC does, and define pre-fabricated __INTxx_C macros instead or in addition to the lone suffix macros, and then you could paste without preexpansion.

shafik commented 7 months ago

CC @AaronBallman

frederick-vs-ja commented 2 months ago

Can/should we use the #pragma push_macro/#pragma pop_macro extension to make the current approach bug-free?

AaronBallman commented 2 months ago

Can/should we use the #pragma push_macro/#pragma pop_macro extension to make the current approach bug-free?

We could, but I think it's probably better to change the way we expose the macros to be more resilient instead.