[PATCH] D97265: [clang] Allow clang-check to customize analyzer output file or dir name
Ella Ma via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 7 20:37:04 PST 2021
OikawaKirie updated this revision to Diff 328927.
OikawaKirie added a comment.
Replace concatenating the output from clang-check and plist with separated checks to workaround the test failure on Windows.
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,7 +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)),
cl::cat(ClangCheckCategory));
@@ -206,7 +209,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}}
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97265.328927.patch
Type: text/x-patch
Size: 2408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210308/11aaa202/attachment.bin>
More information about the cfe-commits
mailing list