[clang] Implement [[msvc::no_unique_address]] (PR #65675)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 12 12:24:28 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.
+ BaseSubobjectInfo *Info;
+
+ if (IsVirtual) {
+ // Check if we already have info about this virtual base.
+ BaseSubobjectInfo *&InfoSlot = VirtualBaseInfo[RD];
+ if (InfoSlot) {
+ assert(InfoSlot->Class == RD && "Wrong class for virtual base info!");
+ return InfoSlot;
+ }
+
+ // We don't, create it.
+ InfoSlot = new (BaseSubobjectInfoAllocator.Allocate()) BaseSubobjectInfo;
+ Info = InfoSlot;
+ } else {
+ Info = new (BaseSubobjectInfoAllocator.Allocate()) BaseSubobjectInfo;
+ }
+
+ Info->Class = RD;
+ Info->IsVirtual = IsVirtual;
+ Info->Derived = nullptr;
+ Info->PrimaryVirtualBaseInfo = nullptr;
+
+ const CXXRecordDecl *PrimaryVirtualBase = nullptr;
+ BaseSubobjectInfo *PrimaryVirtualBaseInfo = nullptr;
+
+ // Check if this base has a primary virtual base.
----------------
efriedma-quic wrote:
Are primary virtual bases actually an thing in the MSVC ABI? It seems like PrimaryVirtualBase and PrimaryVirtualBaseInfo aren't actually used anywhere.
https://github.com/llvm/llvm-project/pull/65675
More information about the cfe-commits
mailing list