Skip to content

Commit 7a69490

Browse files
committed
[Debug info] Retain all type aliases in asttypes mode
Bound generic types don't reference their type parameters in ASTTypes mode, so we need to artificially keep typealiases alive, since they can appear in reflection metadata. rdar://143595521
1 parent ed71c20 commit 7a69490

File tree

7 files changed

+27
-17
lines changed

7 files changed

+27
-17
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,8 +2182,14 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
21822182
DbgTy.getAlignment(), DbgTy.hasDefaultAlignment(),
21832183
/* IsMetadataType = */ false, DbgTy.isFixedBuffer(),
21842184
DbgTy.getNumExtraInhabitants());
2185-
return DBuilder.createTypedef(getOrCreateType(AliasedDbgTy), MangledName,
2186-
L.File, 0, Scope);
2185+
auto *TypeDef = DBuilder.createTypedef(getOrCreateType(AliasedDbgTy),
2186+
MangledName, L.File, 0, Scope);
2187+
// Bound generic types don't reference their type parameters in ASTTypes
2188+
// mode, so we need to artificially keep typealiases alive, since they can
2189+
// appear in reflection metadata.
2190+
if (Opts.DebugInfoLevel < IRGenDebugInfoLevel::DwarfTypes)
2191+
DBuilder.retainType(TypeDef);
2192+
return TypeDef;
21872193
}
21882194

