// Strip away options not necessary to reproduce the crash.
// FIXME: This doesn't work with quotes (e.g., -D "foo bar").
SmallVector<std::string, 16> Flag;
+ Flag.push_back("-D ");
Flag.push_back("-F");
Flag.push_back("-I ");
+ Flag.push_back("-M ");
+ Flag.push_back("-MD ");
+ Flag.push_back("-MF ");
+ Flag.push_back("-MG ");
+ Flag.push_back("-MM ");
+ Flag.push_back("-MMD ");
+ Flag.push_back("-MP ");
+ Flag.push_back("-MQ ");
+ Flag.push_back("-MT ");
Flag.push_back("-o ");
Flag.push_back("-coverage-file ");
Flag.push_back("-dependency-file ");
Flag.push_back("-include ");
Flag.push_back("-include-pch ");
Flag.push_back("-isysroot ");
+ Flag.push_back("-iquote ");
Flag.push_back("-resource-dir ");
Flag.push_back("-serialize-diagnostic-file ");
for (unsigned i = 0, e = Flag.size(); i < e; ++i) {
E = Cmd.find(" ", I + Flag[i].length());
if (E == std::string::npos) break;
- Cmd.erase(I, E - I + 1);
+ // The -D option is not removed. Instead, the argument is quoted.
+ if (Flag[i] != "-D ") {
+ Cmd.erase(I, E - I + 1);
+ } else {
+ Cmd.insert(I+3, "\"");
+ Cmd.insert(++E, "\"");
+ I = E;
+ }
} while(1);
}
// Append the new filename with correct preprocessed suffix.
// RUN: rm -rf %t
// RUN: mkdir %t
-// RUN: env TMPDIR=%t TEMP=%t TMP=%t %clang -fsyntax-only %s -DFOO=BAR 2>&1 | FileCheck %s
+// RUN: env TMPDIR=%t TEMP=%t TMP=%t %clang -fsyntax-only %s \
+// RUN: -F/tmp/ -I /tmp/ -iquote /tmp/ -DFOO=BAR 2>&1 | FileCheck %s
// RUN: cat %t/crash-report-*.c | FileCheck --check-prefix=CHECKSRC %s
// RUN: cat %t/crash-report-*.sh | FileCheck --check-prefix=CHECKSH %s
// REQUIRES: crash-recovery
// CHECK-NEXT: note: diagnostic msg: {{.*}}.c
FOO
// CHECKSRC: FOO
-// CHECKSH: -D FOO=BAR
+// CHECKSH: -D "FOO=BAR"
+// CHECKSH-NOT: -F/tmp/
+// CHECKSH-NOT: -I /tmp/
+// CHECKSH-NOT: -iquote /tmp/