[clang] Add an off-by-default warning to complain about MSVC bitfield padding (PR #117428)
Martin Storsjö via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 3 00:43:14 PST 2024
================
@@ -6418,6 +6418,12 @@ def warn_signed_bitfield_enum_conversion : Warning<
InGroup<BitFieldEnumConversion>, DefaultIgnore;
def note_change_bitfield_sign : Note<
"consider making the bitfield type %select{unsigned|signed}0">;
+def warn_ms_bitfield_mismatched_storage_packing : Warning<
+ "bit-field %0 of type %1 has a different storage size (%2 vs %3 bytes) than the "
+ "preceding bit-field and may not be packed under MSVC ABI">,
+ InGroup<MSBitfieldCompatibility>, DefaultIgnore;
----------------
mstorsjo wrote:
Yes; mingw also uses the MS bitfield packing logic. (Originally, for mingw targets, users would need to opt in to this with `-mms-bitfields`; GCC enabled this option by default for mingw targets in 4.7 and we followed suit a bit belatedly in Clang 11 - see e3fd9dc9734c5775dc6824d0a839702e8d43e7f6.)
As for whether this should be enabled by deault; I think it's entirely up to each individual project whether they want it as an early portability headsup that they're writing code which is behaving differently on Windows or not. People writing windows-exclusive code might not care, and they may want to intentionally keep their structs as they are to match some existing ABI.
https://github.com/llvm/llvm-project/pull/117428
More information about the cfe-commits
mailing list