[clang] [Clang] Emit TBAA info for enums in C (PR #73326)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 5 06:31:11 PST 2023


AaronBallman wrote:

> enums should be treated as 'int' types unless explicitly specified (C23) or if 'int' would not be large enough to hold all the enumerated values. In the latter case the compiler is free to choose a suitable integer that would hold all such values.

In C23, the enumeration type is compatible with its underlying type, which is either `char` or a standard or extended signed or unsigned integer type (C23 6.7.2.2p2). The enumeration member type (C23 6.7.2.2p11) is specified by p12 (when building the enumeration itself) and p15 and p16 (once the enumeration is complete). If there's no fixed underlying type, the members are compatible with either `int` or the enumerated type, and if there is a fixed underlying type, the members type is the enumerated type. Much of this is implementation-defined behavior. It sounds like our implementation was assuming compatibility with `char` and not `int` because of the aliasing behavior, and now you'd like to change it to be `int` so we don't have the aliasing problems?

https://github.com/llvm/llvm-project/pull/73326


More information about the cfe-commits mailing list