[clang] Implement [[msvc::no_unique_address]] (PR #65675)
Amy Huang via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 12 10:40:19 PDT 2023
================
@@ -2937,14 +2964,97 @@ void MicrosoftRecordLayoutBuilder::layoutNonVirtualBase(
BaseOffset = CharUnits::Zero();
} else {
// Otherwise, lay the base out at the end of the MDC.
- BaseOffset = Size = Size.alignTo(Info.Alignment);
+ BaseOffset = DataSize = Size = Size.alignTo(Info.Alignment);
}
+
+ // Place in EmptySubobjects map but don't check the position? MSVC seems to
+ // not allow fields to overlap at the end of a virtual base, but they can
+ // overlap with other bass.
+ EmptySubobjects->CanPlaceBaseAtOffset(Base, BaseOffset);
}
+
Bases.insert(std::make_pair(BaseDecl, BaseOffset));
Size += BaseLayout.getNonVirtualSize();
+ DataSize = Size;
PreviousBaseLayout = &BaseLayout;
}
+BaseSubobjectInfo *MicrosoftRecordLayoutBuilder::computeBaseSubobjectInfo(
+ const CXXRecordDecl *RD, bool IsVirtual, BaseSubobjectInfo *Derived) {
+ // This is copied directly from ItaniumRecordLayoutBuilder::ComputeBaseSubobjectInfo.
----------------
amykhuang wrote:
Actually going to remove this altogether. Makes it less consistent with MSVC's behavior but MSVC appears to avoid overlapping fields with bases only when no_unique_address is used, which seems weird.
https://github.com/llvm/llvm-project/pull/65675
More information about the cfe-commits
mailing list