20 #include "llvm/ADT/SmallSet.h"
21 #include "llvm/Support/Format.h"
22 #include "llvm/Support/MathExtras.h"
24 using namespace clang;
39 struct BaseSubobjectInfo {
51 BaseSubobjectInfo *PrimaryVirtualBaseInfo;
54 const BaseSubobjectInfo *Derived;
60 struct ExternalLayout {
61 ExternalLayout() =
default;
70 llvm::DenseMap<const FieldDecl *, uint64_t> FieldOffsets;
73 llvm::DenseMap<const CXXRecordDecl *, CharUnits> BaseOffsets;
76 llvm::DenseMap<const CXXRecordDecl *, CharUnits> VirtualBaseOffsets;
81 assert(FieldOffsets.count(FD) &&
82 "Field does not have an external offset");
83 return FieldOffsets[FD];
87 auto Known = BaseOffsets.find(RD);
88 if (Known == BaseOffsets.end())
90 BaseOffset = Known->second;
95 auto Known = VirtualBaseOffsets.find(RD);
96 if (Known == VirtualBaseOffsets.end())
98 BaseOffset = Known->second;
105 class EmptySubobjectMap {
113 typedef llvm::TinyPtrVector<const CXXRecordDecl *> ClassVectorTy;
114 typedef llvm::DenseMap<CharUnits, ClassVectorTy> EmptyClassOffsetsMapTy;
115 EmptyClassOffsetsMapTy EmptyClassOffsets;
123 void ComputeEmptySubobjectSizes();
127 void UpdateEmptyBaseSubobjects(
const BaseSubobjectInfo *Info,
132 bool PlacingOverlappingField);
134 bool PlacingOverlappingField);
139 return Offset <= MaxEmptyClassOffset;
145 assert(FieldOffset % CharWidth == 0 &&
146 "Field offset not at char boundary!");
155 bool CanPlaceBaseSubobjectAtOffset(
const BaseSubobjectInfo *Info,
161 bool CanPlaceFieldSubobjectAtOffset(
const FieldDecl *FD,
172 ComputeEmptySubobjectSizes();
179 bool CanPlaceBaseAtOffset(
const BaseSubobjectInfo *Info,
187 void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
202 if (EmptySize > SizeOfLargestEmptySubobject)
203 SizeOfLargestEmptySubobject = EmptySize;
226 if (EmptySize > SizeOfLargestEmptySubobject)
227 SizeOfLargestEmptySubobject = EmptySize;
232 EmptySubobjectMap::CanPlaceSubobjectAtOffset(
const CXXRecordDecl *RD,
238 EmptyClassOffsetsMapTy::const_iterator I = EmptyClassOffsets.find(
Offset);
239 if (I == EmptyClassOffsets.end())
242 const ClassVectorTy &Classes = I->second;
243 if (!llvm::is_contained(Classes, RD))
250 void EmptySubobjectMap::AddSubobjectAtOffset(
const CXXRecordDecl *RD,
258 ClassVectorTy &Classes = EmptyClassOffsets[
Offset];
259 if (llvm::is_contained(Classes, RD))
262 Classes.push_back(RD);
265 if (
Offset > MaxEmptyClassOffset)
266 MaxEmptyClassOffset =
Offset;
270 EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(
const BaseSubobjectInfo *Info,
274 if (!AnyEmptySubobjectsBeyondOffset(
Offset))
277 if (!CanPlaceSubobjectAtOffset(Info->Class,
Offset))
282 for (
const BaseSubobjectInfo *
Base : Info->Bases) {
288 if (!CanPlaceBaseSubobjectAtOffset(
Base, BaseOffset))
292 if (Info->PrimaryVirtualBaseInfo) {
293 BaseSubobjectInfo *PrimaryVirtualBaseInfo = Info->PrimaryVirtualBaseInfo;
295 if (Info == PrimaryVirtualBaseInfo->Derived) {
296 if (!CanPlaceBaseSubobjectAtOffset(PrimaryVirtualBaseInfo,
Offset))
302 unsigned FieldNo = 0;
304 E = Info->Class->field_end(); I != E; ++I, ++FieldNo) {
309 if (!CanPlaceFieldSubobjectAtOffset(*I, FieldOffset))
316 void EmptySubobjectMap::UpdateEmptyBaseSubobjects(
const BaseSubobjectInfo *Info,
318 bool PlacingEmptyBase) {
319 if (!PlacingEmptyBase &&
Offset >= SizeOfLargestEmptySubobject) {
328 AddSubobjectAtOffset(Info->Class,
Offset);
332 for (
const BaseSubobjectInfo *
Base : Info->Bases) {
337 UpdateEmptyBaseSubobjects(
Base, BaseOffset, PlacingEmptyBase);
340 if (Info->PrimaryVirtualBaseInfo) {
341 BaseSubobjectInfo *PrimaryVirtualBaseInfo = Info->PrimaryVirtualBaseInfo;
343 if (Info == PrimaryVirtualBaseInfo->Derived)
344 UpdateEmptyBaseSubobjects(PrimaryVirtualBaseInfo,
Offset,
349 unsigned FieldNo = 0;
351 E = Info->Class->field_end(); I != E; ++I, ++FieldNo) {
356 UpdateEmptyFieldSubobjects(*I, FieldOffset, PlacingEmptyBase);
360 bool EmptySubobjectMap::CanPlaceBaseAtOffset(
const BaseSubobjectInfo *Info,
364 if (SizeOfLargestEmptySubobject.isZero())
367 if (!CanPlaceBaseSubobjectAtOffset(Info,
Offset))
372 UpdateEmptyBaseSubobjects(Info,
Offset, Info->Class->isEmpty());
377 EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(
const CXXRecordDecl *RD,
382 if (!AnyEmptySubobjectsBeyondOffset(
Offset))
385 if (!CanPlaceSubobjectAtOffset(RD,
Offset))
392 if (
Base.isVirtual())
398 if (!CanPlaceFieldSubobjectAtOffset(BaseDecl, Class, BaseOffset))
408 if (!CanPlaceFieldSubobjectAtOffset(VBaseDecl, Class, VBaseOffset))
414 unsigned FieldNo = 0;
416 I != E; ++I, ++FieldNo) {
422 if (!CanPlaceFieldSubobjectAtOffset(*I, FieldOffset))
430 EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(
const FieldDecl *FD,
434 if (!AnyEmptySubobjectsBeyondOffset(
Offset))
439 return CanPlaceFieldSubobjectAtOffset(RD, RD,
Offset);
453 for (
uint64_t I = 0; I != NumElements; ++I) {
456 if (!AnyEmptySubobjectsBeyondOffset(ElementOffset))
459 if (!CanPlaceFieldSubobjectAtOffset(RD, RD, ElementOffset))
462 ElementOffset += Layout.
getSize();
470 EmptySubobjectMap::CanPlaceFieldAtOffset(
const FieldDecl *FD,
472 if (!CanPlaceFieldSubobjectAtOffset(FD,
Offset))
477 UpdateEmptyFieldSubobjects(FD,
Offset, FD->
hasAttr<NoUniqueAddressAttr>());
481 void EmptySubobjectMap::UpdateEmptyFieldSubobjects(
483 bool PlacingOverlappingField) {
494 if (!PlacingOverlappingField &&
Offset >= SizeOfLargestEmptySubobject)
497 AddSubobjectAtOffset(RD,
Offset);
503 if (
Base.isVirtual())
509 UpdateEmptyFieldSubobjects(BaseDecl, Class, BaseOffset,
510 PlacingOverlappingField);
519 UpdateEmptyFieldSubobjects(VBaseDecl, Class, VBaseOffset,
520 PlacingOverlappingField);
525 unsigned FieldNo = 0;
527 I != E; ++I, ++FieldNo) {
533 UpdateEmptyFieldSubobjects(*I, FieldOffset, PlacingOverlappingField);
537 void EmptySubobjectMap::UpdateEmptyFieldSubobjects(
541 UpdateEmptyFieldSubobjects(RD, RD,
Offset, PlacingOverlappingField);
558 for (
uint64_t I = 0; I != NumElements; ++I) {
564 if (!PlacingOverlappingField &&
565 ElementOffset >= SizeOfLargestEmptySubobject)
568 UpdateEmptyFieldSubobjects(RD, RD, ElementOffset,
569 PlacingOverlappingField);
570 ElementOffset += Layout.
getSize();
577 class ItaniumRecordLayoutBuilder {
584 EmptySubobjectMap *EmptySubobjects;
605 LLVM_PREFERRED_TYPE(
bool)
606 unsigned UseExternalLayout : 1;
610 LLVM_PREFERRED_TYPE(
bool)
611 unsigned InferAlignment : 1;
614 LLVM_PREFERRED_TYPE(
bool)
617 LLVM_PREFERRED_TYPE(
bool)
618 unsigned IsUnion : 1;
620 LLVM_PREFERRED_TYPE(
bool)
621 unsigned IsMac68kAlign : 1;
623 LLVM_PREFERRED_TYPE(
bool)
624 unsigned IsNaturalAlign : 1;
626 LLVM_PREFERRED_TYPE(
bool)
627 unsigned IsMsStruct : 1;
633 unsigned char UnfilledBitsInLastUnit;
637 unsigned char LastBitfieldStorageUnitSize;
660 bool PrimaryBaseIsVirtual;
673 bool HandledFirstNonOverlappingEmptyField;
675 typedef llvm::DenseMap<const CXXRecordDecl *, CharUnits> BaseOffsetsMapTy;
678 BaseOffsetsMapTy Bases;
698 ItaniumRecordLayoutBuilder(
const ASTContext &Context,
699 EmptySubobjectMap *EmptySubobjects)
700 : Context(Context), EmptySubobjects(EmptySubobjects),
Size(0),
705 IsMac68kAlign(
false),
706 IsNaturalAlign(!Context.
getTargetInfo().getTriple().isOSAIX()),
707 IsMsStruct(
false), UnfilledBitsInLastUnit(0),
708 LastBitfieldStorageUnitSize(0), MaxFieldAlignment(
CharUnits::
Zero()),
713 PrimaryBaseIsVirtual(
false), HasOwnVFPtr(
false), HasPackedField(
false),
714 HandledFirstNonOverlappingEmptyField(
false),
715 FirstNearlyEmptyVBase(nullptr) {}
722 void LayoutField(
const FieldDecl *D,
bool InsertExtraPadding);
732 llvm::SpecificBumpPtrAllocator<BaseSubobjectInfo> BaseSubobjectInfoAllocator;
734 typedef llvm::DenseMap<const CXXRecordDecl *, BaseSubobjectInfo *>
735 BaseSubobjectInfoMapTy;
743 BaseSubobjectInfoMapTy NonVirtualBaseInfo;
751 BaseSubobjectInfo *ComputeBaseSubobjectInfo(
const CXXRecordDecl *RD,
753 BaseSubobjectInfo *Derived);
760 void EnsureVTablePointerAlignment(
CharUnits UnpackedBaseAlign);
767 void LayoutNonVirtualBase(
const BaseSubobjectInfo *
Base);
769 void AddPrimaryVirtualBaseOffsets(
const BaseSubobjectInfo *Info,
777 void LayoutVirtualBase(
const BaseSubobjectInfo *
Base);
784 void InitializeLayout(
const Decl *D);
793 UpdateAlignment(NewAlignment, UnpackedNewAlignment, NewAlignment);
795 void UpdateAlignment(
CharUnits NewAlignment) {
796 UpdateAlignment(NewAlignment, NewAlignment, NewAlignment);
808 uint64_t UnpackedOffset,
unsigned UnpackedAlign,
822 CharUnits getAligment()
const {
return Alignment; }
828 uint64_t getDataSizeInBits()
const {
return DataSize; }
830 void setDataSize(
CharUnits NewSize) { DataSize = Context.
toBits(NewSize); }
831 void setDataSize(
uint64_t NewSize) { DataSize = NewSize; }
833 ItaniumRecordLayoutBuilder(
const ItaniumRecordLayoutBuilder &) =
delete;
834 void operator=(
const ItaniumRecordLayoutBuilder &) =
delete;
838 void ItaniumRecordLayoutBuilder::SelectPrimaryVBase(
const CXXRecordDecl *RD) {
839 for (
const auto &I : RD->
bases()) {
840 assert(!I.getType()->isDependentType() &&
841 "Cannot layout class with dependent bases.");
849 if (!IndirectPrimaryBases.count(
Base)) {
851 PrimaryBaseIsVirtual =
true;
856 if (!FirstNearlyEmptyVBase)
857 FirstNearlyEmptyVBase =
Base;
860 SelectPrimaryVBase(
Base);
867 void ItaniumRecordLayoutBuilder::DeterminePrimaryBase(
const CXXRecordDecl *RD) {
879 for (
const auto &I : RD->
bases()) {
886 if (
Base->isDynamicClass()) {
889 PrimaryBaseIsVirtual =
false;
899 SelectPrimaryVBase(RD);
905 if (FirstNearlyEmptyVBase) {
906 PrimaryBase = FirstNearlyEmptyVBase;
907 PrimaryBaseIsVirtual =
true;
911 assert(!PrimaryBase &&
"Should not get here with a primary base!");
914 BaseSubobjectInfo *ItaniumRecordLayoutBuilder::ComputeBaseSubobjectInfo(
915 const CXXRecordDecl *RD,
bool IsVirtual, BaseSubobjectInfo *Derived) {
916 BaseSubobjectInfo *Info;
922 assert(InfoSlot->Class == RD &&
"Wrong class for virtual base info!");
927 InfoSlot =
new (BaseSubobjectInfoAllocator.Allocate()) BaseSubobjectInfo;
930 Info =
new (BaseSubobjectInfoAllocator.Allocate()) BaseSubobjectInfo;
934 Info->IsVirtual = IsVirtual;
935 Info->Derived =
nullptr;
936 Info->PrimaryVirtualBaseInfo =
nullptr;
939 BaseSubobjectInfo *PrimaryVirtualBaseInfo =
nullptr;
947 assert(PrimaryVirtualBase &&
"Didn't have a primary virtual base!");
952 if (PrimaryVirtualBaseInfo) {
953 if (PrimaryVirtualBaseInfo->Derived) {
957 PrimaryVirtualBase =
nullptr;
960 Info->PrimaryVirtualBaseInfo = PrimaryVirtualBaseInfo;
961 PrimaryVirtualBaseInfo->Derived = Info;
968 for (
const auto &I : RD->
bases()) {
969 bool IsVirtual = I.isVirtual();
971 const CXXRecordDecl *BaseDecl = I.getType()->getAsCXXRecordDecl();
973 Info->Bases.push_back(ComputeBaseSubobjectInfo(BaseDecl, IsVirtual, Info));
976 if (PrimaryVirtualBase && !PrimaryVirtualBaseInfo) {
980 assert(PrimaryVirtualBaseInfo &&
981 "Did not create a primary virtual base!");
984 Info->PrimaryVirtualBaseInfo = PrimaryVirtualBaseInfo;
985 PrimaryVirtualBaseInfo->Derived = Info;
991 void ItaniumRecordLayoutBuilder::ComputeBaseSubobjectInfo(
993 for (
const auto &I : RD->
bases()) {
994 bool IsVirtual = I.isVirtual();
996 const CXXRecordDecl *BaseDecl = I.getType()->getAsCXXRecordDecl();
999 BaseSubobjectInfo *Info = ComputeBaseSubobjectInfo(BaseDecl, IsVirtual,
1005 "Did not add virtual base!");
1008 assert(!NonVirtualBaseInfo.count(BaseDecl) &&
1009 "Non-virtual base already exists!");
1010 NonVirtualBaseInfo.insert(std::make_pair(BaseDecl, Info));
1015 void ItaniumRecordLayoutBuilder::EnsureVTablePointerAlignment(
1020 if (!MaxFieldAlignment.
isZero()) {
1021 BaseAlign =
std::min(BaseAlign, MaxFieldAlignment);
1022 UnpackedBaseAlign =
std::min(UnpackedBaseAlign, MaxFieldAlignment);
1026 setSize(getSize().alignTo(BaseAlign));
1029 UpdateAlignment(BaseAlign, UnpackedBaseAlign, BaseAlign);
1032 void ItaniumRecordLayoutBuilder::LayoutNonVirtualBases(
1035 DeterminePrimaryBase(RD);
1038 ComputeBaseSubobjectInfo(RD);
1042 if (PrimaryBaseIsVirtual) {
1045 BaseSubobjectInfo *PrimaryBaseInfo =
VirtualBaseInfo.lookup(PrimaryBase);
1046 PrimaryBaseInfo->Derived =
nullptr;
1049 IndirectPrimaryBases.insert(PrimaryBase);
1051 assert(!VisitedVirtualBases.count(PrimaryBase) &&
1052 "vbase already visited!");
1053 VisitedVirtualBases.insert(PrimaryBase);
1055 LayoutVirtualBase(PrimaryBaseInfo);
1057 BaseSubobjectInfo *PrimaryBaseInfo =
1058 NonVirtualBaseInfo.lookup(PrimaryBase);
1059 assert(PrimaryBaseInfo &&
1060 "Did not find base info for non-virtual primary base!");
1062 LayoutNonVirtualBase(PrimaryBaseInfo);
1068 assert(DataSize == 0 &&
"Vtable pointer must be at offset zero!");
1073 EnsureVTablePointerAlignment(PtrAlign);
1076 assert(!IsUnion &&
"Unions cannot be dynamic classes.");
1077 HandledFirstNonOverlappingEmptyField =
true;
1079 setSize(getSize() + PtrWidth);
1080 setDataSize(getSize());
1084 for (
const auto &I : RD->
bases()) {
1090 const CXXRecordDecl *BaseDecl = I.getType()->getAsCXXRecordDecl();
1095 if (BaseDecl == PrimaryBase && !PrimaryBaseIsVirtual)
1099 BaseSubobjectInfo *BaseInfo = NonVirtualBaseInfo.
lookup(BaseDecl);
1100 assert(BaseInfo &&
"Did not find base info for non-virtual base!");
1102 LayoutNonVirtualBase(BaseInfo);
1106 void ItaniumRecordLayoutBuilder::LayoutNonVirtualBase(
1107 const BaseSubobjectInfo *
Base) {
1112 assert(!Bases.count(
Base->Class) &&
"base offset already exists!");
1113 Bases.insert(std::make_pair(
Base->Class,
Offset));
1118 void ItaniumRecordLayoutBuilder::AddPrimaryVirtualBaseOffsets(
1121 if (!Info->Class->getNumVBases())
1125 if (Info->PrimaryVirtualBaseInfo) {
1126 assert(Info->PrimaryVirtualBaseInfo->IsVirtual &&
1127 "Primary virtual base is not virtual!");
1128 if (Info->PrimaryVirtualBaseInfo->Derived == Info) {
1130 assert(!VBases.count(Info->PrimaryVirtualBaseInfo->Class) &&
1131 "primary vbase offset already exists!");
1132 VBases.insert(std::make_pair(Info->PrimaryVirtualBaseInfo->Class,
1136 AddPrimaryVirtualBaseOffsets(Info->PrimaryVirtualBaseInfo,
Offset);
1142 for (
const BaseSubobjectInfo *
Base : Info->Bases) {
1143 if (
Base->IsVirtual)
1147 AddPrimaryVirtualBaseOffsets(
Base, BaseOffset);
1151 void ItaniumRecordLayoutBuilder::LayoutVirtualBases(
1154 bool PrimaryBaseIsVirtual;
1156 if (MostDerivedClass == RD) {
1157 PrimaryBase = this->PrimaryBase;
1158 PrimaryBaseIsVirtual = this->PrimaryBaseIsVirtual;
1166 assert(!
Base.getType()->isDependentType() &&
1167 "Cannot layout class with dependent bases.");
1171 if (
Base.isVirtual()) {
1172 if (PrimaryBase != BaseDecl || !PrimaryBaseIsVirtual) {
1173 bool IndirectPrimaryBase = IndirectPrimaryBases.count(BaseDecl);
1176 if (!IndirectPrimaryBase) {
1178 if (!VisitedVirtualBases.insert(BaseDecl).second)
1182 assert(BaseInfo &&
"Did not find virtual base info!");
1183 LayoutVirtualBase(BaseInfo);
1193 LayoutVirtualBases(BaseDecl, MostDerivedClass);
1197 void ItaniumRecordLayoutBuilder::LayoutVirtualBase(
1198 const BaseSubobjectInfo *
Base) {
1199 assert(!
Base->Derived &&
"Trying to lay out a primary virtual base!");
1205 assert(!VBases.count(
Base->Class) &&
"vbase offset already exists!");
1206 VBases.insert(std::make_pair(
Base->Class,
1213 ItaniumRecordLayoutBuilder::LayoutBase(
const BaseSubobjectInfo *
Base) {
1214 assert(!IsUnion &&
"Unions cannot have base classes.");
1220 bool HasExternalLayout =
false;
1221 if (UseExternalLayout) {
1222 if (
Base->IsVirtual)
1228 auto getBaseOrPreferredBaseAlignFromUnpacked = [&](
CharUnits UnpackedAlign) {
1231 return (Packed && ((Context.
getLangOpts().getClangABICompat() <=
1242 getBaseOrPreferredBaseAlignFromUnpacked(UnpackedBaseAlign);
1244 getBaseOrPreferredBaseAlignFromUnpacked(UnpackedPreferredBaseAlign);
1246 const bool DefaultsToAIXPowerAlignment =
1248 if (DefaultsToAIXPowerAlignment) {
1253 if (!
Base->Class->isEmpty() && !HandledFirstNonOverlappingEmptyField) {
1256 HandledFirstNonOverlappingEmptyField =
true;
1257 }
else if (!IsNaturalAlign) {
1258 UnpackedPreferredBaseAlign = UnpackedBaseAlign;
1259 PreferredBaseAlign = BaseAlign;
1263 CharUnits UnpackedAlignTo = !DefaultsToAIXPowerAlignment
1265 : UnpackedPreferredBaseAlign;
1267 if (
Base->Class->isEmpty() &&
1273 UpdateAlignment(BaseAlign, UnpackedAlignTo, PreferredBaseAlign);
1280 if (!MaxFieldAlignment.
isZero()) {
1281 BaseAlign =
std::min(BaseAlign, MaxFieldAlignment);
1282 PreferredBaseAlign =
std::min(PreferredBaseAlign, MaxFieldAlignment);
1283 UnpackedAlignTo =
std::min(UnpackedAlignTo, MaxFieldAlignment);
1287 !DefaultsToAIXPowerAlignment ? BaseAlign : PreferredBaseAlign;
1288 if (!HasExternalLayout) {
1290 Offset = getDataSize().alignTo(AlignTo);
1293 while (!EmptySubobjects->CanPlaceBaseAtOffset(
Base,
Offset))
1296 bool Allowed = EmptySubobjects->CanPlaceBaseAtOffset(
Base,
Offset);
1298 assert(Allowed &&
"Base subobject externally placed at overlapping offset");
1300 if (InferAlignment &&
Offset < getDataSize().alignTo(AlignTo)) {
1304 InferAlignment =
false;
1308 if (!
Base->Class->isEmpty()) {
1312 setSize(
std::max(getSize(), getDataSize()));
1317 UpdateAlignment(BaseAlign, UnpackedAlignTo, PreferredBaseAlign);
1322 void ItaniumRecordLayoutBuilder::InitializeLayout(
const Decl *D) {
1323 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(D)) {
1328 Packed = D->
hasAttr<PackedAttr>();
1331 if (
unsigned DefaultMaxFieldAlignment = Context.
getLangOpts().PackStruct) {
1339 if (D->
hasAttr<AlignMac68kAttr>()) {
1341 !D->
hasAttr<AlignNaturalAttr>() &&
1342 "Having both mac68k and natural alignment on a decl is not allowed.");
1343 IsMac68kAlign =
true;
1348 if (D->
hasAttr<AlignNaturalAttr>())
1349 IsNaturalAlign =
true;
1351 if (
const MaxFieldAlignmentAttr *MFAA = D->
getAttr<MaxFieldAlignmentAttr>())
1358 HandledFirstNonOverlappingEmptyField =
1362 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(D))
1364 UseExternalLayout = Source->layoutRecordType(
1369 if (UseExternalLayout) {
1375 InferAlignment =
true;
1381 void ItaniumRecordLayoutBuilder::Layout(
const RecordDecl *D) {
1382 InitializeLayout(D);
1390 void ItaniumRecordLayoutBuilder::Layout(
const CXXRecordDecl *RD) {
1391 InitializeLayout(RD);
1394 LayoutNonVirtualBases(RD);
1400 NonVirtualAlignment = Alignment;
1401 PreferredNVAlignment = PreferredAlignment;
1404 LayoutVirtualBases(RD, RD);
1413 if (
Base.isVirtual())
1418 assert(Bases.count(BaseDecl) &&
"Did not find base offset!");
1425 assert(VBases.count(BaseDecl) &&
"Did not find base offset!");
1439 setSize(getDataSize());
1442 InitializeLayout(D);
1446 LayoutField(IVD,
false);
1453 void ItaniumRecordLayoutBuilder::LayoutFields(
const RecordDecl *D) {
1462 InsertExtraPadding && (Next !=
End || !HasFlexibleArrayMember));
1471 return llvm::alignTo(Size, CharAlignment);
1474 void ItaniumRecordLayoutBuilder::LayoutWideBitField(
uint64_t FieldSize,
1479 "Can only have wide bit-fields in C++!");
1491 for (
const QualType &QT : IntegralPODTypes) {
1494 if (Size > FieldSize)
1499 assert(!
Type.isNull() &&
"Did not find a type!");
1504 UnfilledBitsInLastUnit = 0;
1505 LastBitfieldStorageUnitSize = 0;
1508 uint64_t UnpaddedFieldOffset = getDataSizeInBits() - UnfilledBitsInLastUnit;
1513 setDataSize(
std::max(getDataSizeInBits(), RoundedFieldSize));
1518 FieldOffset = llvm::alignTo(getDataSizeInBits(), Context.
toBits(TypeAlign));
1520 uint64_t NewSizeInBits = FieldOffset + FieldSize;
1524 UnfilledBitsInLastUnit = getDataSizeInBits() - NewSizeInBits;
1528 FieldOffsets.push_back(FieldOffset);
1530 CheckFieldPadding(FieldOffset, UnpaddedFieldOffset, FieldOffset,
1531 Context.
toBits(TypeAlign), FieldPacked, D);
1534 setSize(
std::max(getSizeInBits(), getDataSizeInBits()));
1537 UpdateAlignment(TypeAlign);
1544 void ItaniumRecordLayoutBuilder::LayoutBitField(
const FieldDecl *D) {
1545 bool FieldPacked = Packed || D->
hasAttr<PackedAttr>();
1549 unsigned FieldAlign = FieldInfo.
Align;
1612 FieldAlign = StorageUnitSize;
1617 if (LastBitfieldStorageUnitSize != StorageUnitSize ||
1618 UnfilledBitsInLastUnit < FieldSize) {
1620 if (!LastBitfieldStorageUnitSize && !FieldSize)
1623 UnfilledBitsInLastUnit = 0;
1624 LastBitfieldStorageUnitSize = 0;
1638 StorageUnitSize = 32;
1640 if (!AlignIsRequired)
1644 if (FieldAlign < StorageUnitSize) {
1647 FieldAlign = StorageUnitSize;
1654 if (FieldSize > StorageUnitSize && !
isAIXLayout(Context)) {
1655 LayoutWideBitField(FieldSize, StorageUnitSize, FieldPacked, D);
1661 IsUnion ? 0 : (getDataSizeInBits() - UnfilledBitsInLastUnit);
1666 if (FieldSize == 0 &&
1669 if (!IsUnion && FieldOffset == 0 &&
1675 unsigned ZeroLengthBitfieldBoundary =
1677 FieldAlign =
std::max(FieldAlign, ZeroLengthBitfieldBoundary);
1686 unsigned UnpackedFieldAlign = FieldAlign;
1689 if (!IsMsStruct && FieldPacked && FieldSize != 0)
1694 if (ExplicitFieldAlign) {
1695 FieldAlign =
std::max(FieldAlign, ExplicitFieldAlign);
1696 UnpackedFieldAlign =
std::max(UnpackedFieldAlign, ExplicitFieldAlign);
1701 unsigned MaxFieldAlignmentInBits = Context.
toBits(MaxFieldAlignment);
1702 if (!MaxFieldAlignment.
isZero() && FieldSize) {
1703 UnpackedFieldAlign =
std::min(UnpackedFieldAlign, MaxFieldAlignmentInBits);
1705 FieldAlign = UnpackedFieldAlign;
1707 FieldAlign =
std::min(FieldAlign, MaxFieldAlignmentInBits);
1712 if (IsMsStruct && IsUnion) {
1713 FieldAlign = UnpackedFieldAlign = 1;
1719 uint64_t UnpaddedFieldOffset = FieldOffset;
1720 uint64_t UnpackedFieldOffset = FieldOffset;
1730 if (FieldSize == 0 || FieldSize > UnfilledBitsInLastUnit) {
1731 FieldOffset = llvm::alignTo(FieldOffset, FieldAlign);
1732 UnpackedFieldOffset =
1733 llvm::alignTo(UnpackedFieldOffset, UnpackedFieldAlign);
1734 UnfilledBitsInLastUnit = 0;
1739 bool AllowPadding = MaxFieldAlignment.
isZero();
1742 if (FieldSize == 0 ||
1744 (FieldOffset & (FieldAlign - 1)) + FieldSize > StorageUnitSize)) {
1745 FieldOffset = llvm::alignTo(FieldOffset, FieldAlign);
1746 }
else if (ExplicitFieldAlign &&
1747 (MaxFieldAlignmentInBits == 0 ||
1748 ExplicitFieldAlign <= MaxFieldAlignmentInBits) &&
1752 FieldOffset = llvm::alignTo(FieldOffset, ExplicitFieldAlign);
1756 if (FieldSize == 0 ||
1758 (UnpackedFieldOffset & (UnpackedFieldAlign - 1)) + FieldSize >
1760 UnpackedFieldOffset =
1761 llvm::alignTo(UnpackedFieldOffset, UnpackedFieldAlign);
1762 else if (ExplicitFieldAlign &&
1763 (MaxFieldAlignmentInBits == 0 ||
1764 ExplicitFieldAlign <= MaxFieldAlignmentInBits) &&
1766 UnpackedFieldOffset =
1767 llvm::alignTo(UnpackedFieldOffset, ExplicitFieldAlign);
1772 if (UseExternalLayout)
1773 FieldOffset = updateExternalFieldOffset(D, FieldOffset);
1776 FieldOffsets.push_back(FieldOffset);
1785 FieldAlign = UnpackedFieldAlign = 1;
1793 if (!MaxFieldAlignment.
isZero()) {
1794 UnpackedFieldAlign =
1795 std::min(UnpackedFieldAlign, MaxFieldAlignmentInBits);
1796 FieldAlign =
std::min(FieldAlign, MaxFieldAlignmentInBits);
1801 if (!UseExternalLayout)
1802 CheckFieldPadding(FieldOffset, UnpaddedFieldOffset, UnpackedFieldOffset,
1803 UnpackedFieldAlign, FieldPacked, D);
1813 RoundedFieldSize = (FieldSize ? StorageUnitSize
1821 setDataSize(
std::max(getDataSizeInBits(), RoundedFieldSize));
1825 }
else if (IsMsStruct && FieldSize) {
1828 if (!UnfilledBitsInLastUnit) {
1829 setDataSize(FieldOffset + StorageUnitSize);
1830 UnfilledBitsInLastUnit = StorageUnitSize;
1832 UnfilledBitsInLastUnit -= FieldSize;
1833 LastBitfieldStorageUnitSize = StorageUnitSize;
1839 uint64_t NewSizeInBits = FieldOffset + FieldSize;
1841 setDataSize(llvm::alignTo(NewSizeInBits, CharAlignment));
1842 UnfilledBitsInLastUnit = getDataSizeInBits() - NewSizeInBits;
1847 LastBitfieldStorageUnitSize = 0;
1851 setSize(
std::max(getSizeInBits(), getDataSizeInBits()));
1854 UnadjustedAlignment =
1860 void ItaniumRecordLayoutBuilder::LayoutField(
const FieldDecl *D,
1861 bool InsertExtraPadding) {
1863 bool IsOverlappingEmptyField =
1867 (IsUnion || IsOverlappingEmptyField) ?
CharUnits::Zero() : getDataSize();
1869 const bool DefaultsToAIXPowerAlignment =
1871 bool FoundFirstNonOverlappingEmptyFieldForAIX =
false;
1872 if (DefaultsToAIXPowerAlignment && !HandledFirstNonOverlappingEmptyField) {
1874 "The first non-overlapping empty field should have been handled.");
1876 if (!IsOverlappingEmptyField) {
1877 FoundFirstNonOverlappingEmptyFieldForAIX =
true;
1884 HandledFirstNonOverlappingEmptyField = !IsUnion;
1893 uint64_t UnpaddedFieldOffset = getDataSizeInBits() - UnfilledBitsInLastUnit;
1895 UnfilledBitsInLastUnit = 0;
1896 LastBitfieldStorageUnitSize = 0;
1908 auto setDeclInfo = [&](
bool IsIncompleteArrayType) {
1910 FieldAlign = TI.Align;
1913 EffectiveFieldSize = FieldSize =
1915 AlignRequirement = TI.AlignRequirement;
1921 setDeclInfo(
false );
1927 EffectiveFieldSize =
1941 if (!llvm::isPowerOf2_64(TypeSize.
getQuantity())) {
1944 "Non PowerOf2 size in MSVC mode");
1966 if (TypeSize > FieldAlign &&
1968 FieldAlign = TypeSize;
1973 bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
1974 FieldClass->hasAttr<PackedAttr>() ||
1985 auto alignedAttrCanDecreaseAIXAlignment = [AlignRequirement, FieldPacked] {
2004 if (DefaultsToAIXPowerAlignment && !alignedAttrCanDecreaseAIXAlignment() &&
2005 (FoundFirstNonOverlappingEmptyFieldForAIX || IsNaturalAlign)) {
2006 auto performBuiltinTypeAlignmentUpgrade = [&](
const BuiltinType *BTy) {
2007 if (BTy->getKind() == BuiltinType::Double ||
2008 BTy->getKind() == BuiltinType::LongDouble) {
2010 "No need to upgrade the alignment value.");
2017 performBuiltinTypeAlignmentUpgrade(
2020 performBuiltinTypeAlignmentUpgrade(BTy);
2023 assert(RD &&
"Expected non-null RecordDecl.");
2031 CharUnits UnpackedFieldAlign = FieldAlign;
2033 CharUnits UnpackedFieldOffset = FieldOffset;
2034 CharUnits OriginalFieldAlign = UnpackedFieldAlign;
2038 PackedFieldAlign =
std::max(PackedFieldAlign, MaxAlignmentInChars);
2039 PreferredAlign =
std::max(PreferredAlign, MaxAlignmentInChars);
2040 UnpackedFieldAlign =
std::max(UnpackedFieldAlign, MaxAlignmentInChars);
2043 if (!MaxFieldAlignment.
isZero()) {
2044 PackedFieldAlign =
std::min(PackedFieldAlign, MaxFieldAlignment);
2045 PreferredAlign =
std::min(PreferredAlign, MaxFieldAlignment);
2046 UnpackedFieldAlign =
std::min(UnpackedFieldAlign, MaxFieldAlignment);
2051 FieldAlign = UnpackedFieldAlign;
2052 if (DefaultsToAIXPowerAlignment)
2053 UnpackedFieldAlign = PreferredAlign;
2055 PreferredAlign = PackedFieldAlign;
2056 FieldAlign = PackedFieldAlign;
2060 !DefaultsToAIXPowerAlignment ? FieldAlign : PreferredAlign;
2062 FieldOffset = FieldOffset.
alignTo(AlignTo);
2063 UnpackedFieldOffset = UnpackedFieldOffset.
alignTo(UnpackedFieldAlign);
2065 if (UseExternalLayout) {
2067 updateExternalFieldOffset(D, Context.
toBits(FieldOffset)));
2069 if (!IsUnion && EmptySubobjects) {
2071 bool Allowed = EmptySubobjects->CanPlaceFieldAtOffset(D, FieldOffset);
2073 assert(Allowed &&
"Externally-placed field cannot be placed here");
2076 if (!IsUnion && EmptySubobjects) {
2078 while (!EmptySubobjects->CanPlaceFieldAtOffset(D, FieldOffset)) {
2083 FieldOffset = getDataSize().
alignTo(AlignTo);
2085 FieldOffset += AlignTo;
2091 FieldOffsets.push_back(Context.
toBits(FieldOffset));
2093 if (!UseExternalLayout)
2094 CheckFieldPadding(Context.
toBits(FieldOffset), UnpaddedFieldOffset,
2095 Context.
toBits(UnpackedFieldOffset),
2096 Context.
toBits(UnpackedFieldAlign), FieldPacked, D);
2098 if (InsertExtraPadding) {
2100 CharUnits ExtraSizeForAsan = ASanAlignment;
2101 if (FieldSize % ASanAlignment)
2104 EffectiveFieldSize = FieldSize = FieldSize + ExtraSizeForAsan;
2108 if (!IsOverlappingEmptyField) {
2109 uint64_t EffectiveFieldSizeInBits = Context.
toBits(EffectiveFieldSize);
2111 setDataSize(
std::max(getDataSizeInBits(), EffectiveFieldSizeInBits));
2113 setDataSize(FieldOffset + EffectiveFieldSize);
2115 PaddedFieldSize =
std::max(PaddedFieldSize, FieldOffset + FieldSize);
2116 setSize(
std::max(getSizeInBits(), getDataSizeInBits()));
2123 UnadjustedAlignment =
std::max(UnadjustedAlignment, FieldAlign);
2124 UpdateAlignment(FieldAlign, UnpackedFieldAlign, PreferredAlign);
2130 if (RD->
hasAttr<PackedAttr>() || !MaxFieldAlignment.
isZero())
2131 if (FieldAlign < OriginalFieldAlign)
2136 if (FieldOffset % OriginalFieldAlign != 0)
2142 if (Packed && !FieldPacked && PackedFieldAlign < FieldAlign)
2146 void ItaniumRecordLayoutBuilder::FinishLayout(
const NamedDecl *D) {
2148 if (Context.
getLangOpts().CPlusPlus && getSizeInBits() == 0) {
2166 uint64_t UnpaddedSize = getSizeInBits() - UnfilledBitsInLastUnit;
2168 llvm::alignTo(getSizeInBits(), Context.
toBits(UnpackedAlignment));
2170 uint64_t RoundedSize = llvm::alignTo(
2174 : PreferredAlignment));
2176 if (UseExternalLayout) {
2180 if (InferAlignment &&
External.Size < RoundedSize) {
2183 InferAlignment =
false;
2190 setSize(RoundedSize);
2193 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(D)) {
2195 if (getSizeInBits() > UnpaddedSize) {
2196 unsigned PadSize = getSizeInBits() - UnpaddedSize;
2198 if (PadSize % CharBitNum == 0) {
2199 PadSize = PadSize / CharBitNum;
2205 << (InBits ? 1 : 0);
2208 const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
2216 if (Packed && UnpackedAlignment <= Alignment &&
2217 UnpackedSizeInBits == getSizeInBits() && !HasPackedField &&
2218 (!CXXRD || CXXRD->isPOD() ||
2226 void ItaniumRecordLayoutBuilder::UpdateAlignment(
2231 if (IsMac68kAlign || (UseExternalLayout && !InferAlignment))
2234 if (NewAlignment > Alignment) {
2235 assert(llvm::isPowerOf2_64(NewAlignment.
getQuantity()) &&
2236 "Alignment not a power of 2");
2237 Alignment = NewAlignment;
2240 if (UnpackedNewAlignment > UnpackedAlignment) {
2241 assert(llvm::isPowerOf2_64(UnpackedNewAlignment.
getQuantity()) &&
2242 "Alignment not a power of 2");
2243 UnpackedAlignment = UnpackedNewAlignment;
2246 if (PreferredNewAlignment > PreferredAlignment) {
2247 assert(llvm::isPowerOf2_64(PreferredNewAlignment.
getQuantity()) &&
2248 "Alignment not a power of 2");
2249 PreferredAlignment = PreferredNewAlignment;
2254 ItaniumRecordLayoutBuilder::updateExternalFieldOffset(
const FieldDecl *Field,
2258 if (InferAlignment && ExternalFieldOffset < ComputedOffset) {
2263 InferAlignment =
false;
2267 return ExternalFieldOffset;
2283 default: llvm_unreachable(
"Invalid tag kind for field padding diagnostic!");
2287 void ItaniumRecordLayoutBuilder::CheckFieldPadding(
2289 unsigned UnpackedAlign,
bool isPacked,
const FieldDecl *D) {
2292 if (isa<ObjCIvarDecl>(D))
2303 if (!IsUnion &&
Offset > UnpaddedOffset) {
2304 unsigned PadSize =
Offset - UnpaddedOffset;
2306 if (PadSize % CharBitNum == 0) {
2307 PadSize = PadSize / CharBitNum;
2312 : diag::warn_padded_struct_field;
2320 : diag::warn_padded_struct_anon_field;
2324 << (InBits ? 1 : 0);
2327 if (isPacked &&
Offset != UnpackedOffset) {
2328 HasPackedField =
true;
2352 bool allowInlineFunctions =
2356 if (!MD->isVirtual())
2359 if (MD->isPureVirtual())
2364 if (MD->isImplicit())
2367 if (MD->isInlineSpecified() || MD->isConstexpr())
2370 if (MD->hasInlineBody())
2374 if (!MD->isUserProvided())
2378 if (!allowInlineFunctions) {
2390 if (!MD->hasAttr<CUDADeviceAttr>())
2394 if (!MD->hasAttr<CUDAHostAttr>() && MD->hasAttr<CUDADeviceAttr>())
2402 if (MD->hasAttr<DLLImportAttr>() && !RD->
hasAttr<DLLImportAttr>() &&
2457 llvm_unreachable(
"bad tail-padding use kind");
2561 struct MicrosoftRecordLayoutBuilder {
2562 struct ElementInfo {
2566 typedef llvm::DenseMap<const CXXRecordDecl *, CharUnits> BaseOffsetsMapTy;
2567 MicrosoftRecordLayoutBuilder(
const ASTContext &Context,
2568 EmptySubobjectMap *EmptySubobjects)
2569 : Context(Context), EmptySubobjects(EmptySubobjects) {}
2572 MicrosoftRecordLayoutBuilder(
const MicrosoftRecordLayoutBuilder &) =
delete;
2573 void operator=(
const MicrosoftRecordLayoutBuilder &) =
delete;
2594 void layoutBitField(
const FieldDecl *FD);
2597 void layoutZeroWidthBitField(
const FieldDecl *FD);
2606 ElementInfo getAdjustedElementInfo(
const FieldDecl *FD);
2608 void placeFieldAtOffset(
CharUnits FieldOffset) {
2609 FieldOffsets.push_back(Context.
toBits(FieldOffset));
2612 void placeFieldAtBitOffset(
uint64_t FieldOffset) {
2613 FieldOffsets.push_back(FieldOffset);
2616 void computeVtorDispSet(
2617 llvm::SmallPtrSetImpl<const CXXRecordDecl *> &HasVtorDispSet,
2620 EmptySubobjectMap *EmptySubobjects;
2644 ElementInfo PointerInfo;
2652 BaseOffsetsMapTy Bases;
2658 unsigned RemainingBitsInField;
2662 bool LastFieldIsNonZeroWidthBitfield : 1;
2664 bool HasOwnVFPtr : 1;
2670 bool EndsWithZeroSizedObject : 1;
2673 bool LeadsWithZeroSizedBase : 1;
2676 bool UseExternalLayout : 1;
2684 MicrosoftRecordLayoutBuilder::ElementInfo
2685 MicrosoftRecordLayoutBuilder::getAdjustedElementInfo(
2690 if (!MaxFieldAlignment.
isZero())
2691 Info.Alignment =
std::min(Info.Alignment, MaxFieldAlignment);
2697 Alignment =
std::max(Alignment, Info.Alignment);
2704 MicrosoftRecordLayoutBuilder::ElementInfo
2705 MicrosoftRecordLayoutBuilder::getAdjustedElementInfo(
2711 ElementInfo Info{TInfo.
Width, TInfo.Align};
2723 Info.Alignment =
std::max(Info.Alignment, FieldRequiredAlignment);
2729 FieldRequiredAlignment =
std::max(FieldRequiredAlignment,
2733 RequiredAlignment =
std::max(RequiredAlignment, FieldRequiredAlignment);
2736 if (!MaxFieldAlignment.
isZero())
2737 Info.Alignment =
std::min(Info.Alignment, MaxFieldAlignment);
2738 if (FD->
hasAttr<PackedAttr>())
2740 Info.Alignment =
std::max(Info.Alignment, FieldRequiredAlignment);
2744 void MicrosoftRecordLayoutBuilder::layout(
const RecordDecl *RD) {
2747 initializeLayout(RD);
2749 DataSize =
Size =
Size.alignTo(Alignment);
2755 void MicrosoftRecordLayoutBuilder::cxxLayout(
const CXXRecordDecl *RD) {
2758 initializeLayout(RD);
2759 initializeCXXLayout(RD);
2760 layoutNonVirtualBases(RD);
2764 if (HasOwnVFPtr || (HasVBPtr && !SharedVBPtrBase))
2765 Alignment =
std::max(Alignment, PointerInfo.Alignment);
2766 auto RoundingAlignment = Alignment;
2767 if (!MaxFieldAlignment.
isZero())
2768 RoundingAlignment =
std::min(RoundingAlignment, MaxFieldAlignment);
2769 if (!UseExternalLayout)
2770 Size =
Size.alignTo(RoundingAlignment);
2771 NonVirtualSize =
Size;
2774 layoutVirtualBases(RD);
2778 void MicrosoftRecordLayoutBuilder::initializeLayout(
const RecordDecl *RD) {
2791 if (
unsigned DefaultMaxFieldAlignment = Context.
getLangOpts().PackStruct)
2795 if (
const MaxFieldAlignmentAttr *MFAA = RD->
getAttr<MaxFieldAlignmentAttr>()){
2796 unsigned PackedAlignment = MFAA->getAlignment();
2797 if (PackedAlignment <=
2802 if (RD->
hasAttr<PackedAttr>())
2806 UseExternalLayout =
false;
2808 UseExternalLayout = Source->layoutRecordType(
2814 MicrosoftRecordLayoutBuilder::initializeCXXLayout(
const CXXRecordDecl *RD) {
2815 EndsWithZeroSizedObject =
false;
2816 LeadsWithZeroSizedBase =
false;
2817 HasOwnVFPtr =
false;
2819 PrimaryBase =
nullptr;
2820 SharedVBPtrBase =
nullptr;
2828 if (!MaxFieldAlignment.
isZero())
2829 PointerInfo.Alignment =
std::min(PointerInfo.Alignment, MaxFieldAlignment);
2833 MicrosoftRecordLayoutBuilder::layoutNonVirtualBases(
const CXXRecordDecl *RD) {
2841 bool HasPolymorphicBaseClass =
false;
2848 if (
Base.isVirtual()) {
2853 if (!SharedVBPtrBase && BaseLayout.
hasVBPtr()) {
2854 SharedVBPtrBase = BaseDecl;
2862 PrimaryBase = BaseDecl;
2866 layoutNonVirtualBase(RD, BaseDecl, BaseLayout, PreviousBaseLayout);
2870 if (!HasPolymorphicBaseClass)
2874 else if (!PrimaryBase) {
2879 M->size_overridden_methods() == 0) {
2888 bool CheckLeadingLayout = !PrimaryBase;
2891 if (
Base.isVirtual())
2902 if (CheckLeadingLayout) {
2903 CheckLeadingLayout =
false;
2907 layoutNonVirtualBase(RD, BaseDecl, BaseLayout, PreviousBaseLayout);
2913 else if (SharedVBPtrBase) {
2920 if (!isa<CXXRecordDecl>(RD))
2922 if (RD->
hasAttr<EmptyBasesAttr>())
2924 if (
auto *LVA = RD->
getAttr<LayoutVersionAttr>())
2934 void MicrosoftRecordLayoutBuilder::layoutNonVirtualBase(
2945 ElementInfo Info = getAdjustedElementInfo(BaseLayout);
2949 bool FoundBase =
false;
2950 if (UseExternalLayout) {
2951 FoundBase =
External.getExternalNVBaseOffset(BaseDecl, BaseOffset);
2952 if (BaseOffset > Size) {
2958 if (MDCUsesEBO && BaseDecl->
isEmpty() &&
2963 BaseOffset =
Size =
Size.alignTo(Info.Alignment);
2966 Bases.insert(std::make_pair(BaseDecl, BaseOffset));
2969 PreviousBaseLayout = &BaseLayout;
2972 void MicrosoftRecordLayoutBuilder::layoutFields(
const RecordDecl *RD) {
2973 LastFieldIsNonZeroWidthBitfield =
false;
2978 void MicrosoftRecordLayoutBuilder::layoutField(
const FieldDecl *FD) {
2983 LastFieldIsNonZeroWidthBitfield =
false;
2984 ElementInfo Info = getAdjustedElementInfo(FD);
2985 Alignment =
std::max(Alignment, Info.Alignment);
2990 FieldClass->
fields().empty();
2993 if (UseExternalLayout) {
2996 }
else if (IsUnion) {
2998 }
else if (EmptySubobjects) {
2999 if (!IsOverlappingEmptyField)
3000 FieldOffset = DataSize.
alignTo(Info.Alignment);
3002 while (!EmptySubobjects->CanPlaceFieldAtOffset(FD, FieldOffset)) {
3004 bool HasBases = ParentClass && (!ParentClass->
bases().empty() ||
3005 !ParentClass->
vbases().empty());
3010 FieldOffset = DataSize.
alignTo(Info.Alignment);
3012 FieldOffset += Info.Alignment;
3016 FieldOffset =
Size.alignTo(Info.Alignment);
3018 placeFieldAtOffset(FieldOffset);
3020 if (!IsOverlappingEmptyField)
3021 DataSize =
std::max(DataSize, FieldOffset + Info.Size);
3026 void MicrosoftRecordLayoutBuilder::layoutBitField(
const FieldDecl *FD) {
3029 layoutZeroWidthBitField(FD);
3032 ElementInfo Info = getAdjustedElementInfo(FD);
3035 if (Width > Context.
toBits(Info.Size))
3036 Width = Context.
toBits(Info.Size);
3040 if (!UseExternalLayout && !IsUnion && LastFieldIsNonZeroWidthBitfield &&
3041 CurrentBitfieldSize == Info.Size && Width <= RemainingBitsInField) {
3042 placeFieldAtBitOffset(Context.
toBits(Size) - RemainingBitsInField);
3043 RemainingBitsInField -= Width;
3046 LastFieldIsNonZeroWidthBitfield =
true;
3047 CurrentBitfieldSize = Info.Size;
3048 if (UseExternalLayout) {
3049 auto FieldBitOffset =
External.getExternalFieldOffset(FD);
3050 placeFieldAtBitOffset(FieldBitOffset);
3052 llvm::alignDown(FieldBitOffset, Context.
toBits(Info.Alignment)) +
3053 Context.
toBits(Info.Size));
3055 Alignment =
std::max(Alignment, Info.Alignment);
3056 }
else if (IsUnion) {
3063 placeFieldAtOffset(FieldOffset);
3064 Size = FieldOffset + Info.Size;
3065 Alignment =
std::max(Alignment, Info.Alignment);
3066 RemainingBitsInField = Context.
toBits(Info.Size) - Width;
3072 MicrosoftRecordLayoutBuilder::layoutZeroWidthBitField(
const FieldDecl *FD) {
3075 if (!LastFieldIsNonZeroWidthBitfield) {
3081 LastFieldIsNonZeroWidthBitfield =
false;
3082 ElementInfo Info = getAdjustedElementInfo(FD);
3090 placeFieldAtOffset(FieldOffset);
3092 Alignment =
std::max(Alignment, Info.Alignment);
3097 void MicrosoftRecordLayoutBuilder::injectVBPtr(
const CXXRecordDecl *RD) {
3098 if (!HasVBPtr || SharedVBPtrBase)
3103 VBPtrOffset = VBPtrOffset.
alignTo(PointerInfo.Alignment);
3105 CharUnits FieldStart = VBPtrOffset + PointerInfo.Size;
3108 if (UseExternalLayout) {
3111 if (Size < FieldStart)
3118 .alignTo(
std::max(RequiredAlignment, Alignment));
3120 for (
uint64_t &FieldOffset : FieldOffsets)
3122 for (BaseOffsetsMapTy::value_type &
Base : Bases)
3123 if (
Base.second >= InjectionSite)
3127 void MicrosoftRecordLayoutBuilder::injectVFPtr(
const CXXRecordDecl *RD) {
3133 PointerInfo.Size.alignTo(
std::max(RequiredAlignment, Alignment));
3139 if (UseExternalLayout) {
3151 for (
uint64_t &FieldOffset : FieldOffsets)
3153 for (BaseOffsetsMapTy::value_type &
Base : Bases)
3157 void MicrosoftRecordLayoutBuilder::layoutVirtualBases(
const CXXRecordDecl *RD) {
3162 CharUnits VtorDispAlignment = VtorDispSize;
3164 if (!MaxFieldAlignment.
isZero())
3165 VtorDispAlignment =
std::min(VtorDispAlignment, MaxFieldAlignment);
3170 const CXXRecordDecl *BaseDecl = VBase.getType()->getAsCXXRecordDecl();
3175 VtorDispAlignment =
std::max(VtorDispAlignment, RequiredAlignment);
3178 computeVtorDispSet(HasVtorDispSet, RD);
3182 const CXXRecordDecl *BaseDecl = VBase.getType()->getAsCXXRecordDecl();
3184 bool HasVtordisp = HasVtorDispSet.contains(BaseDecl);
3193 Size =
Size.alignTo(VtorDispAlignment) + VtorDispSize;
3194 Alignment =
std::max(VtorDispAlignment, Alignment);
3197 ElementInfo Info = getAdjustedElementInfo(BaseLayout);
3201 if (UseExternalLayout) {
3202 if (!
External.getExternalVBaseOffset(BaseDecl, BaseOffset))
3205 BaseOffset =
Size.alignTo(Info.Alignment);
3207 assert(BaseOffset >= Size &&
"base offset already allocated");
3209 VBases.insert(std::make_pair(BaseDecl,
3212 PreviousBaseLayout = &BaseLayout;
3216 void MicrosoftRecordLayoutBuilder::finalizeLayout(
const RecordDecl *RD) {
3220 if (!RequiredAlignment.isZero()) {
3221 Alignment =
std::max(Alignment, RequiredAlignment);
3222 auto RoundingAlignment = Alignment;
3223 if (!MaxFieldAlignment.
isZero())
3224 RoundingAlignment =
std::min(RoundingAlignment, MaxFieldAlignment);
3225 RoundingAlignment =
std::max(RoundingAlignment, RequiredAlignment);
3226 Size =
Size.alignTo(RoundingAlignment);
3228 if (
Size.isZero()) {
3229 if (!
recordUsesEBO(RD) || !cast<CXXRecordDecl>(RD)->isEmpty()) {
3230 EndsWithZeroSizedObject =
true;
3231 LeadsWithZeroSizedBase =
true;
3235 if (RequiredAlignment >= MinEmptyStructSize)
3238 Size = MinEmptyStructSize;
3241 if (UseExternalLayout) {
3252 BasesWithOverriddenMethods,
3254 if (BasesWithOverriddenMethods.count(RD))
3259 if (!
Base.isVirtual() &&
3261 Base.getType()->getAsCXXRecordDecl()))
3266 void MicrosoftRecordLayoutBuilder::computeVtorDispSet(
3267 llvm::SmallPtrSetImpl<const CXXRecordDecl *> &HasVtordispSet,
3276 HasVtordispSet.insert(BaseDecl);
3287 if (bi.second.hasVtorDisp())
3288 HasVtordispSet.insert(bi.first);
3309 !isa<CXXDestructorDecl>(MD) && !MD->isPureVirtual())
3311 while (!Work.empty()) {
3315 if (MethodRange.begin() == MethodRange.end())
3316 BasesWithOverriddenMethods.insert(MD->
getParent());
3318 Work.insert(MethodRange.begin(), MethodRange.end());
3326 if (!HasVtordispSet.count(BaseDecl) &&
3328 HasVtordispSet.insert(BaseDecl);
3341 bool CheckAuxABI =
false;
3351 assert(D &&
"Cannot get layout of forward declarations!");
3352 assert(!D->
isInvalidDecl() &&
"Cannot get layout of invalid decl!");
3359 if (Entry)
return *Entry;
3364 if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
3365 EmptySubobjectMap EmptySubobjects(*
this, RD);
3366 MicrosoftRecordLayoutBuilder Builder(*
this, &EmptySubobjects);
3367 Builder.cxxLayout(RD);
3369 *
this, Builder.Size, Builder.Alignment, Builder.Alignment,
3370 Builder.Alignment, Builder.RequiredAlignment, Builder.HasOwnVFPtr,
3371 Builder.HasOwnVFPtr || Builder.PrimaryBase, Builder.VBPtrOffset,
3372 Builder.DataSize, Builder.FieldOffsets, Builder.NonVirtualSize,
3374 Builder.PrimaryBase,
false, Builder.SharedVBPtrBase,
3375 Builder.EndsWithZeroSizedObject, Builder.LeadsWithZeroSizedBase,
3376 Builder.Bases, Builder.VBases);
3378 MicrosoftRecordLayoutBuilder Builder(*
this,
nullptr);
3381 *
this, Builder.Size, Builder.Alignment, Builder.Alignment,
3382 Builder.Alignment, Builder.RequiredAlignment, Builder.Size,
3383 Builder.FieldOffsets);
3386 if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
3387 EmptySubobjectMap EmptySubobjects(*
this, RD);
3388 ItaniumRecordLayoutBuilder Builder(*
this, &EmptySubobjects);
3394 bool skipTailPadding =
3399 skipTailPadding ? Builder.getSize() : Builder.getDataSize();
3401 skipTailPadding ? DataSize : Builder.NonVirtualSize;
3403 *
this, Builder.getSize(), Builder.Alignment,
3404 Builder.PreferredAlignment, Builder.UnadjustedAlignment,
3408 NonVirtualSize, Builder.NonVirtualAlignment,
3409 Builder.PreferredNVAlignment,
3410 EmptySubobjects.SizeOfLargestEmptySubobject, Builder.PrimaryBase,
3411 Builder.PrimaryBaseIsVirtual,
nullptr,
false,
false, Builder.Bases,
3414 ItaniumRecordLayoutBuilder Builder(*
this,
nullptr);
3418 *
this, Builder.getSize(), Builder.Alignment,
3419 Builder.PreferredAlignment, Builder.UnadjustedAlignment,
3421 Builder.Alignment, Builder.getSize(), Builder.FieldOffsets);
3425 ASTRecordLayouts[D] = NewEntry;
3428 llvm::outs() <<
"\n*** Dumping AST Record Layout\n";
3439 assert(RD->
getDefinition() &&
"Cannot get key function for forward decl!");
3448 const Decl *Result =
3453 KeyFunctions[RD] =
const_cast<Decl*
>(Result);
3455 return cast_or_null<CXXMethodDecl>(Result);
3460 "not working with method declaration from class definition");
3465 const auto &Map = KeyFunctions;
3469 if (I == Map.end())
return;
3477 KeyFunctions.erase(Method->
getParent());
3488 if (
const FieldDecl *FD = dyn_cast<FieldDecl>(VD)) {
3498 return OffsetInBits;
3526 for (
const ObjCIvarDecl *IVD = Container->all_declared_ivar_begin();
3527 IVD; IVD = IVD->getNextIvar()) {
3532 assert(Index < RL->getFieldCount() &&
"Ivar is not inside record layout!");
3550 "Invalid interface decl!");
3565 if (SynthCount == 0)
3566 return getObjCLayout(D,
nullptr);
3569 ItaniumRecordLayoutBuilder Builder(*
this,
nullptr);
3573 *
this, Builder.getSize(), Builder.Alignment, Builder.PreferredAlignment,
3574 Builder.UnadjustedAlignment,
3576 Builder.Alignment, Builder.getDataSize(), Builder.FieldOffsets);
3578 ObjCLayouts[Key] = NewEntry;
3585 OS << llvm::format(
"%10" PRId64
" | ", (
int64_t)
Offset.getQuantity());
3586 OS.indent(IndentLevel * 2);
3590 unsigned Begin,
unsigned Width,
3591 unsigned IndentLevel) {
3594 llvm::raw_svector_ostream BufferOS(Buffer);
3595 BufferOS <<
Offset.getQuantity() <<
':';
3599 BufferOS <<
Begin <<
'-' << (
Begin + Width - 1);
3603 OS << llvm::right_justify(Buffer, 10) <<
" | ";
3604 OS.indent(IndentLevel * 2);
3609 OS.indent(IndentLevel * 2);
3615 unsigned IndentLevel,
3616 const char* Description,
3618 bool IncludeVirtualBases) {
3620 auto CXXRD = dyn_cast<CXXRecordDecl>(RD);
3623 OS << C.getTypeDeclType(
const_cast<RecordDecl *
>(RD));
3625 OS <<
' ' << Description;
3626 if (CXXRD && CXXRD->isEmpty())
3639 if (CXXRD->isDynamicClass() && !PrimaryBase && !
isMsLayout(C)) {
3641 OS <<
'(' << *RD <<
" vtable pointer)\n";
3642 }
else if (HasOwnVFPtr) {
3645 OS <<
'(' << *RD <<
" vftable pointer)\n";
3651 assert(!
Base.getType()->isDependentType() &&
3652 "Cannot layout class with dependent bases.");
3653 if (!
Base.isVirtual())
3654 Bases.push_back(
Base.getType()->getAsCXXRecordDecl());
3667 Base == PrimaryBase ?
"(primary base)" :
"(base)",
3675 OS <<
'(' << *RD <<
" vbtable pointer)\n";
3682 E = RD->
field_end(); I != E; ++I, ++FieldNo) {
3686 Offset + C.toCharUnitsFromBits(LocalFieldOffsetInBits);
3689 if (
auto RT = Field.getType()->getAs<
RecordType>()) {
3691 Field.getName().data(),
3697 if (Field.isBitField()) {
3698 uint64_t LocalFieldByteOffsetInBits = C.toBits(FieldOffset -
Offset);
3699 unsigned Begin = LocalFieldOffsetInBits - LocalFieldByteOffsetInBits;
3700 unsigned Width = Field.getBitWidthValue(C);
3705 const QualType &FieldType = C.getLangOpts().DumpRecordLayoutsCanonical
3706 ? Field.getType().getCanonicalType()
3708 OS << FieldType <<
' ' << Field <<
'\n';
3712 if (CXXRD && IncludeVirtualBases) {
3717 assert(
Base.isVirtual() &&
"Found non-virtual class!");
3722 if (VtorDisps.find(VBase)->second.hasVtorDisp()) {
3724 OS <<
"(vtordisp for vbase " << *VBase <<
")\n";
3729 "(primary virtual base)" :
"(virtual base)",
3735 if (!PrintSizeInfo)
return;
3742 if (C.getTargetInfo().defaultsToAIXPowerAlignment())
3750 if (C.getTargetInfo().defaultsToAIXPowerAlignment())
3751 OS <<
", preferrednvalign="
3758 bool Simple)
const {
3776 OS <<
"<ASTRecordLayout\n";
3781 if (
Target->defaultsToAIXPowerAlignment())
3784 if (
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
3785 OS <<
" BaseOffsets: [";
3787 for (
auto I : CXXRD->bases()) {
3792 Base = I.getType()->getAsCXXRecordDecl();
3793 OS << Info.CXXInfo->BaseOffsets[
Base].getQuantity();
3796 OS <<
" VBaseOffsets: [";
3798 for (
auto I : CXXRD->vbases()) {
3801 VBase = I.getType()->getAsCXXRecordDecl();
3802 OS << Info.CXXInfo->VBaseOffsets[VBase].VBaseOffset.getQuantity();
3806 OS <<
" FieldOffsets: [";
3807 for (
unsigned i = 0, e = Info.
getFieldCount(); i != e; ++i) {
clang::driver::toolchains::AIX AIX
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
static unsigned getCharWidth(tok::TokenKind kind, const TargetInfo &Target)
llvm::MachO::Target Target
static bool mustSkipTailPadding(TargetCXXABI ABI, const CXXRecordDecl *RD)
Does the target C++ ABI require us to skip over the tail-padding of the given class (considering it a...
static bool isAIXLayout(const ASTContext &Context)
static void PrintIndentNoOffset(raw_ostream &OS, unsigned IndentLevel)
static uint64_t roundUpSizeToCharAlignment(uint64_t Size, const ASTContext &Context)
static void PrintOffset(raw_ostream &OS, CharUnits Offset, unsigned IndentLevel)
static unsigned getPaddingDiagFromTagKind(TagTypeKind Tag)
Get diagnostic select index for tag kind for field padding diagnostic message.
static void DumpRecordLayout(raw_ostream &OS, const RecordDecl *RD, const ASTContext &C, CharUnits Offset, unsigned IndentLevel, const char *Description, bool PrintSizeInfo, bool IncludeVirtualBases)
static const CXXMethodDecl * computeKeyFunction(ASTContext &Context, const CXXRecordDecl *RD)
static uint64_t getFieldOffset(const ASTContext &C, const FieldDecl *FD)
static bool isMsLayout(const ASTContext &Context, bool CheckAuxABI=false)
static bool RequiresVtordisp(const llvm::SmallPtrSetImpl< const CXXRecordDecl * > &BasesWithOverriddenMethods, const CXXRecordDecl *RD)
static void PrintBitFieldOffset(raw_ostream &OS, CharUnits Offset, unsigned Begin, unsigned Width, unsigned IndentLevel)
static bool recordUsesEBO(const RecordDecl *RD)
__DEVICE__ int min(int __a, int __b)
__DEVICE__ int max(int __a, int __b)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
uint64_t getFieldOffset(const ValueDecl *FD) const
Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS, bool Simple=false) const
const CXXMethodDecl * getCurrentKeyFunction(const CXXRecordDecl *RD)
Get our current best idea for the key function of the given record decl, or nullptr if there isn't on...
const ASTRecordLayout & getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const
Get or compute information about the layout of the specified Objective-C implementation.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
const ASTRecordLayout & getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) const
Get or compute information about the layout of the specified Objective-C interface.
const LangOptions & getLangOpts() const
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const
bool isNearlyEmpty(const CXXRecordDecl *RD) const
CanQualType UnsignedLongTy
TypeInfo getTypeInfo(const Type *T) const
Get the size and alignment of the specified complete type in bits.
bool isAlignmentRequired(const Type *T) const
Determine if the alignment the type has was required using an alignment attribute.
void setNonKeyFunction(const CXXMethodDecl *method)
Observe that the given method cannot be a key function.
TypeInfoChars getTypeInfoInChars(const Type *T) const
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
uint64_t lookupFieldBitOffset(const ObjCInterfaceDecl *OID, const ObjCImplementationDecl *ID, const ObjCIvarDecl *Ivar) const
Get the offset of an ObjCIvarDecl in bits.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CanQualType UnsignedCharTy
CanQualType UnsignedIntTy
CanQualType UnsignedLongLongTy
CanQualType UnsignedShortTy
const TargetInfo & getTargetInfo() const
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
DiagnosticsEngine & getDiagnostics() const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const
Return number of constant array elements.
const TargetInfo * getAuxTargetInfo() const
ASTContext & operator=(const ASTContext &)=delete
uint64_t getCharWidth() const
Return the size of the character type, in bits.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
bool endsWithZeroSizedObject() const
bool hasOwnVFPtr() const
hasOwnVFPtr - Does this class provide its own virtual-function table pointer, rather than inheriting ...
CharUnits getAlignment() const
getAlignment - Get the record alignment in characters.
const CXXRecordDecl * getPrimaryBase() const
getPrimaryBase - Get the primary base for this record.
CharUnits getPreferredAlignment() const
getPreferredFieldAlignment - Get the record preferred alignment in characters.
bool hasOwnVBPtr() const
hasOwnVBPtr - Does this class provide its own virtual-base table pointer, rather than inheriting one ...
llvm::DenseMap< const CXXRecordDecl *, VBaseInfo > VBaseOffsetsMapTy
CharUnits getSize() const
getSize - Get the record size in characters.
const VBaseOffsetsMapTy & getVBaseOffsetsMap() const
unsigned getFieldCount() const
getFieldCount - Get the number of fields in the layout.
bool hasVBPtr() const
hasVBPtr - Does this class have a virtual function table pointer.
bool leadsWithZeroSizedBase() const
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
CharUnits getNonVirtualAlignment() const
getNonVirtualAlignment - Get the non-virtual alignment (in chars) of an object, which is the alignmen...
CharUnits getVBPtrOffset() const
getVBPtrOffset - Get the offset for virtual base table pointer.
CharUnits getDataSize() const
getDataSize() - Get the record data size, which is the record size without tail padding,...
CharUnits getRequiredAlignment() const
CharUnits getSizeOfLargestEmptySubobject() const
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
CharUnits getPreferredNVAlignment() const
getPreferredNVAlignment - Get the preferred non-virtual alignment (in chars) of an object,...
CharUnits getVBaseClassOffset(const CXXRecordDecl *VBase) const
getVBaseClassOffset - Get the offset, in chars, for the given base class.
bool hasExtendableVFPtr() const
hasVFPtr - Does this class have a virtual function table pointer that can be extended by a derived cl...
bool isPrimaryBaseVirtual() const
isPrimaryBaseVirtual - Get whether the primary base for this record is virtual or not.
CharUnits getNonVirtualSize() const
getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...
This class is used for builtin types like 'int'.
Represents a base class of a C++ class.
A set of all the primary bases for a class.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
overridden_method_range overridden_methods() const
Represents a C++ struct/union/class.
void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet &Bases) const
Get the indirect primary bases for this class.
bool hasUserDeclaredDestructor() const
Determine whether this class has a user-declared destructor.
method_range methods() const
bool isPolymorphic() const
Whether this class is polymorphic (C++ [class.virtual]), which means that the class contains or inher...
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
base_class_range vbases()
bool isDynamicClass() const
bool isCXX11StandardLayout() const
Determine whether this class was standard-layout per C++11 [class]p7, specifically using the C++11 ru...
bool hasUserDeclaredConstructor() const
Determine whether this class has any user-declared constructors.
bool isPOD() const
Whether this class is a POD-type (C++ [class]p4)
MSVtorDispMode getMSVtorDispMode() const
Controls when vtordisps will be emitted if this record is used as a virtual base.
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
bool isTrivial() const
Determine whether this class is considered trivial.
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
CXXRecordDecl * getDefinition() const
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
CharUnits alignTo(const CharUnits &Align) const
alignTo - Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is ...
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Complex values, per C99 6.2.5p11.
Represents the canonical version of C arrays with a specified constant size.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Decl - This represents one declaration (or definition), e.g.
unsigned getMaxAlignment() const
getMaxAlignment - return the maximum alignment specified by attributes on this decl,...
bool isInvalidDecl() const
SourceLocation getLocation() const
A little helper class used to produce diagnostics.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Abstract interface for external sources of AST nodes.
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
unsigned getBitWidthValue(const ASTContext &Ctx) const
Computes the bit width of this field, if this is a bit field.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
bool isPotentiallyOverlapping() const
Determine if this field is of potentially-overlapping class type, that is, subobject with the [[no_un...
Represents a function declaration or definition.
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Represents a field injected from an anonymous union/struct into the parent scope.
ArrayRef< NamedDecl * > chain() const
@ Ver6
Attempt to be ABI-compatible with code generated by Clang 6.0.x (SVN r321711).
@ Ver15
Attempt to be ABI-compatible with code generated by Clang 15.0.x.
This represents a decl that may have a name.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
bool isExternallyVisible() const
ObjCContainerDecl - Represents a container for method declarations.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Represents an ObjC class declaration.
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
ObjCIvarDecl * all_declared_ivar_begin()
all_declared_ivar_begin - return first ivar declared in this class, its extensions and its implementa...
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
ObjCInterfaceDecl * getSuperClass() const
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCInterfaceDecl * getContainingInterface()
Return the class interface that this ivar is logically contained in; this is either the interface whe...
ObjCIvarDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this field.
ObjCIvarDecl * getNextIvar()
A (possibly-)qualified type.
Represents a struct/union/class.
bool isMsStruct(const ASTContext &C) const
Get whether or not this is an ms_struct which can be turned on with an attribute, pragma,...
bool hasFlexibleArrayMember() const
field_iterator field_end() const
field_range fields() const
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
specific_decl_iterator< FieldDecl > field_iterator
RecordDecl * getMostRecentDecl()
field_iterator field_begin() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
RecordDecl * getDecl() const
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Encodes a location in the source.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
TagKind getTagKind() const
The basic abstraction for the target C++ ABI.
TailPaddingUseRules getTailPaddingUseRules() const
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
bool canKeyFunctionBeInline() const
Can an out-of-line inline function serve as a key function?
@ AlwaysUseTailPadding
The tail-padding of a base class is always theoretically available, even if it's POD.
@ UseTailPaddingUnlessPOD11
Only allocate objects in the tail padding of a base class if the base class is not POD according to t...
@ UseTailPaddingUnlessPOD03
Only allocate objects in the tail padding of a base class if the base class is not POD according to t...
bool useLeadingZeroLengthBitfield() const
Check whether zero length bitfield alignment is respected if they are leading members.
uint64_t getPointerWidth(LangAS AddrSpace) const
Return the width of pointers on this target, for the specified address space.
virtual bool hasPS4DLLImportExport() const
virtual bool defaultsToAIXPowerAlignment() const
Whether target defaults to the power alignment rules of AIX.
unsigned getCharAlign() const
unsigned getZeroLengthBitfieldBoundary() const
Get the fixed alignment value in bits for a member that follows a zero length bitfield.
bool useExplicitBitFieldAlignment() const
Check whether explicit bitfield alignment attributes should be.
uint64_t getPointerAlign(LangAS AddrSpace) const
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
unsigned getCharWidth() const
bool useZeroLengthBitfieldAlignment() const
Check whether zero length bitfields should force alignment of the next member.
bool useBitFieldTypeAlignment() const
Check whether the alignment of bit-field types is respected when laying out structures.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isIncompleteArrayType() const
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
const T * getAs() const
Member-template getAs<specific type>'.
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
bool isRecordType() const
static bool hasVtableSlot(const CXXMethodDecl *MD)
Determine whether this function should be assigned a vtable slot.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Defines the clang::TargetInfo interface.
bool Zero(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
@ External
External linkage, which indicates that the entity can be referred to from other translation units.
TagTypeKind
The kind of a tag type.
@ Interface
The "__interface" keyword.
@ Struct
The "struct" keyword.
@ Class
The "class" keyword.
const FunctionProtoType * T
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
@ None
The alignment was not explicit in code.
@ RequiredByTypedef
The alignment comes from an alignment attribute on a typedef.
@ RequiredByRecord
The alignment comes from an alignment attribute on a record type.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
bool isValid() const
Whether this pointer is non-NULL.
bool isOffset() const
Whether this pointer is currently stored as an offset.
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer points to.
All virtual base related information about a given record decl.