This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGda168dd875bf: [clang] Allow clang-check to customize analyzer output file or dir name (authored by OikawaKirie, committed by kbobyrev). Herald added a subscriber: manas.
Changed prior to commit: https://reviews.llvm.org/D97265?vs=328927&id=387266#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97265/new/ https://reviews.llvm.org/D97265 Files: clang/test/Tooling/clang-check-set-analyzer-output-path.cpp clang/tools/clang-check/ClangCheck.cpp Index: clang/tools/clang-check/ClangCheck.cpp =================================================================== --- clang/tools/clang-check/ClangCheck.cpp +++ clang/tools/clang-check/ClangCheck.cpp @@ -76,6 +76,10 @@ Analyze("analyze", cl::desc(Options.getOptionHelpText(options::OPT_analyze)), cl::cat(ClangCheckCategory)); +static cl::opt<std::string> + AnalyzerOutput("analyzer-output-path", + cl::desc(Options.getOptionHelpText(options::OPT_o)), + cl::cat(ClangCheckCategory)); static cl::opt<bool> Fixit("fixit", cl::desc(Options.getOptionHelpText(options::OPT_fixit)), @@ -206,7 +210,19 @@ // 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( + Analyze ? [&](const CommandLineArguments &Args, StringRef File) { + auto Ret = getClangStripOutputAdjuster()(Args, File); + if (!AnalyzerOutput.empty()) { + Ret.emplace_back("-o"); + Ret.emplace_back(AnalyzerOutput); + } + return Ret; + } + : getClangStripOutputAdjuster()); + Tool.appendArgumentsAdjuster(getClangStripDependencyFileAdjuster()); // Running the analyzer requires --analyze. Other modes can work with the Index: clang/test/Tooling/clang-check-set-analyzer-output-path.cpp =================================================================== --- /dev/null +++ clang/test/Tooling/clang-check-set-analyzer-output-path.cpp @@ -0,0 +1,14 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: cd %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: echo '// CHECK: {{qwerty}}' > %t/cclog-check +// RUN: clang-check -p "%t" "%t/test.cpp" -analyze -analyzer-output-path=%t/qwerty -extra-arg=-v -extra-arg=-Xclang -extra-arg=-verify 2>&1 | FileCheck %t/cclog-check +// RUN: FileCheck %s --input-file=%t/qwerty + +// CHECK: DOCTYPE plist +// CHECK: Division by zero +int f() { + return 1 / 0; // expected-warning {{Division by zero}} +}
Index: clang/tools/clang-check/ClangCheck.cpp =================================================================== --- clang/tools/clang-check/ClangCheck.cpp +++ clang/tools/clang-check/ClangCheck.cpp @@ -76,6 +76,10 @@ Analyze("analyze", cl::desc(Options.getOptionHelpText(options::OPT_analyze)), cl::cat(ClangCheckCategory)); +static cl::opt<std::string> + AnalyzerOutput("analyzer-output-path", + cl::desc(Options.getOptionHelpText(options::OPT_o)), + cl::cat(ClangCheckCategory)); static cl::opt<bool> Fixit("fixit", cl::desc(Options.getOptionHelpText(options::OPT_fixit)), @@ -206,7 +210,19 @@ // 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( + Analyze ? [&](const CommandLineArguments &Args, StringRef File) { + auto Ret = getClangStripOutputAdjuster()(Args, File); + if (!AnalyzerOutput.empty()) { + Ret.emplace_back("-o"); + Ret.emplace_back(AnalyzerOutput); + } + return Ret; + } + : getClangStripOutputAdjuster()); + Tool.appendArgumentsAdjuster(getClangStripDependencyFileAdjuster()); // Running the analyzer requires --analyze. Other modes can work with the Index: clang/test/Tooling/clang-check-set-analyzer-output-path.cpp =================================================================== --- /dev/null +++ clang/test/Tooling/clang-check-set-analyzer-output-path.cpp @@ -0,0 +1,14 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: cd %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: echo '// CHECK: {{qwerty}}' > %t/cclog-check +// RUN: clang-check -p "%t" "%t/test.cpp" -analyze -analyzer-output-path=%t/qwerty -extra-arg=-v -extra-arg=-Xclang -extra-arg=-verify 2>&1 | FileCheck %t/cclog-check +// RUN: FileCheck %s --input-file=%t/qwerty + +// CHECK: DOCTYPE plist +// CHECK: Division by zero +int f() { + return 1 / 0; // expected-warning {{Division by zero}} +}
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits