[clang] eac90d1 - [clang][deps] During scanning don't emit warnings-as-errors that are ignored with diagnostic pragmas.

Volodymyr Sapsai via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 28 13:48:42 PST 2022


Author: Volodymyr Sapsai
Date: 2022-11-28T13:48:29-08:00
New Revision: eac90d1236cfd2935fac5cbe5634f09e2cd0981a

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

LOG: [clang][deps] During scanning don't emit warnings-as-errors that are ignored with diagnostic pragmas.

Before the fix the scanning would fail with
`-Werror,-Wnon-modular-include-in-module` despite the warning being
suppressed in the source code.

Existing approach with `-Wno-error` is not sufficient because it negates
only general `-Werror` but not specific `-Werror=...` and some warnings
can still emitted as errors. Make the approach stricter by using `-w`
flag and ignore all warnings, including those upgraded to errors. This
approach is still valid as it doesn't affect the dependencies.

rdar://101588531

Differential Revision: https://reviews.llvm.org/D138252

Added: 
    clang/test/ClangScanDeps/diagnostic-pragmas.c

Modified: 
    clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 50c42087d2fa..ff2d4b76820e 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -135,8 +135,8 @@ static void sanitizeDiagOpts(DiagnosticOptions &DiagOpts) {
   DiagOpts.ShowCarets = false;
   // Don't write out diagnostic file.
   DiagOpts.DiagnosticSerializationFile.clear();
-  // Don't treat warnings as errors.
-  DiagOpts.Warnings.push_back("no-error");
+  // Don't emit warnings as errors (and all other warnings too).
+  DiagOpts.IgnoreWarnings = true;
 }
 
 /// A clang tool that runs the preprocessor in a mode that's optimized for

diff  --git a/clang/test/ClangScanDeps/diagnostic-pragmas.c b/clang/test/ClangScanDeps/diagnostic-pragmas.c
new file mode 100644
index 000000000000..520f82047d2b
--- /dev/null
+++ b/clang/test/ClangScanDeps/diagnostic-pragmas.c
@@ -0,0 +1,35 @@
+// Test scanning deps does not have more errors than the regular compilation.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// Check the regular compilation does not fail.
+// RUN: %clang -fsyntax-only %t/test.c -I %t/include -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -Wnon-modular-include-in-module -Werror=non-modular-include-in-module
+
+// And now scanning deps should succeed too.
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -j 1
+
+//--- cdb.json.template
+[
+  {
+    "directory": "DIR",
+    "command": "clang -fsyntax-only DIR/test.c -I DIR/include -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -Wnon-modular-include-in-module -Werror=non-modular-include-in-module",
+    "file": "DIR/test.c"
+  },
+]
+
+//--- include/nonmodular.h
+// empty
+
+//--- include/modular-includer.h
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnon-modular-include-in-module"
+#include <nonmodular.h>
+#pragma clang diagnostic pop
+
+//--- include/module.modulemap
+module ModularIncluder { header "modular-includer.h" }
+
+//--- test.c
+#include <modular-includer.h>


        


More information about the cfe-commits mailing list