Index: clang/test/Tooling/clang-check-reset-o.cpp =================================================================== --- /dev/null +++ clang/test/Tooling/clang-check-reset-o.cpp @@ -0,0 +1,11 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: echo '[{"directory":".","command":"clang++ -c %t/test.cpp -o foo -ofoo","file":"%t/test.cpp"}]' | sed -e 's/\\/\//g' > %t/compile_commands.json +// RUN: cp "%s" "%t/test.cpp" +// RUN: not clang-check -p "%t" "%t/test.cpp" -analyze -output=qwerty -extra-arg=-v 2>&1|FileCheck %s +// FIXME: Make the above easier. + +// CHECK: Invocation +// CHECK: {{qwerty}} +// CHECK: C++ requires +invalid; Index: clang/tools/clang-check/ClangCheck.cpp =================================================================== --- clang/tools/clang-check/ClangCheck.cpp +++ clang/tools/clang-check/ClangCheck.cpp @@ -76,7 +76,9 @@ Analyze("analyze", cl::desc(Options.getOptionHelpText(options::OPT_analyze)), cl::cat(ClangCheckCategory)); - +static cl::opt + Output("output", cl::desc(Options.getOptionHelpText(options::OPT_o)), + cl::cat(ClangCheckCategory)); static cl::opt Fixit("fixit", cl::desc(Options.getOptionHelpText(options::OPT_fixit)), cl::cat(ClangCheckCategory)); @@ -206,7 +208,18 @@ // Clear adjusters because -fsyntax-only is inserted by the default chain. Tool.clearArgumentsAdjusters(); - Tool.appendArgumentsAdjuster(getClangStripOutputAdjuster()); + + // Reset output path if is provided by user. + Tool.appendArgumentsAdjuster( + [&](const CommandLineArguments &Args, StringRef File) { + auto Ret = getClangStripOutputAdjuster()(Args, File); + if (!Output.empty()) { + Ret.emplace_back("-o"); + Ret.emplace_back(Output); + } + return Ret; + }); + Tool.appendArgumentsAdjuster(getClangStripDependencyFileAdjuster()); // Running the analyzer requires --analyze. Other modes can work with the