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

Ted Kremenek kremenek at apple.com
Thu Apr 17 16:44:38 PDT 2008


Author: kremenek
Date: Thu Apr 17 18:44:37 2008
New Revision: 49880

URL: http://llvm.org/viewvc/llvm-project?rev=49880&view=rev
Log:
Modified BugReport::getEndPath() to handle the case where end path is at
the exit block of the CFG.

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=49880&r1=49879&r2=49880&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Thu Apr 17 18:44:37 2008
@@ -63,7 +63,8 @@
     return getBugType().getDescription();
   }
   
-  virtual PathDiagnosticPiece* getEndPath(ASTContext& Ctx) const;
+  virtual PathDiagnosticPiece* getEndPath(BugReporter& BR,
+                                          ExplodedNode<ValueState>* N) const;
   
   virtual FullSourceLoc getLocation(SourceManager& Mgr);
   
@@ -124,6 +125,8 @@
 
   GRExprEngine& getEngine() { return Eng; }
   
+  CFG& getCFG() { return getGraph().getCFG(); }
+  
   void EmitPathWarning(BugReport& R);
   
   void EmitWarning(BugReport& R);

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

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Thu Apr 17 18:44:37 2008
@@ -55,15 +55,44 @@
 Stmt* BugReport::getStmt() const {
   return N ? GetStmt(N->getLocation()) : NULL;
 }
+
+static inline ExplodedNode<ValueState>*
+GetNextNode(ExplodedNode<ValueState>* N) {
+  return N->pred_empty() ? NULL : *(N->pred_begin());
+}
+  
+  
+static Stmt* GetLastStmt(ExplodedNode<ValueState>* N) {
+  assert (isa<BlockEntrance>(N->getLocation()));
   
-PathDiagnosticPiece* BugReport::getEndPath(ASTContext& Ctx) const {
+  for (N = GetNextNode(N); N; N = GetNextNode(N)) {
+    
+    ProgramPoint P = N->getLocation();
+    
+    if (PostStmt* PS = dyn_cast<PostStmt>(&P))
+      return PS->getStmt();
+  }
   
-  Stmt* S = getStmt();
+  return NULL;
+}
+
+PathDiagnosticPiece*
+BugReport::getEndPath(BugReporter& BR,
+                      ExplodedNode<ValueState>* EndPathNode) const {
+  
+  ProgramPoint ProgP = EndPathNode->getLocation();  
+  Stmt *S = NULL;
+  
+  if (BlockEntrance* BE = dyn_cast<BlockEntrance>(&ProgP))
+    if (BE->getBlock() == &BR.getCFG().getExit())
+      S = GetLastStmt(EndPathNode);
+  if (!S)
+    S = GetStmt(ProgP);      
   
   if (!S)
     return NULL;
   
-  FullSourceLoc L(S->getLocStart(), Ctx.getSourceManager());  
+  FullSourceLoc L(S->getLocStart(), BR.getContext().getSourceManager());  
 
   PathDiagnosticPiece* P =
     new PathDiagnosticPiece(L, getDescription());
@@ -113,26 +142,18 @@
 void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD,
                                          BugReport& R) {
 
-  ExplodedNode<ValueState>* N = R.getEndNode();
-  
+  ExplodedNode<ValueState>* N = R.getEndNode();  
   assert (N && "Path diagnostic requires a ExplodedNode.");
   
-  if (PathDiagnosticPiece* Piece = R.getEndPath(Ctx))
-    PD.push_back(Piece);
-  else
-    return;
-  
-  SourceManager& SMgr = Ctx.getSourceManager();
-  
   llvm::OwningPtr<ExplodedGraph<ValueState> > GTrim(getGraph().Trim(&N, &N+1));
-  
+
   // Find the sink in the trimmed graph.
   // FIXME: Should we eventually have a sink iterator?
   
   ExplodedNode<ValueState>* NewN = 0;
   
   for (ExplodedGraph<ValueState>::node_iterator
-        I = GTrim->nodes_begin(), E = GTrim->nodes_end(); I != E; ++I) {
+       I = GTrim->nodes_begin(), E = GTrim->nodes_end(); I != E; ++I) {
     
     if (I->isSink()) {
       NewN = &*I;
@@ -144,15 +165,22 @@
   assert (NewN->getLocation() == N->getLocation());
   
   N = NewN;
+    
+  if (PathDiagnosticPiece* Piece = R.getEndPath(*this, N))
+    PD.push_back(Piece);
+  else
+    return;
   
   ExplodedNode<ValueState>* NextNode = N->pred_empty() 
                                        ? NULL : *(N->pred_begin());
   
+  SourceManager& SMgr = Ctx.getSourceManager();
+  
   while (NextNode) {
     
     ExplodedNode<ValueState>* LastNode = N;
     N = NextNode;    
-    NextNode = N->pred_empty() ? NULL : *(N->pred_begin());
+    NextNode = GetNextNode(N);
     
     ProgramPoint P = N->getLocation();
     





More information about the cfe-commits mailing list