[clang] Add an off-by-default warning to complain about MSVC bitfield padding (PR #117428)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 11 15:30:06 PDT 2025
================
@@ -633,6 +633,52 @@ def Packed : DiagGroup<"packed", [PackedNonPod]>;
def PaddedBitField : DiagGroup<"padded-bitfield">;
def Padded : DiagGroup<"padded", [PaddedBitField]>;
def UnalignedAccess : DiagGroup<"unaligned-access">;
+def MSBitfieldCompatibility : DiagGroup<"ms-bitfield-compatibility"> {
+ code Documentation = [{
+ Under the MS Windows platform ABI, adjacent bit-fields are not packed if the
+ underlying type has a different storage size. This warning indicates that a
+ pair of adjacent bit-fields may not pack in the same way due to this behavioural
+ difference.
+
+ This can occur when mixing different types explicitly:
+
+ .. code-block:: c++
+
+ struct S {
+ uint16_t field1 : 1;
+ uint32_t field2 : 1;
+ };
+
+ or more subtly through enums
+
+ .. code-block:: c++
+
+ enum Enum1 { /* ... */ };
+ enum class Enum2 : unsigned char { /* ... */ };
+ struct S {
+ Enum1 field1 : 1;
+ Enum2 field2 : 1;
+ };
+
+ In each of these cases under the MS Windows platform ABI the second bit-field
----------------
ojhunt wrote:
Fixed
https://github.com/llvm/llvm-project/pull/117428
More information about the cfe-commits
mailing list