Skip to content

Commit 575f1d8

Browse files
committed
[DebugInfo] Use underlying type of global variables with opaque type
rdar://144881938
1 parent ecc9093 commit 575f1d8

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,6 +3869,14 @@ void IRGenDebugInfoImpl::emitGlobalVariableDeclaration(
38693869
if (Opts.DebugInfoLevel <= IRGenDebugInfoLevel::LineTables)
38703870
return;
38713871

3872+
// If this global variable contains an opaque type, replace it with its
3873+
// underlying type.
3874+
if (auto UnderlyingType = IGM.substOpaqueTypesWithUnderlyingTypes(
3875+
DbgTy.getType()->getCanonicalType())) {
3876+
auto &TI = IGM.getTypeInfoForUnlowered(UnderlyingType);
3877+
DbgTy = DebugTypeInfo::getFromTypeInfo(UnderlyingType, TI, IGM);
3878+
}
3879+
38723880
llvm::DIType *DITy = getOrCreateType(DbgTy);
38733881
VarDecl *VD = nullptr;
38743882
if (Loc)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-swift-frontend -primary-file %s -emit-ir -g -o - | %FileCheck %s
2+
3+
public protocol TheProtocol {}
4+
5+
public class TheClass: TheProtocol {
6+
}
7+
8+
struct TheStruct<T> {
9+
let t: T
10+
}
11+
12+
func f() -> some TheProtocol {
13+
let p: some TheProtocol = TheClass()
14+
return p
15+
}
16+
17+
let v = f()
18+
// CHECK: !DIGlobalVariable(name: "v", {{.*}}type: ![[CONST_TYPE:[0-9]+]]
19+
// CHECK: ![[CONST_TYPE]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[TYPE:[0-9]+]])
20+
// CHECK: ![[TYPE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "TheClass"
21+
22+
let v2 = TheStruct(t: f())
23+
// CHECK: !DIGlobalVariable(name: "v2", {{.*}}type: ![[CONST_TYPE_GEN:[0-9]+]]
24+
// CHECK: ![[CONST_TYPE_GEN]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[TYPE_GEN_1:[0-9]+]])
25+
// CHECK: ![[TYPE_GEN_1]] = !DICompositeType(tag: DW_TAG_structure_type{{.*}}elements: ![[TYPE_GEN_2:[0-9]+]]
26+
// CHECK: ![[TYPE_GEN_2]] = !{![[TYPE_GEN_3:[0-9]+]]}
27+
// CHECK: ![[TYPE_GEN_3]] = !DIDerivedType(tag: DW_TAG_member{{.*}}baseType: ![[TYPE_GEN:[0-9]+]]
28+
// CHECK: ![[TYPE_GEN]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$s17global_opaque_var9TheStructVyAA0D5ClassCGD"

0 commit comments

Comments
 (0)