================
@@ -15917,13 +15917,17 @@ struct PaddingCalculator {
 
     const uint64_t DeclaredSizeInBits = Field->getBitWidthValue();
 
-    // Handle over-sized bitfields:
-    //   unsigned char a : 12;
-    // In this case, DeclaredSizeInBits is 12, but the actually occupied bit
-    // size is 8, while the remaining 4 bits are padding.
+    // Oversized bit-fields (declared width larger than the field type) occupy
+    // only the type's width. The extra declared bits are padding and follow
+    // the occupied bits (Itanium C++ ABI ยง2.4, II.1(b)).
+    // A bool bit-field occupies its whole declared width up to the size of
+    // bool, like GCC. _BitInt(N) occupies only its N value bits.
+    const QualType FieldTy = Field->getType();
     const uint64_t OccupiedSizeInBits =
----------------
vhscampos wrote:

I think ultimately the comment we'll need now is something along these lines:

In case where the bitfield can only have values with a range smaller than the 
one declared, e.g. bool a : 5 or _BitInt(5) b : 6, the remaining bits within 
the bitfield are for sign or zero extension. These are still considered 
occupied.

https://github.com/llvm/llvm-project/pull/225494
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to