Skip to content

Store Clang module imports in addition to Swift overlay. #34037

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
Sep 24, 2020
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
24 changes: 20 additions & 4 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,24 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
isa<ConstructorDecl>(DeclCtx);
}

void createImportedModule(llvm::DIScope *Context,
ModuleDecl::ImportedModule M, llvm::DIFile *File,
unsigned Line) {
// For overlays of Clang modules also emit an import of the underlying Clang
// module. The helps the debugger resolve types that are present only in the
// underlying module.
if (const clang::Module *UnderlyingClangModule =
M.importedModule->findUnderlyingClangModule()) {
DBuilder.createImportedModule(
Context,
getOrCreateModule(
{*const_cast<clang::Module *>(UnderlyingClangModule)},
UnderlyingClangModule),
File, 0);
}
DBuilder.createImportedModule(Context, getOrCreateModule(M), File, Line);
}

llvm::DIModule *getOrCreateModule(const void *Key, llvm::DIScope *Parent,
StringRef Name, StringRef IncludePath,
uint64_t Signature = ~1ULL,
Expand Down Expand Up @@ -1871,8 +1889,7 @@ void IRGenDebugInfoImpl::finalize() {
ModuleDecl::ImportFilterKind::ImplementationOnly});
for (auto M : ModuleWideImports)
if (!ImportedModules.count(M.importedModule))
DBuilder.createImportedModule(MainFile, getOrCreateModule(M), MainFile,
0);
createImportedModule(MainFile, M, MainFile, 0);

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

assert(D->getModule() && "compiler-synthesized ImportDecl is incomplete");
ModuleDecl::ImportedModule Imported = { D->getAccessPath(), D->getModule() };
auto DIMod = getOrCreateModule(Imported);
auto L = getDebugLoc(*this, D);
auto *File = getOrCreateFile(L.Filename);
DBuilder.createImportedModule(File, DIMod, File, L.Line);
createImportedModule(File, Imported, File, L.Line);
ImportedModules.insert(Imported.importedModule);
}

Expand Down
6 changes: 2 additions & 4 deletions test/DebugInfo/ImportClangSubmodule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
// CHECK-SAME: {{..}}-DFOO=foo{{..}}
// CHECK-SAME: {{..}}-UBAR{{..}}

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

// The Swift compiler uses an ugly hack that auto-imports a
Expand Down
8 changes: 8 additions & 0 deletions test/DebugInfo/overlay-import.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %target-swift-frontend -emit-ir -g %s -o - | %FileCheck %s

// REQUIRES: OS=macosx

import Foundation
let n = Notification(name: Notification.Name(rawValue: "test"))
// Test that a skeleton CU for the Foundation module is emitted even though we are only using the overlay!
// CHECK: !DICompileUnit(language: DW_LANG_ObjC, {{.*}}Foundation{{.*}}.pcm", {{.*}}dwoId: