Skip to content

Commit a5dddce

Browse files
Merge pull request #78901 from adrian-prantl/143595521
[Debug info] Retain all type aliases in asttypes mode
2 parents d5f6bef + f213289 commit a5dddce

File tree

4 files changed

+34
-36
lines changed

4 files changed

+34
-36
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,16 +1283,12 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
12831283
DBuilder.createInheritance(UnsubstitutedType, SuperClassDITy, 0, 0,
12841284
llvm::DINode::FlagZero);
12851285
}
1286-
1287-
auto *OpaqueType = createPointerSizedStruct(
1288-
Scope, Decl ? Decl->getNameStr() : MangledName, File, 0, Flags,
1289-
MangledName, UnsubstitutedType);
1290-
return OpaqueType;
12911286
}
12921287

1293-
auto *OpaqueType = createOpaqueStruct(
1294-
Scope, "", File, Line, SizeInBits, AlignInBits, Flags, MangledName,
1295-
collectGenericParams(Type), UnsubstitutedType);
1288+
auto *OpaqueType =
1289+
createOpaqueStruct(Scope, Decl ? Decl->getNameStr() : "", File, Line,
1290+
SizeInBits, AlignInBits, Flags, MangledName,
1291+
collectGenericParams(Type), UnsubstitutedType);
12961292
DBuilder.replaceTemporary(std::move(FwdDecl), OpaqueType);
12971293
return OpaqueType;
12981294
}
@@ -1979,18 +1975,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
19791975
auto L = getFileAndLocation(Decl);
19801976
unsigned FwdDeclLine = 0;
19811977

1982-
if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes)
1983-
return createSpecializedStructOrClassType(
1984-
ClassTy, Decl, Scope, L.File, L.Line, SizeInBits, AlignInBits,
1985-
Flags, MangledName);
1986-
1987-
// TODO: We may want to peek at Decl->isObjC() and set this
1988-
// attribute accordingly.
1989-
assert(SizeInBits ==
1990-
CI.getTargetInfo().getPointerWidth(clang::LangAS::Default));
1991-
return createPointerSizedStruct(
1992-
Scope, Decl ? Decl->getNameStr() : MangledName, L.File, FwdDeclLine,
1993-
Flags, MangledName, SpecificationOf);
1978+
return createSpecializedStructOrClassType(ClassTy, Decl, Scope, L.File,
1979+
L.Line, SizeInBits, AlignInBits,
1980+
Flags, MangledName);
19941981
}
19951982

19961983
case TypeKind::Pack:
@@ -2174,8 +2161,14 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
21742161
AliasedTy, DbgTy.getAlignment(), DbgTy.hasDefaultAlignment(),
21752162
/* IsMetadataType = */ false, DbgTy.isFixedBuffer(),
21762163
DbgTy.getNumExtraInhabitants());
2177-
return DBuilder.createTypedef(getOrCreateType(AliasedDbgTy), MangledName,
2178-
L.File, 0, Scope);
2164+
auto *TypeDef = DBuilder.createTypedef(getOrCreateType(AliasedDbgTy),
2165+
MangledName, L.File, 0, Scope);
2166+
// Bound generic types don't reference their type parameters in ASTTypes
2167+
// mode, so we need to artificially keep typealiases alive, since they can
2168+
// appear in reflection metadata.
2169+
if (Opts.DebugInfoLevel < IRGenDebugInfoLevel::DwarfTypes)
2170+
DBuilder.retainType(TypeDef);
2171+
return TypeDef;
21792172
}
21802173

