[clang] 35fa3e6 - [clang][deps] Move stripping of diagnostic serialization from `clang-scan-deps` to `DependencyScanning` library
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 14 03:23:39 PDT 2021
Author: Jan Svoboda
Date: 2021-06-14T12:23:32+02:00
New Revision: 35fa3e60d1612dcc4f8e233b046423d948ca9a9b
URL: https://github.com/llvm/llvm-project/commit/35fa3e60d1612dcc4f8e233b046423d948ca9a9b
DIFF: https://github.com/llvm/llvm-project/commit/35fa3e60d1612dcc4f8e233b046423d948ca9a9b.diff
LOG: [clang][deps] Move stripping of diagnostic serialization from `clang-scan-deps` to `DependencyScanning` library
To prevent the creation of diagnostics file, `clang-scan-deps` strips the corresponding command-line argument. This behavior is useful even when using the C++ `DependencyScanner` library.
This patch transforms stripping of command-line in `clang-scan-deps` into stripping of `CompilerInvocation` in `DependencyScanning`.
AFAIK, the `clang-cl` driver doesn't even accept `--serialize-diagnostics`, so I've removed the test. (It would fail with an unknown command-line argument otherwise.)
Note: Since we're generating command-lines for modular dependencies from `CompilerInvocation`, the `--serialize-diagnostics` will be dropped. This was already happening in `clang-scan-deps` before this patch, but it will now happen also when using `DependencyScanning` library directly. This is resolved in D104036.
Reviewed By: dexonsmith, arphaman
Differential Revision: https://reviews.llvm.org/D104012
Added:
Modified:
clang/include/clang/Tooling/ArgumentsAdjusters.h
clang/lib/Tooling/ArgumentsAdjusters.cpp
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
clang/test/ClangScanDeps/strip_diag_serialize.cpp
clang/tools/clang-scan-deps/ClangScanDeps.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Tooling/ArgumentsAdjusters.h b/clang/include/clang/Tooling/ArgumentsAdjusters.h
index c48a8725aae9..bf0886034324 100644
--- a/clang/include/clang/Tooling/ArgumentsAdjusters.h
+++ b/clang/include/clang/Tooling/ArgumentsAdjusters.h
@@ -43,10 +43,6 @@ ArgumentsAdjuster getClangSyntaxOnlyAdjuster();
/// arguments.
ArgumentsAdjuster getClangStripOutputAdjuster();
-/// Gets an argument adjuster which removes command line arguments related to
-/// diagnostic serialization.
-ArgumentsAdjuster getClangStripSerializeDiagnosticAdjuster();
-
/// Gets an argument adjuster which removes dependency-file
/// related command line arguments.
ArgumentsAdjuster getClangStripDependencyFileAdjuster();
diff --git a/clang/lib/Tooling/ArgumentsAdjusters.cpp b/clang/lib/Tooling/ArgumentsAdjusters.cpp
index d94673bd2ab9..7f5dc4d62f11 100644
--- a/clang/lib/Tooling/ArgumentsAdjusters.cpp
+++ b/clang/lib/Tooling/ArgumentsAdjusters.cpp
@@ -86,22 +86,6 @@ ArgumentsAdjuster getClangStripOutputAdjuster() {
};
}
-ArgumentsAdjuster getClangStripSerializeDiagnosticAdjuster() {
- return [](const CommandLineArguments &Args, StringRef /*unused*/) {
- CommandLineArguments AdjustedArgs;
- for (size_t i = 0, e = Args.size(); i < e; ++i) {
- StringRef Arg = Args[i];
- if (Arg == "--serialize-diagnostics") {
- // Skip the diagnostic output argument.
- ++i;
- continue;
- }
- AdjustedArgs.push_back(Args[i]);
- }
- return AdjustedArgs;
- };
-}
-
ArgumentsAdjuster getClangStripDependencyFileAdjuster() {
return [](const CommandLineArguments &Args, StringRef /*unused*/) {
auto UsingClDriver = (getDriverMode(Args) == "cl");
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index ebcd16e5ab6f..40466b00f0e5 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -85,6 +85,8 @@ class DependencyScanningAction : public tooling::ToolAction {
// Don't print 'X warnings and Y errors generated'.
Compiler.getDiagnosticOpts().ShowCarets = false;
+ // Don't write out diagnostic file.
+ Compiler.getDiagnosticOpts().DiagnosticSerializationFile.clear();
// Create the compiler's actual diagnostics engine.
Compiler.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false);
if (!Compiler.hasDiagnostics())
diff --git a/clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json b/clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
index 7af1acdc378a..a774d95a3b02 100644
--- a/clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
+++ b/clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
@@ -3,10 +3,5 @@
"directory": "DIR",
"command": "clang -E -fsyntax-only DIR/strip_diag_serialize_input.cpp --serialize-diagnostics /does/not/exist",
"file": "DIR/strip_diag_serialize_input.cpp"
-},
-{
- "directory": "DIR",
- "command": "clang-cl /E --serialize-diagnostics A:/does/not/exist -- DIR/strip_diag_serialize_input_clangcl.cpp",
- "file": "DIR/strip_diag_serialize_input_clangcl.cpp"
}
]
diff --git a/clang/test/ClangScanDeps/strip_diag_serialize.cpp b/clang/test/ClangScanDeps/strip_diag_serialize.cpp
index d9f758882027..c8713be7f3b7 100644
--- a/clang/test/ClangScanDeps/strip_diag_serialize.cpp
+++ b/clang/test/ClangScanDeps/strip_diag_serialize.cpp
@@ -8,6 +8,5 @@
// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 2>&1 | FileCheck %s
// CHECK-NOT: unable to open file
// CHECK: strip_diag_serialize_input.cpp
-// CHECK: strip_diag_serialize_input_clangcl.cpp
#warning "diagnostic"
diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index ce8be72bc291..625a4c1ef923 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -571,8 +571,6 @@ int main(int argc, const char **argv) {
AdjustedArgs.insert(AdjustedArgs.end(), FlagsEnd, Args.end());
return AdjustedArgs;
});
- AdjustingCompilations->appendArgumentsAdjuster(
- tooling::getClangStripSerializeDiagnosticAdjuster());
SharedStream Errs(llvm::errs());
// Print out the dependency results to STDOUT by default.
More information about the cfe-commits
mailing list