Skip to content

Commit 899c1f5

Browse files
committed
[Driver] Handle failure-to-exec somewhat more politely, rdar://37865437.
1 parent 3715464 commit 899c1f5

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

lib/Driver/Compilation.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -810,15 +810,29 @@ namespace driver {
810810
do {
811811
using namespace std::placeholders;
812812
// Ask the TaskQueue to execute.
813-
TQ->execute(std::bind(&PerformJobsState::taskBegan, this,
814-
_1, _2),
815-
std::bind(&PerformJobsState::taskFinished, this,
816-
_1, _2, _3, _4, _5),
817-
std::bind(&PerformJobsState::taskSignalled, this,
818-
_1, _2, _3, _4, _5, _6));
819-
820-
// Returning from TaskQueue::execute should mean either an empty
821-
// TaskQueue or a failed subprocess.
813+
if (TQ->execute(std::bind(&PerformJobsState::taskBegan, this,
814+
_1, _2),
815+
std::bind(&PerformJobsState::taskFinished, this,
816+
_1, _2, _3, _4, _5),
817+
std::bind(&PerformJobsState::taskSignalled, this,
818+
_1, _2, _3, _4, _5, _6))) {
819+
if (Result == EXIT_SUCCESS) {
820+
// FIXME: Error from task queue while Result == EXIT_SUCCESS most
821+
// likely means some fork/exec or posix_spawn failed; TaskQueue saw
822+
// "an error" at some stage before even calling us with a process
823+
// exit / signal (or else a poll failed); unfortunately the task
824+
// causing it was dropped on the floor and we have no way to recover
825+
// it here, so we report a very poor, generic error.
826+
Comp.Diags.diagnose(SourceLoc(), diag::error_unable_to_execute_command,
827+
"<unknown>");
828+
Result = -2;
829+
AnyAbnormalExit = true;
830+
return;
831+
}
832+
}
833+
834+
// Returning without error from TaskQueue::execute should mean either an
835+
// empty TaskQueue or a failed subprocess.
822836
assert(!(Result == 0 && TQ->hasRemainingTasks()));
823837

824838
// Task-exit callbacks from TaskQueue::execute may have unblocked jobs,

test/Driver/bad_exec.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// REQUIRES: OS=macosx
2+
// RUN: %empty-directory(%t)
3+
// RUN: not %swiftc_driver -driver-use-frontend-path /always/searching/never/finding %s 2>&1 | %FileCheck %s
4+
// CHECK: unable to execute command
5+
func thing() {
6+
print(1)
7+
}

0 commit comments

Comments
 (0)