From 45d4648bdb9e1a9f1e3205556e653e203c55c06a Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 30 Jan 2025 17:25:23 -0800 Subject: [PATCH] Revert "[Debug info] Emit bound generic class type parameters when emitting AST types" This reverts commit f2132890db531a91864564b6a51c7b0810a89094 it triggers the debug info sanity check when running the source compatibility testsuite. --- lib/IRGen/IRGenDebugInfo.cpp | 38 ++++++++++++++----------- test/ClangImporter/objc_ir.swift | 18 ++++++------ test/DebugInfo/BoundGenericStruct.swift | 6 +++- test/DebugInfo/typealias_indirect.swift | 8 ------ 4 files changed, 36 insertions(+), 34 deletions(-) delete mode 100644 test/DebugInfo/typealias_indirect.swift diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index 7c550ba54cf9f..a8a0bc77dd187 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -1283,12 +1283,16 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { DBuilder.createInheritance(UnsubstitutedType, SuperClassDITy, 0, 0, llvm::DINode::FlagZero); } + + auto *OpaqueType = createPointerSizedStruct( + Scope, Decl ? Decl->getNameStr() : MangledName, File, 0, Flags, + MangledName, UnsubstitutedType); + return OpaqueType; } - auto *OpaqueType = - createOpaqueStruct(Scope, Decl ? Decl->getNameStr() : "", File, Line, - SizeInBits, AlignInBits, Flags, MangledName, - collectGenericParams(Type), UnsubstitutedType); + auto *OpaqueType = createOpaqueStruct( + Scope, "", File, Line, SizeInBits, AlignInBits, Flags, MangledName, + collectGenericParams(Type), UnsubstitutedType); DBuilder.replaceTemporary(std::move(FwdDecl), OpaqueType); return OpaqueType; } @@ -1975,9 +1979,18 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { auto L = getFileAndLocation(Decl); unsigned FwdDeclLine = 0; - return createSpecializedStructOrClassType(ClassTy, Decl, Scope, L.File, - L.Line, SizeInBits, AlignInBits, - Flags, MangledName); + if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes) + return createSpecializedStructOrClassType( + ClassTy, Decl, Scope, L.File, L.Line, SizeInBits, AlignInBits, + Flags, MangledName); + + // TODO: We may want to peek at Decl->isObjC() and set this + // attribute accordingly. + assert(SizeInBits == + CI.getTargetInfo().getPointerWidth(clang::LangAS::Default)); + return createPointerSizedStruct( + Scope, Decl ? Decl->getNameStr() : MangledName, L.File, FwdDeclLine, + Flags, MangledName, SpecificationOf); } case TypeKind::Pack: @@ -2161,14 +2174,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { AliasedTy, DbgTy.getAlignment(), DbgTy.hasDefaultAlignment(), /* IsMetadataType = */ false, DbgTy.isFixedBuffer(), DbgTy.getNumExtraInhabitants()); - auto *TypeDef = DBuilder.createTypedef(getOrCreateType(AliasedDbgTy), - MangledName, L.File, 0, Scope); - // 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. - if (Opts.DebugInfoLevel < IRGenDebugInfoLevel::DwarfTypes) - DBuilder.retainType(TypeDef); - return TypeDef; + return DBuilder.createTypedef(getOrCreateType(AliasedDbgTy), MangledName, + L.File, 0, Scope); } case TypeKind::Locatable: { @@ -2504,7 +2511,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { // winning over a full definition. auto *FwdDecl = DBuilder.createReplaceableCompositeType( llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, 0, 0, - llvm::dwarf::DW_LANG_Swift); FwdDeclTypes.emplace_back( std::piecewise_construct, std::make_tuple(MangledName), diff --git a/test/ClangImporter/objc_ir.swift b/test/ClangImporter/objc_ir.swift index 6a82df814d5a6..fc5f264653c2d 100644 --- a/test/ClangImporter/objc_ir.swift +++ b/test/ClangImporter/objc_ir.swift @@ -351,14 +351,14 @@ func testBlocksWithGenerics(hba: HasBlockArray) -> Any { // CHECK: attributes [[NOUNWIND]] = { nounwind memory(read) } -// 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]+]]) -// CHECK-DAG: ![[LET_SWIFT_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[SWIFT_NAME_ALIAS_TYPE:[0-9]+]]) -// CHECK-DAG: ![[SWIFT_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo14SwiftNameAliasaD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}}) +// 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]+]]) +// CHECK: ![[LET_SWIFT_NAME_ALIAS_TYPE:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[SWIFT_NAME_ALIAS_TYPE:[0-9]+]]) +// CHECK: ![[SWIFT_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo14SwiftNameAliasaD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}}) -// 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]+]]) -// CHECK-DAG: ![[LET_SWIFT_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE:[0-9]+]]) -// CHECK-DAG: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo21SwiftGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}}) +// 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]+]]) +// CHECK: ![[LET_SWIFT_GENERIC_NAME_ALIAS_TYPE:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE:[0-9]+]]) +// CHECK: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo21SwiftGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}}) -// 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]+]]) -// CHECK-DAG: ![[LET_SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE:[0-9]+]]) -// CHECK-DAG: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo27SwiftConstrGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}}) +// 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]+]]) +// 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]+]]) +// CHECK: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo27SwiftConstrGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}}) diff --git a/test/DebugInfo/BoundGenericStruct.swift b/test/DebugInfo/BoundGenericStruct.swift index 7401983b8a895..838c847c01870 100644 --- a/test/DebugInfo/BoundGenericStruct.swift +++ b/test/DebugInfo/BoundGenericStruct.swift @@ -12,6 +12,7 @@ public let s = S(t: 0) // CHECK: ![[INTPARAM]] = !DITemplateTypeParameter(type: ![[INT:[0-9]+]]) // CHECK: ![[INT]] = !DICompositeType(tag: DW_TAG_structure_type, {{.*}}identifier: "$sSiD" + // DWARF: !DICompositeType(tag: DW_TAG_structure_type, // DWARF-SAME: templateParams: ![[PARAMS:[0-9]+]] // DWARF-SAME: identifier: "$s18BoundGenericStruct1SVySiGD" @@ -39,7 +40,10 @@ public let inner = S2.Inner(t:4.2) // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$s18BoundGenericStruct2S2VyxGD", // CHECK-SAME: flags: DIFlagFwdDecl, runtimeLang: DW_LANG_Swift) -// 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]+]] +// DWARF: !DICompositeType(tag: DW_TAG_structure_type, scope: ![[SCOPE1:[0-9]+]], +// DWARF-SAME: size: 64, {{.*}}, templateParams: ![[PARAMS2:[0-9]+]], identifier: "$s18BoundGenericStruct2S2V5InnerVySd_GD" +// DWARF-SAME: specification: ![[SPECIFICATION:[0-9]+]] + // DWARF: ![[SCOPE1]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$s18BoundGenericStruct2S2VyxGD", // DWARF: ![[PARAMS2]] = !{![[PARAMS3:[0-9]+]]} diff --git a/test/DebugInfo/typealias_indirect.swift b/test/DebugInfo/typealias_indirect.swift deleted file mode 100644 index 9f04320a9fd20..0000000000000 --- a/test/DebugInfo/typealias_indirect.swift +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: %target-swift-frontend %s -emit-ir -parse-as-library -module-name a -g -o - | %FileCheck %s -// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "$s1a10LocalAliasaD", {{.*}}baseType: ![[BASETY:[0-9]+]] -// CHECK: ![[BASETY]]{{.*}}$sSbD -public class MyClass {} -public typealias LocalAlias = Bool -public typealias ClassAlias = MyClass -public func use(cls: ClassAlias?) {} -