Skip to content

Commit 10d263b

Browse files
committed
[DebugInfo] Fix bound generic types debug info generation
When generating full debug info for generic types, emit the specification type as an opaque struct with the collection of substituted generic parameters.
1 parent ab9e07d commit 10d263b

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,11 +1184,10 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
11841184
return OpaqueType;
11851185
}
11861186

1187-
auto *opaqueType = createOpaqueStructWithSizedContainer(
1188-
Scope, Decl ? Decl->getNameStr() : "", File, Line, SizeInBits,
1189-
AlignInBits, Flags, MangledName, collectGenericParams(Type),
1190-
UnsubstitutedType);
1191-
return opaqueType;
1187+
auto *OpaqueType = createOpaqueStruct(
1188+
Scope, "", File, Line, SizeInBits, AlignInBits, Flags, MangledName,
1189+
collectGenericParams(Type), UnsubstitutedType);
1190+
return OpaqueType;
11921191
}
11931192

11941193
/// Create debug information for an enum with a raw type (enum E : Int {}).
@@ -1624,12 +1623,19 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
16241623
llvm::DICompositeType *
16251624
createOpaqueStruct(llvm::DIScope *Scope, StringRef Name, llvm::DIFile *File,
16261625
unsigned Line, unsigned SizeInBits, unsigned AlignInBits,
1627-
llvm::DINode::DIFlags Flags, StringRef MangledName) {
1628-
return DBuilder.createStructType(
1626+
llvm::DINode::DIFlags Flags, StringRef MangledName,
1627+
llvm::DINodeArray BoundParams = {},
1628+
llvm::DIType *SpecificationOf = nullptr) {
1629+
1630+
auto StructType = DBuilder.createStructType(
16291631
Scope, Name, File, Line, SizeInBits, AlignInBits, Flags,
16301632
/* DerivedFrom */ nullptr,
16311633
DBuilder.getOrCreateArray(ArrayRef<llvm::Metadata *>()),
1632-
llvm::dwarf::DW_LANG_Swift, nullptr, MangledName);
1634+
llvm::dwarf::DW_LANG_Swift, nullptr, MangledName, SpecificationOf);
1635+
1636+
if (BoundParams)
1637+
DBuilder.replaceArrays(StructType, nullptr, BoundParams);
1638+
return StructType;
16331639
}
16341640

16351641
bool shouldCacheDIType(llvm::DIType *DITy, DebugTypeInfo &DbgTy) {
@@ -2012,11 +2018,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
20122018
// Force the creation of the unsubstituted type, don't create it
20132019
// directly so it goes through all the caching/verification logic.
20142020
auto unsubstitutedDbgTy = getOrCreateType(DbgTy);
2015-
DBuilder.retainType(unsubstitutedDbgTy);
2016-
return createOpaqueStructWithSizedContainer(
2017-
Scope, Decl->getName().str(), L.File, FwdDeclLine, SizeInBits,
2018-
AlignInBits, Flags, MangledName, collectGenericParams(EnumTy),
2019-
unsubstitutedDbgTy);
2021+
return createOpaqueStruct(
2022+
Scope, "", L.File, FwdDeclLine, SizeInBits, AlignInBits, Flags,
2023+
MangledName, collectGenericParams(EnumTy), unsubstitutedDbgTy);
20202024
}
20212025
return createOpaqueStructWithSizedContainer(
20222026
Scope, Decl->getName().str(), L.File, FwdDeclLine, SizeInBits,

test/DebugInfo/BoundGenericStruct.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ public let s = S<Int>(t: 0)
1313
// CHECK: ![[INT]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$sSiD",
1414

1515

16-
// DWARF: !DICompositeType(tag: DW_TAG_structure_type, name: "$s18BoundGenericStruct1SVySiGD",
16+
// DWARF: !DICompositeType(tag: DW_TAG_structure_type,
1717
// DWARF-SAME: templateParams: ![[PARAMS:[0-9]+]]
18+
// DWARF-SAME: identifier: "$s18BoundGenericStruct1SVySiGD"
19+
// DWARF-SAME: specification_of:
20+
1821
// DWARF: ![[PARAMS]] = !{![[INTPARAM:[0-9]+]]}
1922
// DWARF: ![[INTPARAM]] = !DITemplateTypeParameter(type: ![[INT:[0-9]+]])
2023
// DWARF: ![[INT]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Int", {{.*}}identifier: "$sSiD"

0 commit comments

Comments
 (0)