Skip to content

Commit b63ab45

Browse files
committed
Stop producing line and file debug information for clang::Decls.
It would be nice to query the clang::SourceManager for the source location of the clang::Decl in IRGenDebugInfo, but module out-of-date rebuilds may unload previously loaded clang::Modules and thus also invalidate source locations pointed to, leading to a use-after-free here. If this functionality is desired, the source location must be captured by ClangImporter and stored on the side. LLDB does not actually make use of this information for non-C++ types (it is really helpful with debugging the debug info itself, though), so we can avoid the potential use-after-free and crash by not doing it. <rdar://problem/48509051>
1 parent dc89cc0 commit b63ab45

File tree

3 files changed

+12
-34
lines changed

3 files changed

+12
-34
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,14 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
240240
if (!D)
241241
return L;
242242

243-
if (auto *ClangDecl = D->getClangDecl()) {
244-
auto ClangSrcLoc = ClangDecl->getBeginLoc();
245-
clang::SourceManager &ClangSM =
246-
CI.getClangASTContext().getSourceManager();
247-
L.Line = ClangSM.getPresumedLineNumber(ClangSrcLoc);
248-
L.Filename = ClangSM.getBufferName(ClangSrcLoc);
249-
return L;
250-
}
243+
// If D is a clang::Decl, it would be nice to query the clang::SourceManager
244+
// for the source location of the clang::Decl here, but module out-of-date
245+
// rebuilds may unload previously loaded clang::Modules and thus also
246+
// invalidate source locations pointed to, leading to a use-after-free
247+
// here. If this functionality is desired, the source location must be
248+
// captured by ClangImporter and stored on the side.
249+
// LLDB only uses the DW_AT_decl_file / DW_AT_decl_line for C++ types.
250+
251251
return getSwiftDebugLoc(DI, D, End);
252252
}
253253

test/ClangImporter/objc_ir.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,11 @@ func testBlocksWithGenerics(hba: HasBlockArray) -> Any {
360360
// CHECK: attributes [[NOUNWIND]] = { nounwind }
361361

362362
// 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]+]])
363-
// CHECK: ![[SWIFT_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo14SwiftNameAliasaD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, baseType: !{{[0-9]+}})
363+
// CHECK: ![[SWIFT_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo14SwiftNameAliasaD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})
364364

365365
// CHECK: ![[SWIFT_GENERIC_NAME_ALIAS_VAR]] = !DILocalVariable(name: "generic_obj", arg: 1, scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE:[0-9]+]])
366-
// CHECK: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo21SwiftGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, baseType: !{{[0-9]+}})
366+
// CHECK: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo21SwiftGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})
367367

368368
// CHECK: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_VAR]] = !DILocalVariable(name: "constr_generic_obj", arg: 1, scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE:[0-9]+]])
369-
// CHECK: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo27SwiftConstrGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, baseType: !{{[0-9]+}})
369+
// CHECK: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$sSo27SwiftConstrGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})
370+

test/DebugInfo/ClangPathDots.swift

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)