[cfe-commits] r71027 - /cfe/trunk/lib/Analysis/BugReporter.cpp

Ted Kremenek kremenek at apple.com
Tue May 5 15:19:18 PDT 2009


Author: kremenek
Date: Tue May  5 17:19:17 2009
New Revision: 71027

URL: http://llvm.org/viewvc/llvm-project?rev=71027&view=rev
Log:
BugReporter (extensive diagnostics): Fix getEnclosingStmtLocation to reason
about Exprs that are not consumed and fix where the loop iteration diagnostic
goes.

Modified:
    cfe/trunk/lib/Analysis/BugReporter.cpp

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

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Tue May  5 17:19:17 2009
@@ -215,9 +215,9 @@
 PathDiagnosticLocation
 PathDiagnosticBuilder::getEnclosingStmtLocation(const Stmt *S) {
   assert(S && "Null Stmt* passed to getEnclosingStmtLocation");
-  ParentMap &P = getParentMap();
+  ParentMap &P = getParentMap(); 
     
-  while (isa<DeclStmt>(S) || isa<Expr>(S)) {
+  while (isa<Expr>(S) && P.isConsumedExpr(cast<Expr>(S))) {
     const Stmt *Parent = P.getParent(S);
     
     if (!Parent)
@@ -797,8 +797,6 @@
             S = CE->getCond();
           else if (const BinaryOperator *BE = dyn_cast<BinaryOperator>(S))
             S = BE->getLHS();
-          else if (const DoStmt *DS = dyn_cast<DoStmt>(S))
-            S = DS->getCond();
           else
             break;
         }
@@ -1038,11 +1036,11 @@
       const CFGBlock &Blk = *BE->getSrc();
       const Stmt *Term = Blk.getTerminator();
       
-      if (Term && !isa<DoStmt>(Term))
+      if (Term)
         EB.addContext(Term);
 
       // Are we jumping to the head of a loop?  Add a special diagnostic.
-      if (const Stmt *Loop = BE->getDst()->getLoopTarget()) {
+      if (const Stmt *Loop = BE->getSrc()->getLoopTarget()) {
         
         PathDiagnosticLocation L(Loop, PDB.getSourceManager());
         PathDiagnosticEventPiece *p =
@@ -1086,8 +1084,11 @@
                                 PDB.getBugReporter(), PDB.getNodeMapClosure());
     
     if (p) {
-      EB.addEdge(p->getLocation(), true);
+      const PathDiagnosticLocation &Loc = p->getLocation();
+      EB.addEdge(Loc, true);
       PD.push_front(p);
+      if (const Stmt *S = Loc.asStmt())
+        EB.addContext(PDB.getEnclosingStmtLocation(S).asStmt());      
     }
   }
 }





More information about the cfe-commits mailing list