[cfe-commits] r49412 - in /cfe/trunk: include/clang/Analysis/PathSensitive/BugReporter.h lib/Analysis/BugReporter.cpp

Ted Kremenek kremenek at apple.com
Tue Apr 8 17:20:43 PDT 2008


Author: kremenek
Date: Tue Apr  8 19:20:43 2008
New Revision: 49412

URL: http://llvm.org/viewvc/llvm-project?rev=49412&view=rev
Log:
Added new "BugReporterHelper" class which is used by BugReporter to emit
checker-specific diagnostics.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
    cfe/trunk/lib/Analysis/BugReporter.cpp

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h?rev=49412&r1=49411&r2=49412&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Tue Apr  8 19:20:43 2008
@@ -46,6 +46,16 @@
                          const SourceRange*& end) const;
 };
   
+class BugReporterHelper {
+public:
+  virtual ~BugReporterHelper() {}
+  
+  virtual PathDiagnosticPiece* VisitNode(ExplodedNode<ValueState>* N,
+                                         ExplodedNode<ValueState>* PrevN,
+                                         ExplodedGraph<GRExprEngine>& G,
+                                         ASTContext& Ctx) = 0;
+};
+  
 class BugReporter {
   llvm::SmallPtrSet<void*,10> CachedErrors;
   
@@ -56,7 +66,9 @@
   void EmitPathWarning(Diagnostic& Diag, PathDiagnosticClient* PDC,
                        ASTContext& Ctx, const BugDescription& B,
                        ExplodedGraph<GRExprEngine>& G,
-                       ExplodedNode<ValueState>* N);
+                       ExplodedNode<ValueState>* N,
+                       BugReporterHelper** BegHelpers = NULL,
+                       BugReporterHelper** EndHelpers = NULL);
   
   void EmitWarning(Diagnostic& Diag, ASTContext& Ctx,
                    const BugDescription& B,
@@ -69,7 +81,9 @@
   void GeneratePathDiagnostic(PathDiagnostic& PD, ASTContext& Ctx,
                               const BugDescription& B,
                               ExplodedGraph<GRExprEngine>& G,
-                              ExplodedNode<ValueState>* N);
+                              ExplodedNode<ValueState>* N,
+                              BugReporterHelper** BegHelpers = NULL,
+                              BugReporterHelper** EndHelpers = NULL);
 };
   
 } // end clang namespace

Modified: cfe/trunk/lib/Analysis/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BugReporter.cpp?rev=49412&r1=49411&r2=49412&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Tue Apr  8 19:20:43 2008
@@ -83,7 +83,9 @@
 void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, ASTContext& Ctx,
                                          const BugDescription& B,
                                          ExplodedGraph<GRExprEngine>& G,
-                                         ExplodedNode<ValueState>* N) {
+                                         ExplodedNode<ValueState>* N,
+                                         BugReporterHelper** BegHelpers,
+                                         BugReporterHelper** EndHelpers) {
   
   if (PathDiagnosticPiece* Piece = B.getEndPath(Ctx,N))
     PD.push_back(Piece);
@@ -112,11 +114,15 @@
   assert (NewN->getLocation() == N->getLocation());
   
   N = NewN;
-
-  while (!N->pred_empty()) {
+  
+  ExplodedNode<ValueState>* NextNode = N->pred_empty() 
+                                       ? NULL : *(N->pred_begin());
+  
+  while (NextNode) {
     
     ExplodedNode<ValueState>* LastNode = N;
-    N = *(N->pred_begin());
+    N = NextNode;    
+    NextNode = N->pred_empty() ? NULL : *(N->pred_begin());
     
     ProgramPoint P = N->getLocation();
     
@@ -171,7 +177,7 @@
             case Stmt::DefaultStmtClass: {
               
               os << "Control jumps to the 'default' case at line "
-              << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
+                 << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
               
               break;
             }
@@ -284,7 +290,15 @@
           break;
         }
       }
-    }  
+    }
+    else
+      for (BugReporterHelper** I = BegHelpers; I != EndHelpers; ++I) {
+
+        PathDiagnosticPiece* piece = (*I)->VisitNode(N, NextNode, G, Ctx);
+
+        if (piece)
+          PD.push_front(piece);
+      }
   }
 }
 
@@ -309,7 +323,9 @@
                                   ASTContext& Ctx,
                                   const BugDescription& B,
                                   ExplodedGraph<GRExprEngine>& G,
-                                  ExplodedNode<ValueState>* N) {
+                                  ExplodedNode<ValueState>* N,
+                                  BugReporterHelper** BegHelpers,
+                                  BugReporterHelper** EndHelpers) {
   
   if (!PDC) {
     EmitWarning(Diag, Ctx, B, N);
@@ -320,7 +336,7 @@
     return;
   
   PathDiagnostic D(B.getName());  
-  GeneratePathDiagnostic(D, Ctx, B, G, N);
+  GeneratePathDiagnostic(D, Ctx, B, G, N, BegHelpers, EndHelpers);
   
   if (!D.empty())  
     PDC->HandlePathDiagnostic(D);





More information about the cfe-commits mailing list