[cfe-commits] r50549 - in /cfe/trunk: include/clang/Analysis/PathSensitive/BugReporter.h lib/Analysis/BasicObjCFoundationChecks.cpp lib/Analysis/BugReporter.cpp lib/Analysis/CFRefCount.cpp

Ted Kremenek kremenek at apple.com
Thu May 1 15:50:37 PDT 2008


Author: kremenek
Date: Thu May  1 17:50:36 2008
New Revision: 50549

URL: http://llvm.org/viewvc/llvm-project?rev=50549&view=rev
Log:
Do not highlight bogus ranges for leaks.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
    cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp
    cfe/trunk/lib/Analysis/BugReporter.cpp
    cfe/trunk/lib/Analysis/CFRefCount.cpp

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h?rev=50549&r1=50548&r2=50549&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Thu May  1 17:50:36 2008
@@ -64,7 +64,7 @@
 class BugReport {
   BugType& Desc;
   ExplodedNode<ValueState> *N;
-  
+  SourceRange R;  
 public:
   BugReport(BugType& D, ExplodedNode<ValueState> *n) : Desc(D), N(n) {}
   virtual ~BugReport();
@@ -74,7 +74,7 @@
   
   ExplodedNode<ValueState>* getEndNode() const { return N; }
   
-  Stmt* getStmt() const;
+  Stmt* getStmt(BugReporter& BR) const;
     
   const char* getName() const { return getBugType().getName(); }
 
@@ -87,12 +87,12 @@
   }
   
   virtual PathDiagnosticPiece* getEndPath(BugReporter& BR,
-                                          ExplodedNode<ValueState>* N) const;
+                                          ExplodedNode<ValueState>* N);
   
   virtual FullSourceLoc getLocation(SourceManager& Mgr);
   
