Skip to content

Commit 632399e

Browse files
authored
[Driver] Include more info in "crash because TMPDIR is borked" errors (#27412)
Two places in Driver are creating temporary files at a point in the process where failure is not expected. We should do something better about this, but meanwhile harmonize their failures and include a little more info. Filed https://bugs.swift.org/browse/SR-11541 to improve this.
1 parent 02e1d6e commit 632399e

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

lib/Driver/Compilation.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,11 +1558,13 @@ const char *Compilation::getAllSourcesPath() const {
15581558
std::error_code EC =
15591559
llvm::sys::fs::createTemporaryFile("sources", "", Buffer);
15601560
if (EC) {
1561-
Diags.diagnose(SourceLoc(),
1562-
diag::error_unable_to_make_temporary_file,
1563-
EC.message());
1561+
// Use the constructor that prints both the error code and the
1562+
// description.
15641563
// FIXME: This should not take down the entire process.
1565-
llvm::report_fatal_error("unable to create list of input sources");
1564+
auto error = llvm::make_error<llvm::StringError>(
1565+
EC,
1566+
"- unable to create list of input sources");
1567+
llvm::report_fatal_error(std::move(error));
15661568
}
15671569
auto *mutableThis = const_cast<Compilation *>(this);
15681570
mutableThis->addTemporaryFile(Buffer.str(), PreserveOnSignal::Yes);

lib/Driver/ToolChain.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ ToolChain::JobContext::getTemporaryFilePath(const llvm::Twine &name,
5252
SmallString<128> buffer;
5353
std::error_code EC = llvm::sys::fs::createTemporaryFile(name, suffix, buffer);
5454
if (EC) {
55+
// Use the constructor that prints both the error code and the description.
5556
// FIXME: This should not take down the entire process.
56-
llvm::report_fatal_error("unable to create temporary file for filelist");
57+
auto error = llvm::make_error<llvm::StringError>(
58+
EC,
59+
"- unable to create temporary file for " + name + "." + suffix);
60+
llvm::report_fatal_error(std::move(error));
5761
}
5862

5963
C.addTemporaryFile(buffer.str(), PreserveOnSignal::Yes);

test/Driver/bad_tmpdir.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Check a handful of failures in the driver when TMPDIR can't be accessed.
2+
//
3+
// These particular error messages are kind of finicky to hit because they
4+
// depend on what commands the driver needs to execute on each platform, so the
5+
// test is somewhat artificially limited to macOS.
6+
//
7+
// REQUIRES: OS=macosx
8+
9+
// RUN: env TMP="%t/fake/" TMPDIR="%t/fake/" not %target-build-swift -c -driver-filelist-threshold=0 %s 2>&1 | %FileCheck -check-prefix=CHECK-SOURCES %s
10+
11+
// CHECK-SOURCES: - unable to create list of input sources
12+
13+
// RUN: echo > %t.o
14+
// RUN: env TMP="%t/fake/" TMPDIR="%t/fake/" not %target-build-swift -driver-filelist-threshold=0 %t.o 2>&1 | %FileCheck -check-prefix=CHECK-FILELIST %s
15+
16+
// CHECK-FILELIST: - unable to create temporary file for inputs.LinkFileList

0 commit comments

Comments
 (0)