From: Ted Kremenek Date: Tue, 7 Apr 2009 00:12:43 +0000 (+0000) Subject: retain/release checker: When hunting for the leak location, don't walk the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=933c42217fca2407e3d6dedb1ee6b1b390797d0a;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68477 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 859e6cad1f..d045ee4674 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -2900,12 +2900,40 @@ CFRefLeakReport::getEndPath(BugReporter& br, const ExplodedNode* EndN){ GetAllocationSite(BR.getStateManager(), EndN, Sym); // Get the allocate site. - assert (AllocNode); + assert(AllocNode); Stmt* FirstStmt = cast(AllocNode->getLocation()).getStmt(); SourceManager& SMgr = BR.getContext().getSourceManager(); unsigned AllocLine =SMgr.getInstantiationLineNumber(FirstStmt->getLocStart()); +#if 1 + const ExplodedNode* LeakN = EndN; + PathDiagnosticLocation L; + + while (LeakN) { + ProgramPoint P = LeakN->getLocation(); + + if (const PostStmt *PS = dyn_cast(&P)) { + L = PathDiagnosticLocation(PS->getStmt()->getLocStart(), SMgr); + break; + } + else if (const BlockEdge *BE = dyn_cast(&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* LeakN = EndN; @@ -2963,6 +2991,7 @@ CFRefLeakReport::getEndPath(BugReporter& br, const ExplodedNode* EndN){ // 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);