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

Ted Kremenek kremenek at apple.com
Sat Feb 7 14:38:01 PST 2009


Author: kremenek
Date: Sat Feb  7 16:38:00 2009
New Revision: 64041

URL: http://llvm.org/viewvc/llvm-project?rev=64041&view=rev
Log:
For retain/release leaks, have the BugReport description indicate the allocation site and initial bindings.

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=64041&r1=64040&r2=64041&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Sat Feb  7 16:38:00 2009
@@ -2068,8 +2068,7 @@
       : 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 @@
     const MemRegion* AllocBinding;
   public:
     CFRefLeakReport(CFRefBug& D, ExplodedNode<GRState> *n, SymbolRef sym,
-                    GRStateManager& StateMgr);
+                    GRExprEngine& Eng);
 
     PathDiagnosticPiece* getEndPath(BugReporter& BR,
                                     const ExplodedNode<GRState>* N);
@@ -2519,7 +2518,7 @@
 
 
 CFRefLeakReport::CFRefLeakReport(CFRefBug& D, ExplodedNode<GRState> *n,
-                                 SymbolRef sym, GRStateManager& StateMgr)
+                                 SymbolRef sym, GRExprEngine& Eng)
   : CFRefReport(D, n, sym)
 {
   
@@ -2534,13 +2533,19 @@
   const ExplodedNode<GRState>* 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<PostStmt>(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 @@
     CFRefBug *BT = static_cast<CFRefBug*>(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 @@
     CFRefBug *BT = static_cast<CFRefBug*>(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);
   }
 }





More information about the cfe-commits mailing list