[PATCH] D102914: [analyzer] Make checker silencing work for non-pathsensitive bug reports

Kristóf Umann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 21 05:58:10 PDT 2021


Szelethus updated this revision to Diff 347003.
Szelethus added a comment.

Fix the test file.


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

https://reviews.llvm.org/D102914

Files:
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/test/Analysis/silence-checkers-malloc.cpp
  clang/test/Analysis/silence-checkers.cpp


Index: clang/test/Analysis/silence-checkers.cpp
===================================================================
--- clang/test/Analysis/silence-checkers.cpp
+++ clang/test/Analysis/silence-checkers.cpp
@@ -11,6 +11,12 @@
 // RUN:   -analyzer-checker=cplusplus.NewDelete\
 // RUN:   -analyzer-config silence-checkers="unix"
 
+// RUN: %clang_analyze_cc1 -verify="deadstore-silenced" %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling \
+// RUN:   -analyzer-checker=deadcode \
+// RUN:   -analyzer-config silence-checkers="deadcode.DeadStores"
+
 #include "Inputs/system-header-simulator-cxx.h"
 
 typedef __typeof(sizeof(int)) size_t;
@@ -38,3 +44,17 @@
   delete Ptr; // no-silence-warning{{Argument to 'delete' is a constant address (16), which is not memory allocated by 'new' [cplusplus.NewDelete]}}
               // unix-silenced-warning at -1{{Argument to 'delete' is a constant address (16), which is not memory allocated by 'new' [cplusplus.NewDelete]}}
 }
+
+// deadstore-silenced-no-diagnostics
+
+int foo() {
+  int x = 42;
+  return x;
+}
+
+void g() {
+  int y;
+  y = 7;
+  int x = foo();
+  y = 10;
+}
Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -1989,13 +1989,6 @@
   const SourceManager &SM = getSourceManager();
   const AnalyzerOptions &Opts = getAnalyzerOptions();
 
-  // See whether we need to silence the checker/package.
-  // FIXME: This will not work if the report was emitted with an incorrect tag.
-  for (const std::string &CheckerOrPackage : Opts.SilencedCheckersAndPackages) {
-    if (R->getBugType().getCheckerName().startswith(CheckerOrPackage))
-      return nullptr;
-  }
-
   if (!PDC->shouldGenerateDiagnostics())
     return generateEmptyDiagnosticForReport(R, getSourceManager());
 
@@ -3040,6 +3033,14 @@
   if (!report)
     return;
 
+  // See whether we need to silence the checker/package.
+  for (const std::string &CheckerOrPackage :
+       getAnalyzerOptions().SilencedCheckersAndPackages) {
+    if (report->getBugType().getCheckerName().startswith(
+            CheckerOrPackage))
+      return;
+  }
+
   ArrayRef<PathDiagnosticConsumer*> Consumers = getPathDiagnosticConsumers();
   std::unique_ptr<DiagnosticForConsumerMapTy> Diagnostics =
       generateDiagnosticForConsumerMap(report, Consumers, bugReports);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102914.347003.patch
Type: text/x-patch
Size: 2478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210521/5a9ddc7d/attachment-0001.bin>


More information about the cfe-commits mailing list