[cfe-commits] r68477 - /cfe/trunk/lib/Analysis/CFRefCount.cpp

Ted Kremenek kremenek at apple.com
Mon Apr 6 17:12:43 PDT 2009


Author: kremenek
Date: Mon Apr  6 19:12:43 2009
New Revision: 68477

URL: http://llvm.org/viewvc/llvm-project?rev=68477&view=rev
Log:
retain/release checker: When hunting for the leak location, don't walk the
ExplodedGraph backwards. That may inadvertently result in reverse control-flow
edges in the PathDiagostic.

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

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

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Mon Apr  6 19:12:43 2009
@@ -2900,12 +2900,40 @@
     GetAllocationSite(BR.getStateManager(), EndN, Sym);
   
   // Get the allocate site.  
-  assert (AllocNode);
+  assert(AllocNode);
   Stmt* FirstStmt = cast<PostStmt>(AllocNode->getLocation()).getStmt();
 
   SourceManager& SMgr = BR.getContext().getSourceManager();
   unsigned AllocLine =SMgr.getInstantiationLineNumber(FirstStmt->getLocStart());
 
+#if 1
+  const ExplodedNode<GRState>* LeakN = EndN;
+  PathDiagnosticLocation L;
+  
+  while (LeakN) {
+    ProgramPoint P = LeakN->getLocation();
+    
+    if (const PostStmt *PS = dyn_cast<PostStmt>(&P)) {
+      L = PathDiagnosticLocation(PS->getStmt()->getLocStart(), SMgr);
+      break;
+    }
+    else if (const BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
+      if (const Stmt* Term = BE->getSrc()->getTerminator()) {
+        L = PathDiagnosticLocation(Term->getLocStart(), SMgr);
+        break;
+      }
+    }
+
+
+    LeakN = LeakN->succ_empty() ? 0 : *(LeakN->succ_begin());
+  }
+  
+  if (!L.isValid()) {
+    CompoundStmt *CS = BR.getStateManager().getCodeDecl().getBody();
+    L = PathDiagnosticLocation(CS->getRBracLoc(), SMgr);
+  }
+
+#else
   // Get the leak site.  We want to find the last place where the symbol
   // was used in an expression.
   const ExplodedNode<GRState>* LeakN = EndN;
@@ -2963,6 +2991,7 @@
   // FIXME: We need to do a better job at determing the leak site, e.g., at
   // the end of function bodies.
   PathDiagnosticLocation L(S, SMgr);
+#endif
   std::string sbuf;
   llvm::raw_string_ostream os(sbuf);
   





More information about the cfe-commits mailing list