Index: clang/lib/AST/RecordLayoutBuilder.cpp =================================================================== --- clang/lib/AST/RecordLayoutBuilder.cpp +++ clang/lib/AST/RecordLayoutBuilder.cpp @@ -2923,12 +2923,17 @@ ElementInfo Info = getAdjustedElementInfo(FD); Alignment = std::max(Alignment, Info.Alignment); CharUnits FieldOffset; + auto *FieldClass = FD->getType()->getAsCXXRecordDecl(); + bool PotentiallyOverlapping = + FD->hasAttr() && FieldClass; + bool IsOverlappingEmptyField = + PotentiallyOverlapping && FieldClass->isEmpty(); if (UseExternalLayout) FieldOffset = Context.toCharUnitsFromBits(External.getExternalFieldOffset(FD)); - else if (IsUnion) + else if (IsUnion || IsOverlappingEmptyField) { FieldOffset = CharUnits::Zero(); - else + } else FieldOffset = Size.alignTo(Info.Alignment); placeFieldAtOffset(FieldOffset); Size = std::max(Size, FieldOffset + Info.Size);