Skip to content

Commit e7871c5

Browse files
Merge pull request #34037 from adrian-prantl/69393097
Store Clang module imports in addition to Swift overlay.
2 parents 3c386d8 + ba4c82d commit e7871c5

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,24 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
660660
isa<ConstructorDecl>(DeclCtx);
661661
}
662662

663+
void createImportedModule(llvm::DIScope *Context,
664+
ModuleDecl::ImportedModule M, llvm::DIFile *File,
665+
unsigned Line) {
666+
// For overlays of Clang modules also emit an import of the underlying Clang
667+
// module. The helps the debugger resolve types that are present only in the
668+
// underlying module.
669+
if (const clang::Module *UnderlyingClangModule =
670+
M.importedModule->findUnderlyingClangModule()) {
671+
DBuilder.createImportedModule(
672+
Context,
673+
getOrCreateModule(
674+
{*const_cast<clang::Module *>(UnderlyingClangModule)},
675+
UnderlyingClangModule),
676+
File, 0);
677+
}
678+
DBuilder.createImportedModule(Context, getOrCreateModule(M), File, Line);
679+
}
680+
663681
llvm::DIModule *getOrCreateModule(const void *Key, llvm::DIScope *Parent,
664682
StringRef Name, StringRef IncludePath,
665683
uint64_t Signature = ~1ULL,
@@ -1871,8 +1889,7 @@ void IRGenDebugInfoImpl::finalize() {
18711889
ModuleDecl::ImportFilterKind::ImplementationOnly});
18721890
for (auto M : ModuleWideImports)
18731891
if (!ImportedModules.count(M.importedModule))
1874-
DBuilder.createImportedModule(MainFile, getOrCreateModule(M), MainFile,
1875-
0);
1892+
createImportedModule(MainFile, M, MainFile, 0);
18761893

18771894
// Finalize all replaceable forward declarations.
18781895
for (auto &Ty : ReplaceMap) {
@@ -2113,10 +2130,9 @@ void IRGenDebugInfoImpl::emitImport(ImportDecl *D) {
21132130

21142131
assert(D->getModule() && "compiler-synthesized ImportDecl is incomplete");
21152132
ModuleDecl::ImportedModule Imported = { D->getAccessPath(), D->getModule() };
2116-
auto DIMod = getOrCreateModule(Imported);
21172133
auto L = getDebugLoc(*this, D);
21182134
auto *File = getOrCreateFile(L.Filename);
2119-
DBuilder.createImportedModule(File, DIMod, File, L.Line);
2135+
createImportedModule(File, Imported, File, L.Line);
21202136
ImportedModules.insert(Imported.importedModule);
21212137
}
21222138

test/DebugInfo/ImportClangSubmodule.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
// CHECK-SAME: {{..}}-DFOO=foo{{..}}
2323
// CHECK-SAME: {{..}}-UBAR{{..}}
2424

25-
// CHECK: !DIImportedEntity({{.*}}, entity: ![[SUBMODULE]], file:
26-
// CHECK-SAME: line: [[@LINE+1]])
25+
// CHECK: !DIImportedEntity({{.*}}, entity: ![[SUBMODULE]], file:{{.*}}line: [[@LINE+1]])
2726
import ClangModule.SubModule
28-
// CHECK: !DIImportedEntity({{.*}}, entity: ![[OTHERSUBMODULE]],
29-
// CHECK-SAME: line: [[@LINE+1]])
27+
// CHECK: !DIImportedEntity({{.*}}, entity: ![[OTHERSUBMODULE]],{{.*}}line: [[@LINE+1]])
3028
import OtherClangModule.SubModule
3129

3230
// The Swift compiler uses an ugly hack that auto-imports a

test/DebugInfo/overlay-import.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-swift-frontend -emit-ir -g %s -o - | %FileCheck %s
2+
3+
// REQUIRES: OS=macosx
4+
5+
import Foundation
6+
let n = Notification(name: Notification.Name(rawValue: "test"))
7+
// Test that a skeleton CU for the Foundation module is emitted even though we are only using the overlay!
8+
// CHECK: !DICompileUnit(language: DW_LANG_ObjC, {{.*}}Foundation{{.*}}.pcm", {{.*}}dwoId:

0 commit comments

Comments
 (0)