Skip to content

Commit 89d458b

Browse files
committed
Emit num_extra_inhabitants in DWARF
Swift types have the concept of "extra inhabitants". An extra inhabitant is a bit pattern that does not represent a valid value for objects of a given type. Add a new Apple DWARF extension, APPLE_num_extra_inhabitants, to encode this information in DWARF.
1 parent 17bd0c7 commit 89d458b

File tree

13 files changed

+208
-111
lines changed

13 files changed

+208
-111
lines changed

llvm/include/llvm/BinaryFormat/Dwarf.def

+1
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ HANDLE_DW_AT(0x3fec, APPLE_objc_complete_type, 0, APPLE)
628628
HANDLE_DW_AT(0x3fed, APPLE_property, 0, APPLE)
629629
HANDLE_DW_AT(0x3fee, APPLE_objc_direct, 0, APPLE)
630630
HANDLE_DW_AT(0x3fef, APPLE_sdk, 0, APPLE)
631+
HANDLE_DW_AT(0x3ff0, APPLE_num_extra_inhabitants, 0, APPLE)
631632

632633
// Attribute form encodings.
633634
HANDLE_DW_FORM(0x01, addr, 2, DWARF)

llvm/include/llvm/IR/DIBuilder.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,13 @@ namespace llvm {
216216
/// \param SizeInBits Size of the type.
217217
/// \param Encoding DWARF encoding code, e.g., dwarf::DW_ATE_float.
218218
/// \param Flags Optional DWARF attributes, e.g., DW_AT_endianity.
219+
/// \param NumExtraInhabitants The number of extra inhabitants of the type.
220+
/// An extra inhabitant is a bit pattern that does not represent a valid
221+
/// value for objects of a given type.
219222
DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits,
220223
unsigned Encoding,
221-
DINode::DIFlags Flags = DINode::FlagZero);
224+
DINode::DIFlags Flags = DINode::FlagZero,
225+
uint32_t NumExtraInhabitants = 0);
222226

223227
/// Create debugging information entry for a string
224228
/// type.
@@ -453,11 +457,15 @@ namespace llvm {
453457
/// \param Elements Struct elements.
454458
/// \param RunTimeLang Optional parameter, Objective-C runtime version.
455459
/// \param UniqueIdentifier A unique identifier for the struct.
460+
/// \param NumExtraInhabitants The number of extra inhabitants of the type.
461+
/// An extra inhabitant is a bit pattern that does not represent a valid
462+
/// value for objects of a given type.
456463
DICompositeType *createStructType(
457464
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
458465
uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
459466
DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang = 0,
460-
DIType *VTableHolder = nullptr, StringRef UniqueIdentifier = "");
467+
DIType *VTableHolder = nullptr, StringRef UniqueIdentifier = "",
468+
uint32_t NumExtraInhabitants = 0);
461469

462470
/// Create debugging information entry for an union.
463471
/// \param Scope Scope in which this union is defined.

llvm/include/llvm/IR/DebugInfoMetadata.h

+73-55
Original file line numberDiff line numberDiff line change
@@ -701,31 +701,36 @@ class DIType : public DIScope {
701701
uint64_t SizeInBits;
702702
uint64_t OffsetInBits;
703703
uint32_t AlignInBits;
704+
uint32_t NumExtraInhabitants;
704705

705706
protected:
706707
DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
707708
unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
708-
uint64_t OffsetInBits, DIFlags Flags, ArrayRef<Metadata *> Ops)
709+
uint64_t OffsetInBits, uint32_t NumExtraInhabitants, DIFlags Flags,
710+
ArrayRef<Metadata *> Ops)
709711
: DIScope(C, ID, Storage, Tag, Ops) {
710-
init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
712+
init(Line, SizeInBits, AlignInBits, OffsetInBits, NumExtraInhabitants,
713+
Flags);
711714
}
712715
~DIType() = default;
713716

714717
void init(unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
715-
uint64_t OffsetInBits, DIFlags Flags) {
718+
uint64_t OffsetInBits, uint32_t NumExtraInhabitants,
719+
DIFlags Flags) {
716720
this->Line = Line;
717721
this->Flags = Flags;
718722
this->SizeInBits = SizeInBits;
719723
this->AlignInBits = AlignInBits;
720724
this->OffsetInBits = OffsetInBits;
725+
this->NumExtraInhabitants = NumExtraInhabitants;
721726
}
722727