21812174
case TypeKind::Locatable: {
@@ -2511,6 +2504,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
25112504
// winning over a full definition.
25122505
auto *FwdDecl = DBuilder.createReplaceableCompositeType(
25132506
llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, 0, 0,
2507+
25142508
llvm::dwarf::DW_LANG_Swift);
25152509
FwdDeclTypes.emplace_back(
25162510
std::piecewise_construct, std::make_tuple(MangledName),

test/ClangImporter/objc_ir.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,14 @@ func testBlocksWithGenerics(hba: HasBlockArray) -> Any {
351351

352352
// CHECK: attributes [[NOUNWIND]] = { nounwind memory(read) }
353353

354-
// CHECK: ![[SWIFT_NAME_ALIAS_VAR]] = !DILocalVariable(name: "obj", arg: 1, scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[SWIFT_NAME_ALIAS_TYPE:[0-9]+]])
355-
// CHECK: ![[LET_SWIFT_NAME_ALIAS_TYPE:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[SWIFT_NAME_ALIAS_TYPE:[0-9]+]])
356-
// CHECK: ![[SWIFT_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo14SwiftNameAliasaD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})
354+
// CHECK-DAG: ![[SWIFT_NAME_ALIAS_VAR]] = !DILocalVariable(name: "obj", arg: 1, scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 328, type: ![[LET_SWIFT_NAME_ALIAS_TYPE:[0-9]+]])
355+
// CHECK-DAG: ![[LET_SWIFT_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[SWIFT_NAME_ALIAS_TYPE:[0-9]+]])
356+
// CHECK-DAG: ![[SWIFT_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo14SwiftNameAliasaD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})
357357

358-
// CHECK: ![[SWIFT_GENERIC_NAME_ALIAS_VAR]] = !DILocalVariable(name: "generic_obj", arg: 1, scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[LET_SWIFT_GENERIC_NAME_ALIAS_TYPE:[0-9]+]])
359-
// CHECK: ![[LET_SWIFT_GENERIC_NAME_ALIAS_TYPE:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE:[0-9]+]])
360-
// CHECK: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo21SwiftGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})
358+
// CHECK-DAG: ![[SWIFT_GENERIC_NAME_ALIAS_VAR]] = !DILocalVariable(name: "generic_obj", arg: 1, scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[LET_SWIFT_GENERIC_NAME_ALIAS_TYPE:[0-9]+]])
359+
// CHECK-DAG: ![[LET_SWIFT_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE:[0-9]+]])
360+
// CHECK-DAG: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo21SwiftGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})
361361

362-
// CHECK: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_VAR]] = !DILocalVariable(name: "constr_generic_obj", arg: 1, scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[LET_SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE:[0-9]+]])
363-
// CHECK: ![[LET_SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE:[0-9]+]])
364-
// CHECK: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo27SwiftConstrGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})
362+
// CHECK-DAG: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_VAR]] = !DILocalVariable(name: "constr_generic_obj", arg: 1, scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[LET_SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE:[0-9]+]])
363+
// CHECK-DAG: ![[LET_SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE:[0-9]+]])
364+
// CHECK-DAG: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo27SwiftConstrGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})

test/DebugInfo/BoundGenericStruct.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public let s = S<Int>(t: 0)
1212
// CHECK: ![[INTPARAM]] = !DITemplateTypeParameter(type: ![[INT:[0-9]+]])
1313
// CHECK: ![[INT]] = !DICompositeType(tag: DW_TAG_structure_type, {{.*}}identifier: "$sSiD"
1414

15-
1615
// DWARF: !DICompositeType(tag: DW_TAG_structure_type,
1716
// DWARF-SAME: templateParams: ![[PARAMS:[0-9]+]]
1817
// DWARF-SAME: identifier: "$s18BoundGenericStruct1SVySiGD"
@@ -40,10 +39,7 @@ public let inner = S2<Double>.Inner(t:4.2)
4039
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$s18BoundGenericStruct2S2VyxGD",
4140
// CHECK-SAME: flags: DIFlagFwdDecl, runtimeLang: DW_LANG_Swift)
4241

43-
// DWARF: !DICompositeType(tag: DW_TAG_structure_type, scope: ![[SCOPE1:[0-9]+]],
44-
// DWARF-SAME: size: 64, {{.*}}, templateParams: ![[PARAMS2:[0-9]+]], identifier: "$s18BoundGenericStruct2S2V5InnerVySd_GD"
45-
// DWARF-SAME: specification: ![[SPECIFICATION:[0-9]+]]
46-
42+
// DWARF: !DICompositeType(tag: DW_TAG_structure_type, name: "Inner", scope: ![[SCOPE1:[0-9]+]],{{.*}} size: 64, {{.*}}, templateParams: ![[PARAMS2:[0-9]+]], identifier: "$s18BoundGenericStruct2S2V5InnerVySd_GD",{{.*}} specification: ![[SPECIFICATION:[0-9]+]]
4743
// DWARF: ![[SCOPE1]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$s18BoundGenericStruct2S2VyxGD",
4844

4945
// DWARF: ![[PARAMS2]] = !{![[PARAMS3:[0-9]+]]}
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+

0 commit comments

Comments
 (0)