Skip to content

Debug Info: Generate imported entities for implicitly imported parent #9706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {

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

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

// Get the list of imported modules (which may actually be different
// from all ImportDecls).
SmallVector<ModuleDecl::ImportedModule, 8> ModuleWideImports;
IGM.getSwiftModule()->getImportedModules(ModuleWideImports,
ModuleDecl::ImportFilter::All);
for (auto M : ModuleWideImports)
if (!ImportedModules.count(M))
DBuilder.createImportedModule(MainFile, getOrCreateModule(M), 0);

// Finalize all replaceable forward declarations.
for (auto &Ty : ReplaceMap) {
llvm::TempMDNode FwdDecl(cast<llvm::MDNode>(Ty.second));
Expand Down Expand Up @@ -1716,9 +1727,11 @@ void IRGenDebugInfoImpl::emitImport(ImportDecl *D) {
assert(M && "Could not find module for import decl.");
return;
}
auto DIMod = getOrCreateModule({D->getModulePath(), M});
ModuleDecl::ImportedModule Imported = {D->getModulePath(), M};
auto DIMod = getOrCreateModule(Imported);
auto L = getDebugLoc(*this, D);
DBuilder.createImportedModule(getOrCreateFile(L.Filename), DIMod, L.Line);
ImportedModules.insert(Imported);
}

llvm::DISubprogram *IRGenDebugInfoImpl::emitFunction(SILFunction &SILFn,
Expand Down
5 changes: 5 additions & 0 deletions test/DebugInfo/ImportClangSubmodule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
// CHECK-SAME: configMacros:
// CHECK-SAME: {{..}}-DFOO=foo{{..}}
// CHECK-SAME: {{..}}-UBAR{{..}}

// CHECK: !DIImportedEntity({{.*}}, entity: ![[SUBMODULE]], line: [[@LINE+1]])
import ClangModule.SubModule

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

let bar = Bar()