Skip to content

Commit 75e45bd

Browse files
committed
Emit extra inhabitants in debug info for basic types
To support debugging embedded Swift, we will need to store information that previously we searched in metadata. Extra inhabitants is one of those.
1 parent 9aa1772 commit 75e45bd

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

lib/IRGen/DebugTypeInfo.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ DebugTypeInfo::DebugTypeInfo(swift::Type Ty, llvm::Type *FragmentStorageTy,
2929
llvm::Optional<Size::int_type> SizeInBits,
3030
Alignment Align, bool HasDefaultAlignment,
3131
bool IsMetadata, bool SizeIsFragmentSize,
32-
bool IsFixedBuffer)
32+
bool IsFixedBuffer,
33+
std::optional<uint32_t> NumExtraInhabitants)
3334
: Type(Ty.getPointer()), FragmentStorageType(FragmentStorageTy),
34-
SizeInBits(SizeInBits), Align(Align),
35-
DefaultAlignment(HasDefaultAlignment), IsMetadataType(IsMetadata),
36-
SizeIsFragmentSize(SizeIsFragmentSize), IsFixedBuffer(IsFixedBuffer) {
35+
SizeInBits(SizeInBits), NumExtraInhabitants(NumExtraInhabitants),
36+
Align(Align), DefaultAlignment(HasDefaultAlignment),
37+
IsMetadataType(IsMetadata), SizeIsFragmentSize(SizeIsFragmentSize),
38+
IsFixedBuffer(IsFixedBuffer) {
3739
assert(Align.getValue() != 0);
3840
}
3941

@@ -52,17 +54,22 @@ DebugTypeInfo DebugTypeInfo::getFromTypeInfo(swift::Type Ty, const TypeInfo &TI,
5254
bool IsFragmentTypeInfo) {
5355
llvm::Optional<Size::int_type> SizeInBits;
5456
llvm::Type *StorageType = TI.getStorageType();
57+
std::optional<uint32_t> NumExtraInhabitants;
5558
if (StorageType->isSized())
5659
SizeInBits = IGM.DataLayout.getTypeSizeInBits(StorageType);
5760
else if (TI.isFixedSize()) {
5861
const FixedTypeInfo &FixTy = *cast<const FixedTypeInfo>(&TI);
5962
Size::int_type Size = FixTy.getFixedSize().getValue() * 8;
6063
SizeInBits = Size;
6164
}
65+
if (TI.isFixedSize()) {
66+
const FixedTypeInfo &FixTy = *cast<const FixedTypeInfo>(&TI);
67+
NumExtraInhabitants = FixTy.getFixedExtraInhabitantCount(IGM);
68+
}
6269
assert(TI.getStorageType() && "StorageType is a nullptr");
6370
return DebugTypeInfo(Ty.getPointer(), StorageType, SizeInBits,
6471
TI.getBestKnownAlignment(), ::hasDefaultAlignment(Ty),
65-
false, IsFragmentTypeInfo);
72+
false, IsFragmentTypeInfo, false, NumExtraInhabitants);
6673
}
6774

