Skip to content

Commit af1d477

Browse files
committed
[DebugInfo] Emit a MultiPayloadEnum's spare bits mask in DWARF
1 parent 11ef6e5 commit af1d477

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
10661066
for (VarDecl *VD : Decl->getStoredProperties()) {
10671067
auto memberTy = BaseTy->getTypeOfMember(IGM.getSwiftModule(), VD);
10681068

1069+
auto &TI = IGM.getTypeInfoForUnlowered(
1070+
IGM.getSILTypes().getAbstractionPattern(VD), memberTy);
1071+
10691072
if (auto DbgTy = CompletedDebugTypeInfo::getFromTypeInfo(
10701073
VD->getInterfaceType(),
10711074
IGM.getTypeInfoForUnlowered(
@@ -1186,6 +1189,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
11861189
llvm::DICompositeType *createVariantType(CompletedDebugTypeInfo DbgTy,
11871190
EnumDecl *Decl,
11881191
StringRef MangledName,
1192+
unsigned AlignInBits,
11891193
llvm::DIScope *Scope,
11901194
llvm::DIFile *File, unsigned Line,
11911195
llvm::DINode::DIFlags Flags) {
@@ -1195,7 +1199,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
11951199
StringRef Name = Decl->getName().str();
11961200
unsigned SizeInBits = DbgTy.getSizeInBits();
11971201
// Default, since Swift doesn't allow specifying a custom alignment.
1198-
unsigned AlignInBits = 0;
11991202
auto NumExtraInhabitants = DbgTy.getNumExtraInhabitants();
12001203

12011204
// A variant part should actually be a child to a DW_TAG_structure_type
@@ -1235,27 +1238,42 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
12351238
Elements.push_back(MTy);
12361239
}
12371240
}
1238-
auto VPTy = DBuilder.createVariantPart(Scope, {}, File, Line, SizeInBits,
1239-
AlignInBits, Flags, nullptr,
1240-
DBuilder.getOrCreateArray(Elements));
1241+
1242+
APInt SpareBitsMask;
1243+
auto &EnumStrategy =
1244+
getEnumImplStrategy(IGM, DbgTy.getType()->getCanonicalType());
1245+
1246+
auto VariantOffsetInBits = 0;
1247+
if (auto SpareBitsMaskInfo = EnumStrategy.calculateSpareBitsMask()) {
1248+
SpareBitsMask = SpareBitsMaskInfo->bits;
1249+
// The offset of the variant mask in the overall enum.
1250+
VariantOffsetInBits = SpareBitsMaskInfo->byteOffset * 8;
1251+
}
1252+
1253+
auto VPTy = DBuilder.createVariantPart(
1254+
Scope, {}, File, Line, SizeInBits, AlignInBits, Flags, nullptr,
1255+
DBuilder.getOrCreateArray(Elements), /*UniqueIdentifier=*/"",
1256+
VariantOffsetInBits, SpareBitsMask);
1257+
12411258
auto DITy = DBuilder.createStructType(
12421259
Scope, Name, File, Line, SizeInBits, AlignInBits, Flags, nullptr,
12431260
DBuilder.getOrCreateArray(VPTy), llvm::dwarf::DW_LANG_Swift, nullptr,
1244-
MangledName, NumExtraInhabitants ? *NumExtraInhabitants : 0);
1261+
MangledName, NumExtraInhabitants.value_or(0));
12451262
DBuilder.replaceTemporary(std::move(FwdDecl), DITy);
12461263
return DITy;
12471264
}
12481265

12491266
llvm::DICompositeType *createEnumType(CompletedDebugTypeInfo DbgTy,
12501267
EnumDecl *Decl, StringRef MangledName,
1268+
unsigned AlignInBits,
12511269
llvm::DIScope *Scope,
12521270
llvm::DIFile *File, unsigned Line,
12531271
llvm::DINode::DIFlags Flags) {
12541272
if (Decl->hasRawType())
12551273
return createRawEnumType(DbgTy, Decl, MangledName, Scope, File, Line,
12561274
Flags);
1257-
return createVariantType(DbgTy, Decl, MangledName, Scope, File, Line,
1258-
Flags);
1275+
return createVariantType(DbgTy, Decl, MangledName, AlignInBits, Scope, File,
1276+
Line, Flags);
12591277
}
12601278

12611279
llvm::DIType *getOrCreateDesugaredType(Type Ty, DebugTypeInfo DbgTy) {
@@ -1868,8 +1886,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
18681886
unsigned FwdDeclLine = 0;
18691887
if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes)
18701888
if (auto CompletedDbgTy = CompletedDebugTypeInfo::get(DbgTy))
1871-
return createEnumType(*CompletedDbgTy, Decl, MangledName, Scope,
1872-
L.File, L.Line, Flags);
1889+
return createEnumType(*CompletedDbgTy, Decl, MangledName, AlignInBits,
1890+
Scope, L.File, L.Line, Flags);
18731891
return createOpaqueStruct(Scope, Decl->getName().str(), L.File,
18741892
FwdDeclLine, SizeInBits, AlignInBits, Flags,
18751893
MangledName);

test/DebugInfo/enum.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ enum Either {
2828
// CHECK: ![[EMPTY:.*]] = !{}
2929
let E : Either = .Neither;
3030

31+
class C {}
32+
enum EitherWithSpareBits {
33+
case Left(C), Right(Int32)
34+
// DWARF: !DICompositeType(tag: DW_TAG_structure_type, name: "EitherWithSpareBits",
35+
// DWARF-SAME: size: 64,
36+
// DWARF-SAME: runtimeLang: DW_LANG_Swift, identifier: "$s4enum19EitherWithSpareBitsOD")
37+
38+
// DWARF: !DICompositeType(tag: DW_TAG_variant_part,
39+
// DWARF-SAME: size: 64, offset: 56, spare_bits_mask: {{240|255}}
40+
41+
// DWARF: !DIDerivedType(tag: DW_TAG_member, name: "Left"
42+
43+
// DWARF: !DIDerivedType(tag: DW_TAG_member, name: "Right"
44+
}
45+
let Right: EitherWithSpareBits = .Right(32)
46+
3147
// CHECK: !DICompositeType({{.*}}name: "Color",
3248
// CHECK-SAME: size: 8,
3349
// CHECK-SAME: identifier: "$s4enum5ColorOD"
@@ -102,3 +118,6 @@ public enum List<T> {
102118
// CHECK-DAG: ![[LIST_MEMBER]] = !DIDerivedType(tag: DW_TAG_member, {{.*}} baseType: ![[LIST:[0-9]+]]
103119
// CHECK-DAG: ![[LIST]] = !DICompositeType({{.*}}name: "$s4enum4ListOyxGD",{{.*}}DIFlagFwdDecl
104120
}
121+
122+
123+

0 commit comments

Comments
 (0)