This revision was automatically updated to reflect the committed changes.
Closed by commit rC334526: [analyzer] [NFC] Now let's have only one place 
for diagnostics generation (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D47808?vs=150065&id=150993#toc

Repository:
  rC Clang

https://reviews.llvm.org/D47808

Files:
  lib/StaticAnalyzer/Core/BugReporter.cpp

Index: lib/StaticAnalyzer/Core/BugReporter.cpp
===================================================================
--- lib/StaticAnalyzer/Core/BugReporter.cpp
+++ lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -534,30 +534,6 @@
 }
 
 //===----------------------------------------------------------------------===//
-// "Visitors only" path diagnostic generation algorithm.
-//===----------------------------------------------------------------------===//
-static bool generateVisitorsOnlyPathDiagnostics(
-    PathDiagnostic &PD, PathDiagnosticBuilder &PDB, const ExplodedNode *N,
-    ArrayRef<std::unique_ptr<BugReporterVisitor>> visitors) {
-  // All path generation skips the very first node (the error node).
-  // This is because there is special handling for the end-of-path note.
-  N = N->getFirstPred();
-  if (!N)
-    return true;
-
-  BugReport *R = PDB.getBugReport();
-  while (const ExplodedNode *Pred = N->getFirstPred()) {
-    for (auto &V : visitors)
-      // Visit all the node pairs, but throw the path pieces away.
-      V->VisitNode(N, Pred, PDB, *R);
-
-    N = Pred;
-  }
-
-  return R->isValid();
-}
-
-//===----------------------------------------------------------------------===//
 // "Minimal" path diagnostic generation algorithm.
 //===----------------------------------------------------------------------===//
 using StackDiagPair =
@@ -1285,37 +1261,45 @@
 
 /// There are two path diagnostics generation modes: with adding edges (used
 /// for plists) and without  (used for HTML and text).
-/// When edges are added (\p AddPathEdges),
+/// When edges are added (\p ActiveScheme is Extensive),
 /// the path is modified to insert artificially generated
 /// edges.
 /// Otherwise, more detailed diagnostics is emitted for block edges, explaining
 /// the transitions in words.
 static bool generatePathDiagnostics(
     PathDiagnostic &PD, PathDiagnosticBuilder &PDB, const ExplodedNode *N,
     LocationContextMap &LCM,
     ArrayRef<std::unique_ptr<BugReporterVisitor>> visitors,
-    bool AddPathEdges) {
+    PathDiagnosticConsumer::PathGenerationScheme ActiveScheme) {
   BugReport *report = PDB.getBugReport();
   StackDiagVector CallStack;
   InterestingExprs IE;
+  bool AddPathEdges = (ActiveScheme == PathDiagnosticConsumer::Extensive);
+  bool GenerateDiagnostics = (ActiveScheme != PathDiagnosticConsumer::None);
 
-  PathDiagnosticLocation PrevLoc = PD.getLocation();
+  PathDiagnosticLocation PrevLoc = GenerateDiagnostics ?
+    PD.getLocation() : PathDiagnosticLocation();
 
   const ExplodedNode *NextNode = N->getFirstPred();
   while (NextNode) {
     N = NextNode;
     NextNode = N->getFirstPred();
 
-    generatePathDiagnosticsForNode(
-        N, PD, PrevLoc, PDB, LCM, CallStack, IE, AddPathEdges);
+    if (GenerateDiagnostics)
+      generatePathDiagnosticsForNode(
+          N, PD, PrevLoc, PDB, LCM, CallStack, IE, AddPathEdges);
 
     if (!NextNode)
       continue;
 
     // Add pieces from custom visitors.
     llvm::FoldingSet<PathDiagnosticPiece> DeduplicationSet;
     for (auto &V : visitors) {
       if (auto p = V->VisitNode(N, NextNode, PDB, *report)) {
+
+        if (!GenerateDiagnostics)
+          continue;
+
         if (DeduplicationSet.GetOrInsertNode(p.get()) != p.get())
           continue;
 
@@ -1342,7 +1326,7 @@
 
   // After constructing the full PathDiagnostic, do a pass over it to compact
   // PathDiagnosticPieces that occur within a macro.
-  if (!AddPathEdges)
+  if (!AddPathEdges && GenerateDiagnostics)
     CompactPathDiagnostic(PD.getMutablePieces(), PDB.getSourceManager());
 
   return true;
@@ -2599,19 +2583,7 @@
       // hold onto old mappings.
       LCM.clear();
 
-      switch (ActiveScheme) {
-      case PathDiagnosticConsumer::Extensive:
-        generatePathDiagnostics(PD, PDB, N, LCM, visitors,
-                               /*AddPathEdges=*/true);
-        break;
-      case PathDiagnosticConsumer::Minimal:
-        generatePathDiagnostics(PD, PDB, N, LCM, visitors,
-                               /*AddPathEdges=*/false);
-        break;
-      case PathDiagnosticConsumer::None:
-        generateVisitorsOnlyPathDiagnostics(PD, PDB, N, visitors);
-        break;
-      }
+      generatePathDiagnostics(PD, PDB, N, LCM, visitors, ActiveScheme);
 
       // Clean up the visitors we used.
       visitors.clear();
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to