From d305721d5804edc9942c752d085831ab3556a3ee Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sat, 7 Feb 2009 22:38:00 +0000 Subject: [PATCH] For retain/release leaks, have the BugReport description indicate the allocation site and initial bindings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64041 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/CFRefCount.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index bfacae846d..8b3f37f1e5 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -2068,8 +2068,7 @@ namespace { : CFRefBug(tf, name), isReturn(isRet) {} public: - // FIXME: Remove once reports have better descriptions. - const char* getDescription() const { return "leak"; } + const char* getDescription() const { return ""; } bool isLeak() const { return true; } }; @@ -2133,7 +2132,7 @@ namespace { const MemRegion* AllocBinding; public: CFRefLeakReport(CFRefBug& D, ExplodedNode *n, SymbolRef sym, - GRStateManager& StateMgr); + GRExprEngine& Eng); PathDiagnosticPiece* getEndPath(BugReporter& BR, const ExplodedNode* N); @@ -2519,7 +2518,7 @@ CFRefLeakReport::getEndPath(BugReporter& br, const ExplodedNode* EndN){ CFRefLeakReport::CFRefLeakReport(CFRefBug& D, ExplodedNode *n, - SymbolRef sym, GRStateManager& StateMgr) + SymbolRef sym, GRExprEngine& Eng) : CFRefReport(D, n, sym) { @@ -2534,13 +2533,19 @@ CFRefLeakReport::CFRefLeakReport(CFRefBug& D, ExplodedNode *n, const ExplodedNode* AllocNode = 0; llvm::tie(AllocNode, AllocBinding) = // Set AllocBinding. - GetAllocationSite(StateMgr, getEndNode(), getSymbol()); + GetAllocationSite(Eng.getStateManager(), getEndNode(), getSymbol()); - ProgramPoint P = - GetAllocationSite(StateMgr, getEndNode(), getSymbol()).first->getLocation(); - // Get the SourceLocation for the allocation site. + ProgramPoint P = AllocNode->getLocation(); AllocSite = cast(P).getStmt()->getLocStart(); + + // Fill in the description of the bug. + Description.clear(); + llvm::raw_string_ostream os(Description); + SourceManager& SMgr = Eng.getContext().getSourceManager(); + unsigned AllocLine = SMgr.getInstantiationLineNumber(AllocSite); + os << "Potential leak of object allocated on line " << AllocLine + << " and store into '" << AllocBinding->getString() << '\''; } //===----------------------------------------------------------------------===// @@ -2581,8 +2586,7 @@ void CFRefCount::EvalEndPath(GRExprEngine& Eng, CFRefBug *BT = static_cast(I->second ? leakAtReturn : leakWithinFunction); assert(BT && "BugType not initialized."); - CFRefLeakReport* report = new CFRefLeakReport(*BT, N, I->first, - Eng.getStateManager()); + CFRefLeakReport* report = new CFRefLeakReport(*BT, N, I->first, Eng); BR->EmitReport(report); } } @@ -2631,8 +2635,7 @@ void CFRefCount::EvalDeadSymbols(ExplodedNodeSet& Dst, CFRefBug *BT = static_cast(I->second ? leakAtReturn : leakWithinFunction); assert(BT && "BugType not initialized."); - CFRefLeakReport* report = new CFRefLeakReport(*BT, N, I->first, - Eng.getStateManager()); + CFRefLeakReport* report = new CFRefLeakReport(*BT, N, I->first, Eng); BR->EmitReport(report); } } -- 2.40.0