[Driver] Create non-existent directory for -fcrash-diagnostics-dir
authorPetr Hosek <phosek@chromium.org>
Sat, 4 May 2019 00:55:14 +0000 (00:55 +0000)
committerPetr Hosek <phosek@chromium.org>
Sat, 4 May 2019 00:55:14 +0000 (00:55 +0000)
When user specifies non-existent directory to -fcrash-diagnostics-dir,
create it rather than failing with an error as would be the case before.

Differential Revision: https://reviews.llvm.org/D61542

llvm-svn: 359954

clang/lib/Driver/Driver.cpp
clang/test/Driver/crash-diagnostics-dir.c

index 238315e..06c0e3b 100644 (file)
@@ -4263,6 +4263,8 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
     Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
     if (CCGenDiagnostics && A) {
       SmallString<128> CrashDirectory(A->getValue());
+      if (!getVFS().exists(CrashDirectory))
+        llvm::sys::fs::create_directories(CrashDirectory);
       llvm::sys::path::append(CrashDirectory, Split.first);
       const char *Middle = Suffix ? "-%%%%%%." : "-%%%%%%";
       std::error_code EC = llvm::sys::fs::createUniqueFile(
index c8faf49..44c4af6 100644 (file)
@@ -1,5 +1,4 @@
 // RUN: rm -rf %t
-// RUN: mkdir -p %t
 // RUN: not %clang -fcrash-diagnostics-dir=%t -c %s -o - 2>&1 | FileCheck %s
 #pragma clang __debug parser_crash
 // CHECK: Preprocessed source(s) and associated run script(s) are located at: