[clang] Add clang::preferred_type attribute for bitfields (#69104)
This attribute allows user to specify type of the bitfield that will be emitted to debug info without affecting semantics of the program. Since it doesn't affect semantics, this attribute can be safely ignored by other compilers. This is useful when user is forced to use the same type for all bitfields in a class to get better [layout](https://godbolt.org/z/ovWqzqv9x) and [codegen](https://godbolt.org/z/bdoqvz9e6) from MSVC, because it allows debuggers to interpret the value of bitfield in the most human-friendly way (e.g. when value actually comes from an enum). This is driven by my work on LLDB formatters for Clang. I have two use cases for this: ```cpp namespace Clang { class Type { enum TypeClass { ... }; struct TypeBitfields { [[clang::preferred_type(clang::Type::TypeClass)]] unsigned TC: 8; [[clang::preferred_type(bool)]] mutable unsigned FromAST : 1; }; }; } ```
parent
2973febe
Please register or sign in to comment