Skip to content

Commit 7938272

Browse files
authored
[DebugInfo] Don't record that the standard library imports itself (#17226)
This causes problems for cross-compilation -parse-stdlib tests that emit debug info. At the moment we have zero of those, but we're trying to add one. Also, don't try to load new modules when recording imports. (This isn't harmful, just inefficient.)
1 parent 3b6d832 commit 7938272

File tree

3 files changed

+45
-18
lines changed

3 files changed

+45
-18
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,17 +1111,25 @@ void IRGenerator::emitGlobalTopLevel(bool emitForParallelEmission) {
11111111

11121112
void IRGenModule::finishEmitAfterTopLevel() {
11131113
// Emit the implicit import of the swift standard library.
1114+
// FIXME: We'd get the exact set of implicit imports if we went through the
1115+
// SourceFile's getImportedModules instead, but then we'd lose location info
1116+
// for the explicit imports.
11141117
if (DebugInfo) {
1115-
std::pair<swift::Identifier, swift::SourceLoc> AccessPath[] = {
1116-
{ Context.StdlibModuleName, swift::SourceLoc() }
1117-
};
1118+
if (ModuleDecl *TheStdlib = Context.getStdlibModule()) {
1119+
if (TheStdlib != getSwiftModule()) {
1120+
std::pair<swift::Identifier, swift::SourceLoc> AccessPath[] = {
1121+
{ Context.StdlibModuleName, swift::SourceLoc() }
1122+
};
11181123

1119-
auto Imp = ImportDecl::create(Context,
1120-
getSwiftModule(),
1121-
SourceLoc(),
1122-
ImportKind::Module, SourceLoc(),
1123-
AccessPath);
1124-
DebugInfo->emitImport(Imp);
1124+
auto Imp = ImportDecl::create(Context,
1125+
getSwiftModule(),
1126+
SourceLoc(),
1127+
ImportKind::Module, SourceLoc(),
1128+
AccessPath);
1129+
Imp->setModule(TheStdlib);
1130+
DebugInfo->emitImport(Imp);
1131+
}
1132+
}
11251133
}
11261134
}
11271135

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,15 +1696,8 @@ void IRGenDebugInfoImpl::emitImport(ImportDecl *D) {
16961696
if (Opts.DebugInfoKind <= IRGenDebugInfoKind::LineTables)
16971697
return;
16981698

1699-
swift::ModuleDecl *M = IGM.Context.getModule(D->getModulePath());
1700-
if (!M &&
1701-
D->getModulePath()[0].first == IGM.Context.TheBuiltinModule->getName())
1702-
M = IGM.Context.TheBuiltinModule;
1703-
if (!M) {
1704-
assert(M && "Could not find module for import decl.");
1705-
return;
1706-
}
1707-
ModuleDecl::ImportedModule Imported = {D->getModulePath(), M};
1699+
assert(D->getModule() && "compiler-synthesized ImportDecl is incomplete");
1700+
ModuleDecl::ImportedModule Imported = {D->getModulePath(), D->getModule()};
17081701
auto DIMod = getOrCreateModule(Imported);
17091702
auto L = getDebugLoc(*this, D);
17101703
auto *File = getOrCreateFile(L.Filename);

test/DebugInfo/ImportsStdlib.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -emit-ir -parse-stdlib -module-name NotTheStdlib %s -I %t -g -o - > %t.ll
4+
// RUN: %FileCheck %s < %t.ll
5+
// RUN: %FileCheck -check-prefix=NEGATIVE %s < %t.ll
6+
7+
// RUN: %target-swift-frontend -c -parse-stdlib -module-name NotTheStdlib %s -I %t -g -o %t.o
8+
// RUN: %llvm-dwarfdump -a %t.o > %t.dump
9+
// RUN: %FileCheck -check-prefix=DWARF %s < %t.dump
10+
// RUN: %FileCheck -check-prefix=NEGATIVE-DWARF %s < %t.dump
11+
12+
// CHECK-DAG: ![[MODULE:[0-9]+]] = !DIModule({{.*}}, name: "NotTheStdlib", includePath: "{{.*}}test{{.*}}DebugInfo{{.*}}"
13+
// CHECK-DAG: !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[THISFILE:[0-9]+]], entity: ![[MODULE]]
14+
// CHECK-DAG: ![[THISFILE]] = !DIFile(filename: "ImportsStdlib.swift", directory: "{{.*}}test/DebugInfo")
15+
16+
// NEGATIVE-NOT: !DIFile(filename: "Swift.swiftmodule"
17+
// NEGATIVE-NOT: !DIModule({{.*}}, name: "Swift"
18+
19+
// DWARF: .debug_info
20+
// DWARF: DW_TAG_module
21+
// DWARF: DW_AT_name ("NotTheStdlib")
22+
// DWARF: DW_AT_LLVM_include_path
23+
24+
// DWARF: file_names{{.*}} ImportsStdlib.swift
25+
26+
// NEGATIVE-DWARF-NOT: DW_AT_name ("Swift")

0 commit comments

Comments
 (0)