[clang] [Clang] Fix oversized bit-field layout on big-endian targets (PR #225494)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 30 10:50:52 PDT 2026


xiongzile wrote:

@vhscampos,

I handled `bool` and `_BitInt` separately.

- For `bool`, I changed the occupied size to `min(declared_bits, type_size)` instead of `min(declared_bits, getIntWidth())`, on both LE and BE.
- For `_BitInt`, I only changed the BE case to protect `min(declared_bits, type_size)`. The LE behavior is unchanged.

There is one concern here: for `bool`, the current LE implementation effectively protects only one bit because `getIntWidth(bool) == 1`. GCC appears to preserve the whole declared bit-field width instead. This may be a historical Clang behavior (or an intentional design difference), and I'm not sure whether changing the LE `bool` behavior should be part of this PR.

For `_BitInt`, the BE change is based on Clang's current CodeGen layout(protect all bits, include sign-extension bit). I'm not sure for LE whether we should also protect more bits or leave it as ``getIntWidth``

The code looks ugly but I don't find a better way to handle it:)


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


More information about the cfe-commits mailing list