-  virtual void getRanges(const SourceRange*& beg,
-                         const SourceRange*& end) const;
+  virtual void getRanges(BugReporter& BR,const SourceRange*& beg,
+                         const SourceRange*& end);
   
   virtual PathDiagnosticPiece* VisitNode(ExplodedNode<ValueState>* N,
                                          ExplodedNode<ValueState>* PrevN,
@@ -110,8 +110,8 @@
   
   void addRange(SourceRange R) { Ranges.push_back(R); }
   
-  virtual void getRanges(const SourceRange*& beg,           
-                         const SourceRange*& end) const {
+  virtual void getRanges(BugReporter& BR,const SourceRange*& beg,           
+                         const SourceRange*& end) {
     
     if (Ranges.empty()) {
       beg = NULL;

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

==============================================================================
--- cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp Thu May  1 17:50:36 2008
@@ -89,7 +89,8 @@
     
     virtual const char* getDescription() const { return s; }
     
-    virtual void getRanges(const SourceRange*& B, const SourceRange*& E) const {
+    virtual void getRanges(BugReporter& BR,
+                           const SourceRange*& B, const SourceRange*& E) {
       B = &R;
       E = B+1;
     }

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

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Thu May  1 17:50:36 2008
@@ -56,27 +56,11 @@
     return (*B)[0];
 }
 
-Stmt* BugReport::getStmt() const {
-  return N ? GetStmt(N->getLocation()) : NULL;
-}
-
 static inline ExplodedNode<ValueState>*
 GetNextNode(ExplodedNode<ValueState>* N) {
   return N->pred_empty() ? NULL : *(N->pred_begin());
 }
 
-static void ExecutionContinues(std::ostream& os, SourceManager& SMgr,
-                               ExplodedNode<ValueState>* N) {
-  
-  Stmt* S = GetStmt(N->getLocation());
-  
-  if (!S)
-    return;
-
-  os << "Execution continue on line "
-     << SMgr.getLogicalLineNumber(S->getLocStart()) << '.';
-}
-  
 static Stmt* GetLastStmt(ExplodedNode<ValueState>* N) {
   assert (isa<BlockEntrance>(N->getLocation()));
   
@@ -91,18 +75,39 @@
   return NULL;
 }
 
-PathDiagnosticPiece*
-BugReport::getEndPath(BugReporter& BR,
-                      ExplodedNode<ValueState>* EndPathNode) const {
+
+static void ExecutionContinues(std::ostream& os, SourceManager& SMgr,
+                               ExplodedNode<ValueState>* N) {
+  
+  Stmt* S = GetStmt(N->getLocation());
+  
+  if (!S)
+    return;
+
+  os << "Execution continue on line "
+     << SMgr.getLogicalLineNumber(S->getLocStart()) << '.';
+}
   
-  ProgramPoint ProgP = EndPathNode->getLocation();  
+
+Stmt* BugReport::getStmt(BugReporter& BR) const {
+  
+  ProgramPoint ProgP = N->getLocation();  
   Stmt *S = NULL;
   
   if (BlockEntrance* BE = dyn_cast<BlockEntrance>(&ProgP))
     if (BE->getBlock() == &BR.getCFG().getExit())
-      S = GetLastStmt(EndPathNode);
+      S = GetLastStmt(N);
   if (!S)
-    S = GetStmt(ProgP);      
+    S = GetStmt(ProgP);  
+
+  return S;  
+}
+
+PathDiagnosticPiece*
+BugReport::getEndPath(BugReporter& BR,
+                      ExplodedNode<ValueState>* EndPathNode) {
+  
+  Stmt* S = getStmt(BR);
   
   if (!S)
     return NULL;
@@ -113,25 +118,24 @@
     new PathDiagnosticPiece(L, getDescription());
   
   const SourceRange *Beg, *End;
-  getRanges(Beg, End);
-  
-  if (Beg == End) {
-    if (Expr* E = dyn_cast<Expr>(S))
-      P->addRange(E->getSourceRange());
-  }
-  else {
-    assert (Beg < End);
-    for (; Beg != End; ++Beg)
-      P->addRange(*Beg);
-  }
+  getRanges(BR, Beg, End);  
+
+  for (; Beg != End; ++Beg)
+    P->addRange(*Beg);
   
   return P;
 }
 
-void BugReport::getRanges(const SourceRange*& beg,
-                          const SourceRange*& end) const {  
-  beg = NULL;
-  end = NULL;
+void BugReport::getRanges(BugReporter& BR, const SourceRange*& beg,
+                          const SourceRange*& end) {  
+  
+  if (Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) {
+    R = E->getSourceRange();
+    beg = &R;
+    end = beg+1;
+  }
+  else
+    beg = end = 0;
 }
 
 FullSourceLoc BugReport::getLocation(SourceManager& Mgr) {
@@ -479,7 +483,7 @@
     End = D->back()->ranges_end();
   }
   else  
-    R.getRanges(Beg, End);
+    R.getRanges(*this, Beg, End);
 
   if (PD) {
     PathDiagnosticPiece* piece = new PathDiagnosticPiece(L, R.getDescription());

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

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Thu May  1 17:50:36 2008
@@ -1444,7 +1444,9 @@
   public:
     CFRefBug(CFRefCount& tf) : TF(tf) {}
     
-    CFRefCount& getTF() { return TF; }   
+    CFRefCount& getTF() { return TF; }
+    
+    virtual bool ReportRanges() const { return true; }
   };
   
   class VISIBILITY_HIDDEN UseAfterRelease : public CFRefBug {
@@ -1491,7 +1493,8 @@
     }
     
     virtual void EmitWarnings(BugReporter& BR);
-    virtual void GetErrorNodes(std::vector<ExplodedNode<ValueState>*>& Nodes);    
+    virtual void GetErrorNodes(std::vector<ExplodedNode<ValueState>*>& Nodes);
+    virtual bool ReportRanges() const { return false; }
   };
   
   //===---------===//
@@ -1506,6 +1509,24 @@
         
     virtual ~CFRefReport() {}
     
+    CFRefBug& getBugType() {
+      return (CFRefBug&) RangedBugReport::getBugType();
+    }
+    const CFRefBug& getBugType() const {
+      return (const CFRefBug&) RangedBugReport::getBugType();
+    }
+    
+    virtual void getRanges(BugReporter& BR, const SourceRange*& beg,           
+                           const SourceRange*& end) {
+      
+      if (getBugType().ReportRanges())
+        RangedBugReport::getRanges(BR, beg, end);
+      else {
+        beg = 0;
+        end = 0;
+      }
+    }
+    
     virtual std::pair<const char**,const char**> getExtraDescriptiveText();
     
     virtual PathDiagnosticPiece* VisitNode(ExplodedNode<ValueState>* N,





More information about the cfe-commits mailing list