[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:17:53 PDT 2021


Szelethus created this revision.
Szelethus added reviewers: Charusso, NoQ, steakhal, martong, vsavchenko.
Szelethus added a project: clang.
Herald added subscribers: manas, ASDenysPetrov, gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun, whisperity.
Szelethus requested review of this revision.
Herald added a subscriber: cfe-commits.

D66572 <https://reviews.llvm.org/D66572> separated `BugReport` and `BugReporter` into basic and path sensitive versions. As a result, checker silencing, which worked deep in the path sensitive report generation facilities became specific to it. This patch moves the corresponding code before the call to the virtual function `generateDiagnosticForConsumerMap` (which is overriden by the specific kinds of bug reporters). Although we see bug reporting as relatively lightweight compared to the analysis, this will get rid of several steps we used to throw away.

Quoting from D65379 <https://reviews.llvm.org/D65379>:

> At a very high level, this consists of 3 steps:
>
> 1. For all `BugReport`s in the same `BugReportEquivClass`, collect all their error nodes in a set. With that set, create a new, trimmed `ExplodedGraph` whose leafs are all error nodes.
> 2. Until a valid report is found, construct a bug path, which is yet another `ExplodedGraph`, that is linear from a given error node to the root of the graph.
> 3. Run all visitors on the constructed bug path. If in this process the report got invalidated, start over from step 2.

Checker silencing used to kick in after all of these. Now it does before any of them :^)


Repository:
  rG LLVM Github Monorepo

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 %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,15 @@
   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]}}
 }
+
+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.346992.patch
Type: text/x-patch
Size: 2417 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210521/035cd608/attachment.bin>


More information about the cfe-commits mailing list