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

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rGeac90d1236cf: [clang][deps] During scanning don't emit warnings-as-errors that are ignored… (authored by vsapsai).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138252/new/

https://reviews.llvm.org/D138252

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/diagnostic-pragmas.c


Index: clang/test/ClangScanDeps/diagnostic-pragmas.c
===================================================================
--- /dev/null
+++ 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>
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===================================================================
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -135,8 +135,8 @@
   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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138252.478361.patch
Type: text/x-patch
Size: 2086 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221128/097dca69/attachment.bin>


More information about the cfe-commits mailing list