[clang] 993f60a - [clang][deps] Sanitize both instances of DiagnosticOptions

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 10 05:48:10 PDT 2021


Author: Jan Svoboda
Date: 2021-09-10T14:47:21+02:00
New Revision: 993f60ae32de001ac9ac1ff512f2adf339e265c8

URL: https://github.com/llvm/llvm-project/commit/993f60ae32de001ac9ac1ff512f2adf339e265c8
DIFF: https://github.com/llvm/llvm-project/commit/993f60ae32de001ac9ac1ff512f2adf339e265c8.diff

LOG: [clang][deps] Sanitize both instances of DiagnosticOptions

During dependency scanning, we generally want to suppress -Werror. Apply the same logic to the DiagnosticOptions instance used for command-line parsing.

This fixes a test failure on the PS4 bot, where the system header directory could not be found, which was reported due to -Werror being on the command line and not being sanitized.

Added: 
    

Modified: 
    clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
    clang/test/ClangScanDeps/error.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index faf7d36bf87b8..e4d49756ce6b4 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -133,6 +133,16 @@ deduceDepTarget(const std::string &OutputFile,
   return makeObjFileName(InputFiles.front().getFile());
 }
 
+/// Sanitize diagnostic options for dependency scan.
+static void sanitizeDiagOpts(DiagnosticOptions &DiagOpts) {
+  // Don't print 'X warnings and Y errors generated'.
+  DiagOpts.ShowCarets = false;
+  // Don't write out diagnostic file.
+  DiagOpts.DiagnosticSerializationFile.clear();
+  // Don't treat warnings as errors.
+  DiagOpts.Warnings.push_back("no-error");
+}
+
 /// A clang tool that runs the preprocessor in a mode that's optimized for
 /// dependency scanning for the given compiler invocation.
 class DependencyScanningAction : public tooling::ToolAction {
@@ -157,13 +167,8 @@ class DependencyScanningAction : public tooling::ToolAction {
     CompilerInstance Compiler(std::move(PCHContainerOps));
     Compiler.setInvocation(std::move(Invocation));
 
-    // Don't print 'X warnings and Y errors generated'.
-    Compiler.getDiagnosticOpts().ShowCarets = false;
-    // Don't write out diagnostic file.
-    Compiler.getDiagnosticOpts().DiagnosticSerializationFile.clear();
-    // Don't treat warnings as errors.
-    Compiler.getDiagnosticOpts().Warnings.push_back("no-error");
     // Create the compiler's actual diagnostics engine.
+    sanitizeDiagOpts(Compiler.getDiagnosticOpts());
     Compiler.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false);
     if (!Compiler.hasDiagnostics())
       return false;
@@ -304,8 +309,7 @@ static llvm::Error
 runWithDiags(DiagnosticOptions *DiagOpts,
              llvm::function_ref<bool(DiagnosticConsumer &, DiagnosticOptions &)>
                  BodyShouldSucceed) {
-  // Avoid serializing diagnostics.
-  DiagOpts->DiagnosticSerializationFile.clear();
+  sanitizeDiagOpts(*DiagOpts);
 
   // Capture the emitted diagnostics and report them to the client
   // in the case of a failure.

diff  --git a/clang/test/ClangScanDeps/error.cpp b/clang/test/ClangScanDeps/error.cpp
index e18bf302af26f..d94ba4c03e508 100644
--- a/clang/test/ClangScanDeps/error.cpp
+++ b/clang/test/ClangScanDeps/error.cpp
@@ -21,10 +21,6 @@
 // CHECK-NEXT: error:
 // CHECK-NEXT: Error while scanning dependencies
 // CHECK-NEXT: fatal error: 'missing.h' file not found
-// CHECK-NEXT: "missing.h"
-// CHECK-NEXT: ^
 // CHECK-NEXT: Error while scanning dependencies
 // CHECK-NEXT: fatal error: 'missing.h' file not found
-// CHECK-NEXT: "missing.h"
-// CHECK-NEXT: ^
 // CHECK-NEXT: EOF


        


More information about the cfe-commits mailing list