723728
/// Change fields in place.
724729
void mutate(unsigned Tag, unsigned Line, uint64_t SizeInBits,
725-
uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags) {
730+
uint32_t AlignInBits, uint64_t OffsetInBits, uint32_t NumExtraInhabitants, DIFlags Flags) {
726731
assert(isDistinct() && "Only distinct nodes can mutate");
727732
setTag(Tag);
728-
init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
733+
init(Line, SizeInBits, AlignInBits, OffsetInBits, NumExtraInhabitants, Flags);
729734
}
730735

731736
public:
@@ -738,6 +743,7 @@ class DIType : public DIScope {
738743
uint32_t getAlignInBits() const { return AlignInBits; }
739744
uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
740745
uint64_t getOffsetInBits() const { return OffsetInBits; }
746+
uint32_t getNumExtraInhabitants() const { return NumExtraInhabitants; }
741747
DIFlags getFlags() const { return Flags; }
742748

743749
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
@@ -809,49 +815,55 @@ class DIBasicType : public DIType {
809815

810816
DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
811817
uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
812-
DIFlags Flags, ArrayRef<Metadata *> Ops)
818+
uint32_t NumExtraInhabitants, DIFlags Flags,
819+
ArrayRef<Metadata *> Ops)
813820
: DIType(C, DIBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
814-
Flags, Ops),
821+
NumExtraInhabitants, Flags, Ops),
815822
Encoding(Encoding) {}
816823
~DIBasicType() = default;
817824

818825
static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
819826
StringRef Name, uint64_t SizeInBits,
820827
uint32_t AlignInBits, unsigned Encoding,
821-
DIFlags Flags, StorageType Storage,
822-
bool ShouldCreate = true) {
828+
uint32_t NumExtraInhabitants, DIFlags Flags,
829+
StorageType Storage, bool ShouldCreate = true) {
823830
return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
824-
SizeInBits, AlignInBits, Encoding, Flags, Storage,
825-
ShouldCreate);
831+
SizeInBits, AlignInBits, Encoding, NumExtraInhabitants,
832+
Flags, Storage, ShouldCreate);
826833
}
827834
static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
828835
MDString *Name, uint64_t SizeInBits,
829836
uint32_t AlignInBits, unsigned Encoding,
830-
DIFlags Flags, StorageType Storage,
831-
bool ShouldCreate = true);
837+
uint32_t NumExtraInhabitants, DIFlags Flags,
838+
StorageType Storage, bool ShouldCreate = true);
832839

833840
TempDIBasicType cloneImpl() const {
834841
return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
835-
getAlignInBits(), getEncoding(), getFlags());
842+
getAlignInBits(), getEncoding(),
843+
getNumExtraInhabitants(), getFlags());
836844
}
837845

838846
public:
839847
DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, StringRef Name),
840-
(Tag, Name, 0, 0, 0, FlagZero))
848+
(Tag, Name, 0, 0, 0, 0, FlagZero))
841849
DEFINE_MDNODE_GET(DIBasicType,
842850
(unsigned Tag, StringRef Name, uint64_t SizeInBits),
843-
(Tag, Name, SizeInBits, 0, 0, FlagZero))
851+
(Tag, Name, SizeInBits, 0, 0, 0, FlagZero))
844852
DEFINE_MDNODE_GET(DIBasicType,
845853
(unsigned Tag, MDString *Name, uint64_t SizeInBits),
846-
(Tag, Name, SizeInBits, 0, 0, FlagZero))
854+
(Tag, Name, SizeInBits, 0, 0, 0, FlagZero))
847855
DEFINE_MDNODE_GET(DIBasicType,
848856
(unsigned Tag, StringRef Name, uint64_t SizeInBits,
849-
uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
850-
(Tag, Name, SizeInBits, AlignInBits, Encoding, Flags))
857+
uint32_t AlignInBits, unsigned Encoding,
858+
uint32_t NumExtraInhabitants, DIFlags Flags),
859+
(Tag, Name, SizeInBits, AlignInBits, Encoding,
860+
NumExtraInhabitants, Flags))
851861
DEFINE_MDNODE_GET(DIBasicType,
852862
(unsigned Tag, MDString *Name, uint64_t SizeInBits,
853-
uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
854-
(Tag, Name, SizeInBits, AlignInBits, Encoding, Flags))
863+
uint32_t AlignInBits, unsigned Encoding,
864+
uint32_t NumExtraInhabitants, DIFlags Flags),
865+
(Tag, Name, SizeInBits, AlignInBits, Encoding,
866+
NumExtraInhabitants, Flags))
855867