21892195
case TypeKind::Locatable: {

test/DebugInfo/PrivateDiscriminator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// RUN: %target-swift-frontend %S/../Inputs/empty.swift -primary-file %s \
88
// RUN: -emit-ir -g | %FileCheck %s
99
// CHECK: !DICompileUnit({{.*}}flags: {{[^,]*}}-private-discriminator [[DISCRIMINATOR:_[A-Z0-9]+]]
10-
// CHECK: ![[MOD:.*]] = !DIModule(scope: null,
10+
// CHECK: ![[MOD:.*]] = !DIModule(scope: null, name: "empty"
1111
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "InA",
1212
// CHECK-SAME: scope: ![[A:[0-9]+]],
1313
// CHECK: ![[A]] = !DICompositeType(tag: DW_TAG_structure_type, name: "A",

test/DebugInfo/local_type_originally_defined_in.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import local_type_originally_defined_in_other
77

88
public func definedInOtherModule() {
99
let s = Sheep()
10-
// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "Sheep"{{.*}}identifier: "$s4Barn5SheepCD
10+
// CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "Sheep"{{.*}}identifier: "$s4Barn5SheepCD
1111
}
1212
public func localTypeAliasTest(horse: Horse) {
1313
// The local type mangling for 'A' mentions 'Horse', which must
@@ -18,7 +18,7 @@ public func localTypeAliasTest(horse: Horse) {
1818

1919
let info = UnsafeMutablePointer<A>.allocate(capacity: 1)
2020
_ = info
21-
// CHECK: DIDerivedType(tag: DW_TAG_typedef, name: "$s32local_type_originally_defined_in0A13TypeAliasTest5horsey4Barn5HorseV_tF1AL_aD"
21+
// CHECK-DAG: DIDerivedType(tag: DW_TAG_typedef, name: "$s32local_type_originally_defined_in0A13TypeAliasTest5horsey4Barn5HorseV_tF1AL_aD"
2222
}
2323

2424

@@ -31,7 +31,7 @@ public func localTypeTest(horse: Horse) {
3131

3232
let info = UnsafeMutablePointer<LocalStruct>.allocate(capacity: 1)
3333
_ = info
34-
// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "$s32local_type_originally_defined_in0A8TypeTest5horsey4Barn5HorseV_tF11LocalStructL_VD"
34+
// CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "$s32local_type_originally_defined_in0A8TypeTest5horsey4Barn5HorseV_tF11LocalStructL_VD"
3535
}
3636

3737
public func localTypeAliasTest() -> Horse {
@@ -40,7 +40,7 @@ public func localTypeAliasTest() -> Horse {
4040
let info = UnsafeMutablePointer<B>.allocate(capacity: 1)
4141
_ = info
4242
return Horse()
43-
// CHECK: DIDerivedType(tag: DW_TAG_typedef, name: "$s32local_type_originally_defined_in0A13TypeAliasTest4Barn5HorseVyF1BL_aD"
43+
// CHECK-DAG: DIDerivedType(tag: DW_TAG_typedef, name: "$s32local_type_originally_defined_in0A13TypeAliasTest4Barn5HorseVyF1BL_aD"
4444
}
4545

4646
public func localTypeAliasTestGeneric<T: Cow>(cow: T) {

test/DebugInfo/protocol-extension.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ public extension P {
1515
}
1616
}
1717

18-
// CHECK: ![[SELFMETA]] = !DILocalVariable(name: "$\CF\84_0_0",
19-
// CHECK-SAME: type: ![[SELFTY:[0-9]+]], flags: DIFlagArtificial)
20-
// CHECK: ![[SELFTY]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Self"
18+
// CHECK-DAG: ![[SELFMETA]] = !DILocalVariable(name: "$\CF\84_0_0", {{.*}}type: ![[SELFTY:[0-9]+]], flags: DIFlagArtificial)
19+
// CHECK-DAG: ![[SELFTY]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Self"

test/DebugInfo/test-foundation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MyObject : NSObject {
1818
// LOC-CHECK: ret
1919
@objc var MyArr = NSArray()
2020
// IMPORT-CHECK: filename: "{{.*}}test-foundation.swift"
21-
// IMPORT-CHECK-DAG: [[FOUNDATION:[0-9]+]] = !DIModule({{.*}} name: "Foundation",{{.*}} includePath: {{.*}}Foundation.framework
21+
// IMPORT-CHECK-DAG: [[FOUNDATION:[0-9]+]] = !DIModule({{.*}} name: "Foundation",{{.*}} includePath: {{.*}}Foundation.framework"
2222
// IMPORT-CHECK-DAG: [[OVERLAY:[0-9]+]] = !DIModule({{.*}} name: "Foundation",{{.*}} includePath: {{.*}}Foundation.swiftmodule
2323
// IMPORT-CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "NSArray", scope: ![[NSARRAY:[0-9]+]]
2424
// IMPORT-CHECK-DAG: ![[NSARRAY]] = !DIModule(scope: ![[FOUNDATION:[0-9]+]], name: "NSArray"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -parse-as-library -module-name a -g -o - | %FileCheck %s
2+
// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "$s1a10LocalAliasaD", {{.*}}baseType: ![[BASETY:[0-9]+]]
3+
// CHECK: ![[BASETY]]{{.*}}$sSbD
4+
public class MyClass<A, B> {}
5+
public typealias LocalAlias = Bool
6+
public typealias ClassAlias = MyClass<LocalAlias, Bool>
7+
public func use(cls: ClassAlias?) {}
8+

test/DebugInfo/typearg.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ class AClass : AProtocol {
99

1010
// CHECK: define hidden {{.*}}void @{{.*}}aFunction
1111
// CHECK: #dbg_declare(ptr %{{.*}}, ![[TYPEARG:.*]], !DIExpression(),
12-
// CHECK: ![[TYPEARG]] = !DILocalVariable(name: "$\CF\84_0_0"
13-
// CHECK-SAME: type: ![[SWIFTMETATYPE:[^,)]+]]
14-
// CHECK-SAME: flags: DIFlagArtificial
15-
// CHECK: ![[SWIFTMETATYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "T",
16-
// CHECK-SAME: baseType: ![[VOIDPTR:[0-9]+]]
17-
// CHECK: ![[VOIDPTR]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "$sBpD", baseType: null
12+
// CHECK-DAG: ![[TYPEARG]] = !DILocalVariable(name: "$\CF\84_0_0"{{.*}}type: ![[SWIFTMETATYPE:[^,)]+]]{{.*}}flags: DIFlagArtificial
13+
// CHECK-DAG: ![[SWIFTMETATYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "T",{{.*}}baseType: ![[VOIDPTR:[0-9]+]]
14+
// CHECK-DAG: ![[VOIDPTR]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "$sBpD", baseType: null
1815
func aFunction<T : AProtocol>(_ x: T) {
1916
print("I am in aFunction: \(x.f())")
2017
}

0 commit comments

Comments
 (0)