From 33bdbc66d3ee912e8f50f194a40e5a8237a4ba26 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Tue, 21 Oct 2014 18:03:08 +0000 Subject: [PATCH] Driver: Quote the command in crash reproduction scripts. This fixes crash report generation when filenames have spaces. It also removes an awkward workaround that quoted *some* arguments when generating crash reports. llvm-svn: 220307 --- clang/lib/Driver/Driver.cpp | 2 +- clang/lib/Driver/Job.cpp | 11 ----------- clang/test/Driver/crash report spaces.c | 18 ++++++++++++++++++ clang/test/Driver/crash-report-modules.m | 10 +++++----- clang/test/Driver/crash-report.c | 30 +++++++++++++++--------------- 5 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 clang/test/Driver/crash report spaces.c diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index baf154f..ccefbd8 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -547,7 +547,7 @@ void Driver::generateCompilationDiagnostics(Compilation &C, Diag(clang::diag::note_drv_command_failed_diag_msg) << "Error generating run script: " + Script + " " + EC.message(); } else { - Cmd.Print(ScriptOS, "\n", /*Quote=*/false, &CrashInfo); + Cmd.Print(ScriptOS, "\n", /*Quote=*/true, &CrashInfo); Diag(clang::diag::note_drv_command_failed_diag_msg) << Script; } Diag(clang::diag::note_drv_command_failed_diag_msg) diff --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp index 34d38b9..c5b3f5a 100644 --- a/clang/lib/Driver/Job.cpp +++ b/clang/lib/Driver/Job.cpp @@ -73,12 +73,6 @@ static int skipArgs(const char *Flag) { return 0; } -static bool quoteNextArg(const char *flag) { - return llvm::StringSwitch(flag) - .Case("-D", true) - .Default(false); -} - static void PrintArg(raw_ostream &OS, const char *Arg, bool Quote) { const bool Escape = std::strpbrk(Arg, "\"\\$"); @@ -189,11 +183,6 @@ void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote, OS << ' '; PrintArg(OS, Arg, Quote); - - if (CrashInfo && quoteNextArg(Arg) && i + 1 < e) { - OS << ' '; - PrintArg(OS, Args[++i], true); - } } if (CrashInfo && !CrashInfo->VFSPath.empty()) { diff --git a/clang/test/Driver/crash report spaces.c b/clang/test/Driver/crash report spaces.c new file mode 100644 index 0000000..9bc4626 --- /dev/null +++ b/clang/test/Driver/crash report spaces.c @@ -0,0 +1,18 @@ +// RUN: rm -rf "%t" +// RUN: mkdir "%t" +// RUN: not env TMPDIR="%t" TEMP="%t" TMP="%t" RC_DEBUG_OPTIONS=1 %clang -fsyntax-only "%s" 2>&1 | FileCheck "%s" +// RUN: cat "%t/crash report spaces"-*.c | FileCheck --check-prefix=CHECKSRC "%s" +// RUN: cat "%t/crash report spaces"-*.sh | FileCheck --check-prefix=CHECKSH "%s" +// REQUIRES: crash-recovery + +// because of the glob (*.c, *.sh) +// REQUIRES: shell + +#pragma clang __debug parser_crash +// CHECK: Preprocessed source(s) and associated run script(s) are located at: +// CHECK-NEXT: note: diagnostic msg: {{.*}}.c +FOO +// CHECKSRC: FOO +// CHECKSH: "-cc1" +// CHECKSH: "-main-file-name" "crash report spaces.c" +// CHECKSH: "crash report spaces-{{[^ ]*}}.c" diff --git a/clang/test/Driver/crash-report-modules.m b/clang/test/Driver/crash-report-modules.m index d1c7832..84b1604 100644 --- a/clang/test/Driver/crash-report-modules.m +++ b/clang/test/Driver/crash-report-modules.m @@ -25,8 +25,8 @@ const int x = MODULE_MACRO; // CHECKSRC: @import simple; // CHECKSRC: const int x = 10; -// CHECKSH: -cc1 -// CHECKSH: -D "FOO=BAR" -// CHECKSH-NOT: -fmodules-cache-path=/tmp/ -// CHECKSH: crash-report-modules-{{[^ ]*}}.m -// CHECKSH: -ivfsoverlay crash-report-modules-{{[^ ]*}}.cache/vfs/vfs.yaml +// CHECKSH: "-cc1" +// CHECKSH: "-D" "FOO=BAR" +// CHECKSH-NOT: "-fmodules-cache-path=/tmp/" +// CHECKSH: "crash-report-modules-{{[^ ]*}}.m" +// CHECKSH: "-ivfsoverlay" "crash-report-modules-{{[^ ]*}}.cache/vfs/vfs.yaml" diff --git a/clang/test/Driver/crash-report.c b/clang/test/Driver/crash-report.c index f407a08..3370da8 100644 --- a/clang/test/Driver/crash-report.c +++ b/clang/test/Driver/crash-report.c @@ -18,18 +18,18 @@ // CHECK-NEXT: note: diagnostic msg: {{.*}}crash-report-{{.*}}.c FOO // CHECKSRC: FOO -// CHECKSH: -cc1 -// CHECKSH: -main-file-name crash-report.c -// CHECKSH: -D "FOO=BAR" -// CHECKSH-NOT: -F/tmp/ -// CHECKSH-NOT: -I /tmp/ -// CHECKSH-NOT: -idirafter /tmp/ -// CHECKSH-NOT: -iquote /tmp/ -// CHECKSH-NOT: -isystem /tmp/ -// CHECKSH-NOT: -iprefix /the/prefix -// CHECKSH-NOT: -iwithprefix /tmp/ -// CHECKSH-NOT: -iwithprefixbefore /tmp/ -// CHECKSH-NOT: -internal-isystem /tmp/ -// CHECKSH-NOT: -internal-externc-isystem /tmp/ -// CHECKSH-NOT: -dwarf-debug-flags -// CHECKSH: crash-report-{{[^ ]*}}.c +// CHECKSH: "-cc1" +// CHECKSH: "-main-file-name" "crash-report.c" +// CHECKSH: "-D" "FOO=BAR" +// CHECKSH-NOT: "-F/tmp/" +// CHECKSH-NOT: "-I" "/tmp/" +// CHECKSH-NOT: "-idirafter" "/tmp/" +// CHECKSH-NOT: "-iquote" "/tmp/" +// CHECKSH-NOT: "-isystem" "/tmp/" +// CHECKSH-NOT: "-iprefix" "/the/prefix" +// CHECKSH-NOT: "-iwithprefix" "/tmp/" +// CHECKSH-NOT: "-iwithprefixbefore" "/tmp/" +// CHECKSH-NOT: "-internal-isystem" "/tmp/" +// CHECKSH-NOT: "-internal-externc-isystem" "/tmp/" +// CHECKSH-NOT: "-dwarf-debug-flags" +// CHECKSH: "crash-report-{{[^ ]*}}.c" -- 2.7.4