Skip to content

Commit 68a5cad

Browse files
committed
Debug Info: Generate imported entities for implicitly imported parent modules.
The Swift compiler uses an ugly hack that auto-imports a submodule's top-level-module, even if we didn't ask for it. Reflect that in the debug info. <rdar://problem/31310320>
1 parent 5e31b5b commit 68a5cad

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
9696

9797
/// A list of replaceable fwddecls that need to be RAUWed at the end.
9898
std::vector<std::pair<TypeBase *, llvm::TrackingMDRef>> ReplaceMap;
99+
/// The set of imported modules.
100+
llvm::DenseSet<ModuleDecl::ImportedModule> ImportedModules;
99101

100102
llvm::BumpPtrAllocator DebugInfoNames;
101103
StringRef CWDName; /// The current working directory.
@@ -1550,6 +1552,15 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
15501552
void IRGenDebugInfoImpl::finalize() {
15511553
assert(LocationStack.empty() && "Mismatch of pushLoc() and popLoc().");
15521554

1555+
// Get the list of imported modules (which may actually be different
1556+
// from all ImportDecls).
1557+
SmallVector<ModuleDecl::ImportedModule, 8> ModuleWideImports;
1558+
IGM.getSwiftModule()->getImportedModules(ModuleWideImports,
1559+
ModuleDecl::ImportFilter::All);
1560+
for (auto M : ModuleWideImports)
1561+
if (!ImportedModules.count(M))
1562+
DBuilder.createImportedModule(MainFile, getOrCreateModule(M), 0);
1563+
15531564
// Finalize all replaceable forward declarations.
15541565
for (auto &Ty : ReplaceMap) {
15551566
llvm::TempMDNode FwdDecl(cast<llvm::MDNode>(Ty.second));
@@ -1716,9 +1727,11 @@ void IRGenDebugInfoImpl::emitImport(ImportDecl *D) {
17161727
assert(M && "Could not find module for import decl.");
17171728
return;
17181729
}
1719-
auto DIMod = getOrCreateModule({D->getModulePath(), M});
1730+
ModuleDecl::ImportedModule Imported = {D->getModulePath(), M};
1731+
auto DIMod = getOrCreateModule(Imported);
17201732
auto L = getDebugLoc(*this, D);
17211733
DBuilder.createImportedModule(getOrCreateFile(L.Filename), DIMod, L.Line);
1734+
ImportedModules.insert(Imported);
17221735
}
17231736

17241737
llvm::DISubprogram *IRGenDebugInfoImpl::emitFunction(SILFunction &SILFn,

test/DebugInfo/ImportClangSubmodule.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
// CHECK-SAME: configMacros:
1111
// CHECK-SAME: {{..}}-DFOO=foo{{..}}
1212
// CHECK-SAME: {{..}}-UBAR{{..}}
13+
1314
// CHECK: !DIImportedEntity({{.*}}, entity: ![[SUBMODULE]], line: [[@LINE+1]])
1415
import ClangModule.SubModule
1516

17+
// The Swift compiler uses an ugly hack that auto-imports a
18+
// submodule's top-level-module, even if we didn't ask for it.
19+
// CHECK: !DIImportedEntity({{.*}}, entity: ![[CLANGMODULE]])
20+
1621
let bar = Bar()

0 commit comments

Comments
 (0)