diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index e8b4f279d1cd7..31a76cd6d4f14 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -729,6 +729,16 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { if (!DC) return TheCU; + auto createContext = [&](NominalTypeDecl &NTD) { + GenericContextScope scope( + IGM, NTD.getGenericSignature().getCanonicalSignature()); + + auto Ty = NTD.getDeclaredInterfaceType(); + // Create a Forward-declared type. + auto DbgTy = DebugTypeInfo::getForwardDecl(Ty); + return getOrCreateType(DbgTy); + }; + if (isa(DC)) if (auto *Decl = IGM.getSILModule().lookUpFunction(SILDeclRef( cast(DC), SILDeclRef::Kind::Func))) @@ -742,7 +752,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { // We don't model these in DWARF. case DeclContextKind::Initializer: - case DeclContextKind::ExtensionDecl: case DeclContextKind::SubscriptDecl: case DeclContextKind::EnumElementDecl: case DeclContextKind::TopLevelCodeDecl: @@ -761,16 +770,17 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { return getOrCreateContext(DC->getParent()); case DeclContextKind::MacroDecl: return getOrCreateContext(DC->getParent()); + case DeclContextKind::ExtensionDecl: { + auto *ED = cast(DC); + if (auto *NTD = ED->getExtendedNominal()) + return createContext(*NTD); + return getOrCreateContext(DC->getParent()); + } case DeclContextKind::GenericTypeDecl: { - // The generic signature of this nominal type has no relation to the current - // function's generic signature. + // The generic signature of this nominal type has no relation to the + // current function's generic signature. auto *NTD = cast(DC); - GenericContextScope scope(IGM, NTD->getGenericSignature().getCanonicalSignature()); - - auto Ty = NTD->getDeclaredInterfaceType(); - // Create a Forward-declared type. - auto DbgTy = DebugTypeInfo::getForwardDecl(Ty); - return getOrCreateType(DbgTy); + return createContext(*NTD); } } return TheCU; @@ -2684,8 +2694,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { // declarations may not have a unique ID to avoid a forward declaration // winning over a full definition. auto *FwdDecl = DBuilder.createReplaceableCompositeType( - llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, 0, 0, - llvm::dwarf::DW_LANG_Swift); + llvm::dwarf::DW_TAG_structure_type, Name, Scope, 0, 0, + llvm::dwarf::DW_LANG_Swift, 0, 0, llvm::DINode::FlagFwdDecl, + MangledName); FwdDeclTypes.emplace_back( std::piecewise_construct, std::make_tuple(MangledName), std::make_tuple(static_cast(FwdDecl))); diff --git a/test/DebugInfo/BoundGenericStruct.swift b/test/DebugInfo/BoundGenericStruct.swift index a8aa816e80c86..f324cdc003c4f 100644 --- a/test/DebugInfo/BoundGenericStruct.swift +++ b/test/DebugInfo/BoundGenericStruct.swift @@ -31,12 +31,11 @@ public let inner = S2.Inner(t:4.2) // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Inner", // CHECK-SAME: size: 64, {{.*}}identifier: "$s18BoundGenericStruct2S2V5InnerVySd_GD") -// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$s18BoundGenericStruct2S2VyxGD", -// CHECK-SAME: flags: DIFlagFwdDecl, runtimeLang: DW_LANG_Swift) +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, {{.*}}flags: DIFlagFwdDecl, runtimeLang: DW_LANG_Swift, {{.*}}identifier: "$s18BoundGenericStruct2S2VyxGD" // DWARF-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "$s18BoundGenericStruct2S2V5InnerVySd_GD", scope: ![[SCOPE1:[0-9]+]], {{.*}}flags: DIFlagFwdDecl, runtimeLang: DW_LANG_Swift, templateParams: ![[PARAMS2:[0-9]+]]) -// DWARF-DAG: ![[SCOPE1]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$s18BoundGenericStruct2S2VyxGD", +// DWARF-DAG: ![[SCOPE1]] = !DICompositeType(tag: DW_TAG_structure_type, {{.*}}identifier: "$s18BoundGenericStruct2S2VyxGD" // DWARF-DAG: ![[PARAMS2]] = !{![[PARAMS3:[0-9]+]]} // DWARF-DAG: ![[PARAMS3]] = !DITemplateTypeParameter(type: ![[PARAMS4:[0-9]+]]) diff --git a/test/DebugInfo/Errors.swift b/test/DebugInfo/Errors.swift index 41f5b31e732ac..9dc1f3b715d67 100644 --- a/test/DebugInfo/Errors.swift +++ b/test/DebugInfo/Errors.swift @@ -3,7 +3,7 @@ public enum E : Error { case Err } // Function throws. public func throwError() throws { throw E.Err } -// CHECK: !DISubprogram(name: "throwError", {{.*}}thrownTypes: ![[THROWN:.*]]) +// CHECK-DAG: !DISubprogram(name: "throwError", {{.*}}thrownTypes: ![[THROWN:.*]]) // CHECK-DAG: ![[THROWN]] = !{![[ERROR:[0-9]+]]} // CHECK-DAG: ![[ERROR]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Error" diff --git a/test/DebugInfo/NestedTypes.swift b/test/DebugInfo/NestedTypes.swift index eb4c82a85394e..b2b7857aa9169 100644 --- a/test/DebugInfo/NestedTypes.swift +++ b/test/DebugInfo/NestedTypes.swift @@ -16,3 +16,27 @@ public let e : Enum = .WithClass(C()) // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "WithStruct", // CHECK-SAME: size: 128) +public struct D { + var v : V + let u: U +} + +extension D { + struct V { + internal var obj: Int + } +} + +public let d = D(v: D.V(obj: 1), u: 2) + +// CHECK: ![[D:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "D" +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "V", scope: ![[D]], + +public struct Unused { + public struct W {} +} + +public let w = Unused.W() + +// CHECK-DAG: ![[Unused:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Unused" +// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "W", scope: ![[Unused]], diff --git a/test/DebugInfo/generic_arg4.swift b/test/DebugInfo/generic_arg4.swift index fb3dcefd16e69..36acf634362b9 100644 --- a/test/DebugInfo/generic_arg4.swift +++ b/test/DebugInfo/generic_arg4.swift @@ -9,7 +9,7 @@ public struct Q { // CHECK-SAME: ![[ARG:.*]], !DIExpression() // CHECK: store ptr %0, ptr %[[ALLOCA]], align // No deref here: the array argument is passed by value. -// CHECK: ![[DITY:.*]] = !DICompositeType({{.*}}name: "$sSay12generic_arg41QVyxGGD" +// CHECK: ![[DITY:.*]] = !DICompositeType({{.*}}identifier: "$sSay12generic_arg41QVyxGGD" public func foo(_ arg: [Q]) { // CHECK: ![[ARG]] = !DILocalVariable(name: "arg", arg: 1, // CHECK-SAME: line: [[@LINE-2]], type: ![[DITY:.*]]) diff --git a/test/DebugInfo/generic_arg5.swift b/test/DebugInfo/generic_arg5.swift index ded6a3c3ae7bb..7f9a5efb194d0 100644 --- a/test/DebugInfo/generic_arg5.swift +++ b/test/DebugInfo/generic_arg5.swift @@ -12,7 +12,7 @@ public func foo(_ values : [S]) // CHECK-SAME: ![[ARG:[0-9]+]], // CHECK-SAME: !DIExpression(DW_OP_deref) // CHECK: store ptr %1, ptr %[[ALLOCA]], align - // CHECK-DAG: ![[TYP:[0-9]+]] = !DICompositeType({{.*}}, name: "$s12generic_arg51SVyxGD" + // CHECK-DAG: ![[TYP:[0-9]+]] = !DICompositeType({{.*}}, identifier: "$s12generic_arg51SVyxGD" // The argument is a by-ref struct and thus needs to be dereferenced. // CHECK-DAG: ![[ARG]] = !DILocalVariable(name: "arg", arg: 1,{{.*}}line: [[@LINE+6]],{{.*}} type: ![[LET_TYP:[0-9]+]]) // CHECK-DAG: ![[LET_TYP]] = !DIDerivedType(tag: DW_TAG_const_type,{{.*}} baseType: ![[TYP_CONTAINER:[0-9]+]]) diff --git a/test/DebugInfo/struct_resilience.swift b/test/DebugInfo/struct_resilience.swift index cb61989359983..34a28a4c11e51 100644 --- a/test/DebugInfo/struct_resilience.swift +++ b/test/DebugInfo/struct_resilience.swift @@ -29,7 +29,7 @@ public func f() { // CHECK: store ptr %[[S1]], ptr %[[ADDR]] } -// CHECK: ![[TY:[0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$s16resilient_struct4SizeVD", +// CHECK: ![[TY:[0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Size", // CHECK: ![[LET_TY:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, // CHECK-SAME: baseType: ![[TY:[0-9]+]]) // CHECK: ![[V1]] = !DILocalVariable(name: "s1", {{.*}}type: ![[LET_TY]]) diff --git a/test/DebugInfo/typealias.swift b/test/DebugInfo/typealias.swift index 993cf2fa14e76..7942c96cbd20f 100644 --- a/test/DebugInfo/typealias.swift +++ b/test/DebugInfo/typealias.swift @@ -120,10 +120,11 @@ public protocol Down { } public typealias DependentAlias = T.A.A +// CHECK-DAG: ![[DEPENDENTALIAS:.*]] = !DIDerivedType(tag: DW_TAG_typedef, name: "DependentAlias", {{.*}} baseType: ![[INTTYPE]]) extension Up where A.A == Int { public func foo() { - // CHECK-DAG: !DILocalVariable(name: "gg",{{.*}} type: ![[INTTYPE]] + // CHECK-DAG: !DILocalVariable(name: "gg",{{.*}} type: ![[DEPENDENTALIAS]] var gg: DependentAlias = 123 } }