[clang] Allow packing fields into tail padding of record fields (PR #122197)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 8 16:28:21 PST 2025


================
@@ -389,14 +389,28 @@ void CGRecordLowering::accumulateFields(bool isNonVirtualBaseType) {
       // Empty fields have no storage.
       ++Field;
     } else {
-      // Use base subobject layout for the potentially-overlapping field,
-      // as it is done in RecordLayoutBuilder
-      Members.push_back(MemberInfo(
-          bitsToCharUnits(getFieldBitOffset(*Field)), MemberInfo::Field,
-          Field->isPotentiallyOverlapping()
-              ? getStorageType(Field->getType()->getAsCXXRecordDecl())
-              : getStorageType(*Field),
-          *Field));
+      CharUnits CurOffset = bitsToCharUnits(getFieldBitOffset(*Field));
+      llvm::Type *StorageType = getStorageType(*Field);
+
+      // Detect cases when the next field needs to be packed into tail padding
+      // of a record field. This is typically caused by [[no_unique_address]],
+      // but we try to infer when that is the case rather than checking for the
+      // attribute explicitly because the attribute is typically not present in
+      // debug info. Use the base subobject LLVM struct type in these cases,
----------------
efriedma-quic wrote:

Maybe state more explicitly that this is an issue when the class layout is computed from debug info?

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


More information about the cfe-commits mailing list