Skip to content

Commit 4c47bd1

Browse files
authored
[swift-ide-test] Bail out when a module couldn't be loaded (#15563)
The importer in particular depends on the stdlib and the Foundation overlay being successfully loaded, so if anything /can't/ be loaded we have to assume that trying to walk a module's decls will result in a crash. rdar://problem/37540394
1 parent 76c264e commit 4c47bd1

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: not %swift-ide-test -source-filename %s -print-module -module-to-print Swift -target x86_64-unknown-solaris
2+
3+
// RUN: not %swift-ide-test -source-filename %s -print-module -module-to-print Swift -target x86_64-apple-macosx10.6 -sdk %sdk
4+
// RUN: not %swift-ide-test -source-filename %s -print-module -module-to-print CoreServices -target x86_64-apple-macosx10.6 -sdk %sdk
5+
6+
// RUN: %empty-directory(%t)
7+
// RUN: %target-swift-frontend -emit-module -o %t -module-name Dummy -target x86_64-apple-macosx10.99 %s
8+
// RUN: not %target-swift-ide-test -source-filename %s -print-module -module-to-print Dummy -I %t
9+
10+
// REQUIRES: OS=macosx

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,11 +1490,18 @@ static ModuleDecl *getModuleByFullName(ASTContext &Context, StringRef ModuleName
14901490
AccessPath.push_back(
14911491
{ Context.getIdentifier(SubModuleName), SourceLoc() });
14921492
}
1493-
return Context.getModule(AccessPath);
1493+
ModuleDecl *Result = Context.getModule(AccessPath);
1494+
if (!Result || Result->failedToLoad())
1495+
return nullptr;
1496+
return Result;
14941497
}
14951498

14961499
static ModuleDecl *getModuleByFullName(ASTContext &Context, Identifier ModuleName) {
1497-
return Context.getModule(std::make_pair(ModuleName, SourceLoc()));
1500+
ModuleDecl *Result = Context.getModule(std::make_pair(ModuleName,
1501+
SourceLoc()));
1502+
if (!Result || Result->failedToLoad())
1503+
return nullptr;
1504+
return Result;
14981505
}
14991506

15001507
static int doPrintAST(const CompilerInvocation &InitInvok,

0 commit comments

Comments
 (0)