856868
TempDIBasicType clone() const { return cloneImpl(); }
857869

@@ -879,7 +891,7 @@ class DIStringType : public DIType {
879891
uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
880892
ArrayRef<Metadata *> Ops)
881893
: DIType(C, DIStringTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
882-
FlagZero, Ops),
894+
0, FlagZero, Ops),
883895
Encoding(Encoding) {}
884896
~DIStringType() = default;
885897

@@ -998,10 +1010,11 @@ class DIDerivedType : public DIType {
9981010
DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
9991011
unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
10001012
uint64_t OffsetInBits,
1001-
std::optional<unsigned> DWARFAddressSpace, std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1013+
std::optional<unsigned> DWARFAddressSpace,
1014+
std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
10021015
ArrayRef<Metadata *> Ops)
10031016
: DIType(C, DIDerivedTypeKind, Storage, Tag, Line, SizeInBits,
1004-
AlignInBits, OffsetInBits, Flags, Ops),
1017+
AlignInBits, OffsetInBits, 0, Flags, Ops),
10051018
DWARFAddressSpace(DWARFAddressSpace) {
10061019
if (PtrAuthData)
10071020
SubclassData32 = PtrAuthData->Payload.RawData;
@@ -1145,39 +1158,43 @@ class DICompositeType : public DIType {
11451158

11461159
DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
11471160
unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
1148-
uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
1161+
uint32_t AlignInBits, uint64_t OffsetInBits,
1162+
uint32_t NumExtraInhabitants, DIFlags Flags,
11491163
ArrayRef<Metadata *> Ops)
11501164
: DIType(C, DICompositeTypeKind, Storage, Tag, Line, SizeInBits,
1151-
AlignInBits, OffsetInBits, Flags, Ops),
1165+
AlignInBits, OffsetInBits, NumExtraInhabitants, Flags, Ops),
11521166
RuntimeLang(RuntimeLang) {}
11531167
~DICompositeType() = default;
11541168

11551169
/// Change fields in place.
11561170
void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
11571171
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
1158-
DIFlags Flags) {
1172+
uint32_t NumExtraInhabitants, DIFlags Flags) {
11591173
assert(isDistinct() && "Only distinct nodes can mutate");
11601174
assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate");
11611175
this->RuntimeLang = RuntimeLang;
1162-
DIType::mutate(Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
1176+
DIType::mutate(Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
1177+
NumExtraInhabitants, Flags);
11631178
}
11641179

11651180
static DICompositeType *
11661181
getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
11671182
unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1168-
uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
1169-
DINodeArray Elements, unsigned RuntimeLang, DIType *VTableHolder,
1183+
uint32_t AlignInBits, uint64_t OffsetInBits,
1184+
uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
1185+
unsigned RuntimeLang, DIType *VTableHolder,
11701186
DITemplateParameterArray TemplateParams, StringRef Identifier,
11711187
DIDerivedType *Discriminator, Metadata *DataLocation,
11721188
Metadata *Associated, Metadata *Allocated, Metadata *Rank,
11731189
DINodeArray Annotations, StorageType Storage,
11741190
bool ShouldCreate = true) {
1175-
return getImpl(
1176-
Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
1177-
BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(),
1178-
RuntimeLang, VTableHolder, TemplateParams.get(),
1179-
getCanonicalMDString(Context, Identifier), Discriminator, DataLocation,
1180-
Associated, Allocated, Rank, Annotations.get(), Storage, ShouldCreate);
1191+
return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1192+
Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
1193+
Flags, Elements.get(), RuntimeLang, VTableHolder,
1194+
TemplateParams.get(),
1195+
getCanonicalMDString(Context, Identifier), Discriminator,
1196+
DataLocation, Associated, Allocated, Rank, Annotations.get(),
1197+
NumExtraInhabitants, Storage, ShouldCreate);
11811198
}
11821199
static DICompositeType *
11831200
getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
@@ -1187,7 +1204,8 @@ class DICompositeType : public DIType {
11871204
Metadata *VTableHolder, Metadata *TemplateParams,
11881205
MDString *Identifier, Metadata *Discriminator, Metadata *DataLocation,
11891206
Metadata *Associated, Metadata *Allocated, Metadata *Rank,
1190-
Metadata *Annotations, StorageType Storage, bool ShouldCreate = true);
1207+
Metadata *Annotations, uint32_t NumExtraInhabitants,
1208+
StorageType Storage, bool ShouldCreate = true);
11911209

