Skip to content

Commit ea3a9f4

Browse files
committed
Print proper error message when the swiftmodule for correct architecture is not found
1 parent 0ba027f commit ea3a9f4

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ ERROR(cannot_return_value_from_void_func,none,
562562

563563
ERROR(sema_no_import,Fatal,
564564
"no such module '%0'", (StringRef))
565+
ERROR(sema_no_import_arch,Fatal,
566+
"could not find module '%0' for architecture '%1'", (StringRef, StringRef))
565567
ERROR(sema_no_import_repl,none,
566568
"no such module '%0'", (StringRef))
567569
NOTE(sema_no_import_no_sdk,none,

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ findModule(ASTContext &ctx, AccessPathElem moduleID,
8686
std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
8787
std::unique_ptr<llvm::MemoryBuffer> *moduleDocBuffer,
8888
bool &isFramework) {
89-
llvm::SmallString<64> moduleFilename(moduleID.first.str());
89+
llvm::SmallString<64> moduleName(moduleID.first.str());
90+
llvm::SmallString<64> moduleFilename(moduleName);
9091
moduleFilename += '.';
9192
moduleFilename += SERIALIZED_MODULE_EXTENSION;
9293

@@ -96,9 +97,10 @@ findModule(ASTContext &ctx, AccessPathElem moduleID,
9697

9798
// FIXME: Which name should we be using here? Do we care about CPU subtypes?
9899
// FIXME: At the very least, don't hardcode "arch".
99-
llvm::SmallString<16> archFile{
100+
llvm::SmallString<16> archName{
100101
ctx.LangOpts.getPlatformConditionValue(PlatformConditionKind::Arch)};
101-
llvm::SmallString<16> archDocFile{archFile};
102+
llvm::SmallString<16> archFile{archName};
103+
llvm::SmallString<16> archDocFile{archName};
102104
if (!archFile.empty()) {
103105
archFile += '.';
104106
archFile += SERIALIZED_MODULE_EXTENSION;
@@ -122,6 +124,13 @@ findModule(ASTContext &ctx, AccessPathElem moduleID,
122124
archFile.str(), archDocFile.str(),
123125
moduleBuffer, moduleDocBuffer,
124126
scratch);
127+
128+
if(err == std::errc::no_such_file_or_directory) {
129+
ctx.Diags.diagnose(moduleID.second, diag::sema_no_import_arch,
130+
moduleName, archName);
131+
}
132+
133+
return false;
125134
}
126135
if (!err)
127136
return true;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
// RUN: %empty-directory(%t)
3+
// RUN: mkdir %t/new_module.swiftmodule
4+
// RUN: touch %t/new_module.swiftmodule/arm64.swiftmodule
5+
// RUN: %target-swift-frontend %s -typecheck -I %t -verify -show-diagnostics-after-fatal
6+
7+
import new_module // expected-error {{no such module 'new_module'}} expected-error {{could not find module 'new_module' for architecture 'x86_64'}}
8+
9+
new_module.foo() // expected-error {{use of unresolved identifier 'new_module'}}

0 commit comments

Comments
 (0)