6875
DebugTypeInfo DebugTypeInfo::getLocalVariable(VarDecl *Decl, swift::Type Ty,

lib/IRGen/DebugTypeInfo.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class DebugTypeInfo {
4545
/// the storage type for undefined variables.
4646
llvm::Type *FragmentStorageType = nullptr;
4747
llvm::Optional<Size::int_type> SizeInBits;
48+
std::optional<uint32_t> NumExtraInhabitants;
4849
Alignment Align;
4950
bool DefaultAlignment = true;
5051
bool IsMetadataType = false;
@@ -57,7 +58,8 @@ class DebugTypeInfo {
5758
llvm::Optional<Size::int_type> SizeInBits = {},
5859
Alignment AlignInBytes = Alignment(1),
5960
bool HasDefaultAlignment = true, bool IsMetadataType = false,
60-
bool IsFragmentTypeInfo = false, bool IsFixedBuffer = false);
61+
bool IsFragmentTypeInfo = false, bool IsFixedBuffer = false,
62+
std::optional<uint32_t> NumExtraInhabitants = {});
6163

6264
/// Create type for a local variable.
6365
static DebugTypeInfo getLocalVariable(VarDecl *Decl, swift::Type Ty,
@@ -119,6 +121,9 @@ class DebugTypeInfo {
119121
bool hasDefaultAlignment() const { return DefaultAlignment; }
120122
bool isSizeFragmentSize() const { return SizeIsFragmentSize; }
121123
bool isFixedBuffer() const { return IsFixedBuffer; }
124+
std::optional<uint32_t> getNumExtraInhabitants() const {
125+
return NumExtraInhabitants;
126+
}
122127

123128
bool operator==(DebugTypeInfo T) const;
124129
bool operator!=(DebugTypeInfo T) const;

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
13631363
? 0
13641364
: DbgTy.getAlignment().getValue() * SizeOfByte;
13651365
unsigned Encoding = 0;
1366+
uint32_t NumExtraInhabitants = 0;
13661367
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
13671368

13681369
TypeBase *BaseTy = DbgTy.getType();
@@ -1386,13 +1387,17 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
13861387
Encoding = llvm::dwarf::DW_ATE_unsigned;
13871388
if (auto CompletedDbgTy = CompletedDebugTypeInfo::get(DbgTy))
13881389
SizeInBits = getSizeOfBasicType(*CompletedDbgTy);
1390+
if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants())
1391+
NumExtraInhabitants = *DbgTyNumExtraInhabitants;
13891392
break;
13901393
}
13911394

13921395
case TypeKind::BuiltinIntegerLiteral: {
13931396
Encoding = llvm::dwarf::DW_ATE_unsigned; // ?
13941397
if (auto CompletedDbgTy = CompletedDebugTypeInfo::get(DbgTy))
13951398
SizeInBits = getSizeOfBasicType(*CompletedDbgTy);
1399+
if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants())
1400+
NumExtraInhabitants = *DbgTyNumExtraInhabitants;
13961401
break;
13971402
}
13981403

@@ -1401,6 +1406,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
14011406
// Assuming that the bitwidth and FloatTy->getFPKind() are identical.
14021407
SizeInBits = FloatTy->getBitWidth();
14031408
Encoding = llvm::dwarf::DW_ATE_float;
1409+
if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants())
1410+
NumExtraInhabitants = *DbgTyNumExtraInhabitants;
14041411
break;
14051412
}
14061413

@@ -1726,7 +1733,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
17261733
DebugTypeInfo AliasedDbgTy(
17271734
AliasedTy, DbgTy.getFragmentStorageType(), DbgTy.getRawSizeInBits(),
17281735
DbgTy.getAlignment(), DbgTy.hasDefaultAlignment(), false,
1729-
DbgTy.isSizeFragmentSize(), DbgTy.isFixedBuffer());
1736+
DbgTy.isSizeFragmentSize(), DbgTy.isFixedBuffer(),
1737+
DbgTy.getNumExtraInhabitants());
17301738
return DBuilder.createTypedef(getOrCreateType(AliasedDbgTy), MangledName,
17311739
File, 0, Scope);
17321740
}
@@ -1774,7 +1782,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
17741782
DbgTy.getType()->dump(llvm::dbgs()); llvm::dbgs() << "\n");
17751783
MangledName = "<unknown>";
17761784
}
1777-
return DBuilder.createBasicType(MangledName, SizeInBits, Encoding);
1785+
return DBuilder.createBasicType(MangledName, SizeInBits, Encoding,
1786+
llvm::DINode::FlagZero,
1787+
NumExtraInhabitants);
17781788
}
17791789

17801790
/// Determine if there exists a name mangling for the given type.

test/DebugInfo/bool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
func markUsed<T>(_ t: T) {}
66

77
// Int1 uses 1 bit, but is aligned at 8 bits.
8-
// CHECK: !DIBasicType(name: "$sBi1_D", size: 1, encoding: DW_ATE_unsigned)
8+
// CHECK: !DIBasicType(name: "$sBi1_D", size: 1, encoding: DW_ATE_unsigned, num_extra_inhabitants: 254)
99
// Bool has a fixed layout with a storage size of 1 byte and 7 "spare" bits.
1010
// CHECK_G: !DICompositeType(tag: DW_TAG_structure_type, name: "Bool",
1111
// CHECK_G-SAME: size: 8

0 commit comments

Comments
 (0)