11921210
TempDICompositeType cloneImpl() const {
11931211
return getTemporary(
@@ -1196,7 +1214,7 @@ class DICompositeType : public DIType {
11961214
getFlags(), getElements(), getRuntimeLang(), getVTableHolder(),
11971215
getTemplateParams(), getIdentifier(), getDiscriminator(),
11981216
getRawDataLocation(), getRawAssociated(), getRawAllocated(),
1199-
getRawRank(), getAnnotations());
1217+
getRawRank(), getAnnotations(), getNumExtraInhabitants());
12001218
}
12011219

12021220
public:
@@ -1210,11 +1228,11 @@ class DICompositeType : public DIType {
12101228
StringRef Identifier = "", DIDerivedType *Discriminator = nullptr,
12111229
Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
12121230
Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1213-
DINodeArray Annotations = nullptr),
1231+
DINodeArray Annotations = nullptr, uint32_t NumExtraInhabitants = 0),
12141232
(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits,
1215-
OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
1216-
Identifier, Discriminator, DataLocation, Associated, Allocated, Rank,
1217-
Annotations))
1233+
OffsetInBits, NumExtraInhabitants, Flags, Elements, RuntimeLang,
1234+
VTableHolder, TemplateParams, Identifier, Discriminator, DataLocation,
1235+
Associated, Allocated, Rank, Annotations))
12181236
DEFINE_MDNODE_GET(
12191237
DICompositeType,
12201238
(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
@@ -1224,11 +1242,12 @@ class DICompositeType : public DIType {
12241242
Metadata *TemplateParams = nullptr, MDString *Identifier = nullptr,
12251243
Metadata *Discriminator = nullptr, Metadata *DataLocation = nullptr,
12261244
Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1227-
Metadata *Rank = nullptr, Metadata *Annotations = nullptr),
1245+
Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1246+
uint32_t NumExtraInhabitants = 0),
12281247
(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits,
12291248
OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
12301249
Identifier, Discriminator, DataLocation, Associated, Allocated, Rank,
1231-
Annotations))
1250+
Annotations, NumExtraInhabitants))
12321251

12331252
TempDICompositeType clone() const { return cloneImpl(); }
12341253

@@ -1243,8 +1262,8 @@ class DICompositeType : public DIType {
12431262
getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
12441263
MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
12451264
Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits,
1246-
uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements,
1247-
unsigned RuntimeLang, Metadata *VTableHolder,
1265+
uint64_t OffsetInBits, uint32_t NumExtraInhabitants, DIFlags Flags,
1266+
Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
12481267
Metadata *TemplateParams, Metadata *Discriminator,
12491268
Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
12501269
Metadata *Rank, Metadata *Annotations);
@@ -1260,15 +1279,14 @@ class DICompositeType : public DIType {
12601279
///
12611280
/// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
12621281
/// nullptr.
1263-
static DICompositeType *
1264-
buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1265-
MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1266-
Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits,
1267-
uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements,
1268-
unsigned RuntimeLang, Metadata *VTableHolder,
1269-
Metadata *TemplateParams, Metadata *Discriminator,
1270-
Metadata *DataLocation, Metadata *Associated,
1271-
Metadata *Allocated, Metadata *Rank, Metadata *Annotations);
1282+
static DICompositeType *buildODRType(
1283+
LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
1284+
Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
1285+
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
1286+
uint32_t NumExtraInhabitants, DIFlags Flags, Metadata *Elements,
1287+
unsigned RuntimeLang, Metadata *VTableHolder, Metadata *TemplateParams,
1288+
Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated,
1289+
Metadata *Allocated, Metadata *Rank, Metadata *Annotations);
12721290

12731291
DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
12741292
DINodeArray getElements() const {

0 commit comments

Comments
 (0)