]> granicus.if.org Git - clang/commitdiff
[analyzer] Remove the dependency on CheckerContext::getStmt() as well as the method...
authorAnna Zaks <ganna@apple.com>
Thu, 6 Oct 2011 00:43:15 +0000 (00:43 +0000)
committerAnna Zaks <ganna@apple.com>
Thu, 6 Oct 2011 00:43:15 +0000 (00:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141262 91177308-0d34-0410-b5e6-96231b3b80d8

12 files changed:
include/clang/StaticAnalyzer/Core/Checker.h
include/clang/StaticAnalyzer/Core/CheckerManager.h
include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
lib/StaticAnalyzer/Checkers/MallocChecker.cpp
lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp
lib/StaticAnalyzer/Core/CheckerManager.cpp

index 82fbd46222177424f1d5cbfeea287ee80f8b7ed1..1e4edeb0c7ae4c5d6de8a57f4e51a7b7b3d2c344 100644 (file)
@@ -152,9 +152,10 @@ public:
 
 class Location {
   template <typename CHECKER>
-  static void _checkLocation(void *checker, const SVal &location, bool isLoad,
+  static void _checkLocation(void *checker,
+                             const SVal &location, bool isLoad, const Stmt *S,
                              CheckerContext &C) {
-    ((const CHECKER *)checker)->checkLocation(location, isLoad, C);
+    ((const CHECKER *)checker)->checkLocation(location, isLoad, S, C);
   }
 
 public:
@@ -167,9 +168,10 @@ public:
 
 class Bind {
   template <typename CHECKER>
-  static void _checkBind(void *checker, const SVal &location, const SVal &val,
+  static void _checkBind(void *checker,
+                         const SVal &location, const SVal &val, const Stmt *S,
                          CheckerContext &C) {
-    ((const CHECKER *)checker)->checkBind(location, val, C);
+    ((const CHECKER *)checker)->checkBind(location, val, S, C);
   }
 
 public:
index 89b6e69e5a3eb732fe2480751875cc1b210e7ac7..e3e4c49f71e11c3c97c087f86719e3288337292f 100644 (file)
@@ -320,11 +320,13 @@ public:
   typedef CheckerFn<void (const ObjCMessage &, CheckerContext &)>
       CheckObjCMessageFunc;
   
-  typedef CheckerFn<void (const SVal &location, bool isLoad, CheckerContext &)>
+  typedef CheckerFn<void (const SVal &location, bool isLoad, const Stmt *S,
+                          CheckerContext &)>
       CheckLocationFunc;
   
-  typedef CheckerFn<void (const SVal &location, const SVal &val,
-                          CheckerContext &)> CheckBindFunc;
+  typedef CheckerFn<void (const SVal &location, const SVal &val, 
+                          const Stmt *S, CheckerContext &)> 
+      CheckBindFunc;
   
   typedef CheckerFn<void (ExplodedGraph &, BugReporter &, ExprEngine &)>
       CheckEndAnalysisFunc;
index 19daaa537f332fc772a5368217c0042149240c0c..03ab588a51f9652fedbd6e5e6d2eed480e4ab693 100644 (file)
@@ -80,7 +80,6 @@ public:
   ExplodedNodeSet &getNodeSet() { return Dst; }
   ExplodedNode *&getPredecessor() { return Pred; }
   const ProgramState *getState() { return ST ? ST : Pred->getState(); }
-  const Stmt *getStmt() const { return statement; }
 
   /// \brief Returns the number of times the current block has been visited
   /// along the analyzed path.
index b008f97d99e500448b549ab694fba9bf5c42f3d1..6935c5f1c19239e85927c5f66cd2e60d02295936 100644 (file)
@@ -27,11 +27,12 @@ class ArrayBoundChecker :
     public Checker<check::Location> {
   mutable llvm::OwningPtr<BuiltinBug> BT;
 public:
-  void checkLocation(SVal l, bool isLoad, CheckerContext &C) const;
+  void checkLocation(SVal l, bool isLoad, const Stmt* S,
+                     CheckerContext &C) const;
 };
 }
 
-void ArrayBoundChecker::checkLocation(SVal l, bool isLoad,
+void ArrayBoundChecker::checkLocation(SVal l, bool isLoad, const Stmt* LoadS,
                                       CheckerContext &C) const {
   // Check for out of bound array element access.
   const MemRegion *R = l.getAsRegion();
@@ -76,7 +77,7 @@ void ArrayBoundChecker::checkLocation(SVal l, bool isLoad,
     BugReport *report = 
       new BugReport(*BT, BT->getDescription(), N);
 
-    report->addRange(C.getStmt()->getSourceRange());
+    report->addRange(LoadS->getSourceRange());
     C.EmitReport(report);
     return;
   }
index 2a846aa5b161268c1a989ca8f39e3d1ae42bb3f4..6175028a9b20016b07f369f5bf49ff9ecd36c7c9 100644 (file)
@@ -34,7 +34,8 @@ class ArrayBoundCheckerV2 :
                  OOB_Kind kind) const;
       
 public:
-  void checkLocation(SVal l, bool isLoad, CheckerContext &C) const;
+  void checkLocation(SVal l, bool isLoad, const Stmt*S,
+                     CheckerContext &C) const;
 };
 
 // FIXME: Eventually replace RegionRawOffset with this class.
@@ -79,6 +80,7 @@ static SVal computeExtentBegin(SValBuilder &svalBuilder,
 }
 
 void ArrayBoundCheckerV2::checkLocation(SVal location, bool isLoad,
+                                        const Stmt* LoadS,
                                         CheckerContext &checkerContext) const {
 
   // NOTE: Instead of using ProgramState::assumeInBound(), we are prototyping
index c416dd8e8edf8bded12fff609246a31ecea98c21..eeda734a07667089a00a38f20c3f883aeefddec4 100644 (file)
@@ -29,7 +29,8 @@ class DereferenceChecker
   mutable llvm::OwningPtr<BuiltinBug> BT_undef;
 
 public:
-  void checkLocation(SVal location, bool isLoad, CheckerContext &C) const;
+  void checkLocation(SVal location, bool isLoad, const Stmt* S,
+                     CheckerContext &C) const;
 
   static void AddDerefSource(raw_ostream &os,
                              SmallVectorImpl<SourceRange> &Ranges,
@@ -38,7 +39,7 @@ public:
 } // end anonymous namespace
 
 void DereferenceChecker::AddDerefSource(raw_ostream &os,
-                                     SmallVectorImpl<SourceRange> &Ranges,
+                                        SmallVectorImpl<SourceRange> &Ranges,
                                         const Expr *Ex,
                                         bool loadedFrom) {
   Ex = Ex->IgnoreParenLValueCasts();
@@ -65,7 +66,7 @@ void DereferenceChecker::AddDerefSource(raw_ostream &os,
   }
 }
 
-void DereferenceChecker::checkLocation(SVal l, bool isLoad,
+void DereferenceChecker::checkLocation(SVal l, bool isLoad, const Stmt* S,
                                        CheckerContext &C) const {
   // Check for dereference of an undefined value.
   if (l.isUndef()) {
@@ -88,7 +89,6 @@ void DereferenceChecker::checkLocation(SVal l, bool isLoad,
   if (!isa<Loc>(location))
     return;
 
-  const Stmt *S = C.getStmt();
   const ProgramState *state = C.getState();
   const ProgramState *notNullState, *nullState;
   llvm::tie(notNullState, nullState) = state->assume(location);
index b25ae6cf6fb83dcbd0da253bcc676106d642f543..15dff3e505cd1265b83e8f83a9622de59ffcb0a6 100644 (file)
@@ -82,8 +82,10 @@ public:
   void checkPreStmt(const ReturnStmt *S, CheckerContext &C) const;
   const ProgramState *evalAssume(const ProgramState *state, SVal Cond,
                             bool Assumption) const;
-  void checkLocation(SVal l, bool isLoad, CheckerContext &C) const;
-  void checkBind(SVal location, SVal val, CheckerContext &C) const;
+  void checkLocation(SVal l, bool isLoad, const Stmt *S,
+                     CheckerContext &C) const;
+  void checkBind(SVal location, SVal val, const Stmt*S,
+                 CheckerContext &C) const;
 
 private:
   static void MallocMem(CheckerContext &C, const CallExpr *CE);
@@ -661,7 +663,8 @@ const ProgramState *MallocChecker::evalAssume(const ProgramState *state, SVal Co
 }
 
 // Check if the location is a freed symbolic region.
-void MallocChecker::checkLocation(SVal l, bool isLoad,CheckerContext &C) const {
+void MallocChecker::checkLocation(SVal l, bool isLoad, const Stmt *S,
+                                  CheckerContext &C) const {
   SymbolRef Sym = l.getLocSymbolInBase();
   if (Sym) {
     const RefState *RS = C.getState()->get<RegionState>(Sym);
@@ -679,7 +682,8 @@ void MallocChecker::checkLocation(SVal l, bool isLoad,CheckerContext &C) const {
   }
 }
 
-void MallocChecker::checkBind(SVal location, SVal val,CheckerContext &C) const {
+void MallocChecker::checkBind(SVal location, SVal val,
+                              const Stmt *BindS, CheckerContext &C) const {
   // The PreVisitBind implements the same algorithm as already used by the 
   // Objective C ownership checker: if the pointer escaped from this scope by 
   // assignment, let it go.  However, assigning to fields of a stack-storage 
@@ -728,7 +732,7 @@ void MallocChecker::checkBind(SVal location, SVal val,CheckerContext &C) const {
           // We no longer own this pointer.
           notNullState =
             notNullState->set<RegionState>(Sym,
-                                        RefState::getRelinquished(C.getStmt()));
+                                        RefState::getRelinquished(BindS));
         }
         while (false);
       }
index 3e4a49415cebd656406d3e11ac804d3ef577078c..56789983593e936f3c5099912768de95b37aa908 100644 (file)
@@ -157,7 +157,8 @@ public:
   NSOrCFErrorDerefChecker() : NSErrorII(0), CFErrorII(0),
                               ShouldCheckNSError(0), ShouldCheckCFError(0) { }
 
-  void checkLocation(SVal loc, bool isLoad, CheckerContext &C) const;
+  void checkLocation(SVal loc, bool isLoad, const Stmt *S,
+                     CheckerContext &C) const;
   void checkEvent(ImplicitNullDerefEvent event) const;
 };
 }
@@ -211,6 +212,7 @@ static QualType parameterTypeFromSVal(SVal val, CheckerContext &C) {
 }
 
 void NSOrCFErrorDerefChecker::checkLocation(SVal loc, bool isLoad,
+                                            const Stmt *S,
                                             CheckerContext &C) const {
   if (!isLoad)
     return;
index 8b3e0f76423d341a2240bf4ffcb20eac0c473d74..2fb9944afaa716fd455c7730aeab5e2cbd44f08f 100644 (file)
@@ -77,7 +77,8 @@ public:
   void checkPreStmt(const ReturnStmt *S, CheckerContext &C) const;
   void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
   void checkPostStmt(const CallExpr *CE, CheckerContext &C) const;
-  void checkLocation(SVal location, bool isLoad, CheckerContext &C) const;
+  void checkLocation(SVal location, bool isLoad, const Stmt *S,
+                     CheckerContext &C) const;
 };
 } // end anonymous namespace
 
@@ -295,6 +296,7 @@ void ObjCSelfInitChecker::checkPostStmt(const CallExpr *CE,
 }
 
 void ObjCSelfInitChecker::checkLocation(SVal location, bool isLoad,
+                                        const Stmt *S,
                                         CheckerContext &C) const {
   // Tag the result of a load from 'self' so that we can easily know that the
   // value is the object that 'self' points to.
index b9afe0403dd7dc4e45da21dc41d3c081d42baf1e..9b2331713ad58c2886d4154c8bde056b82c630a5 100644 (file)
@@ -2409,7 +2409,7 @@ public:
   void printState(raw_ostream &Out, const ProgramState *State,
                   const char *NL, const char *Sep) const;
 
-  void checkBind(SVal loc, SVal val, CheckerContext &C) const;
+  void checkBind(SVal loc, SVal val, const Stmt *S, CheckerContext &C) const;
   void checkPostStmt(const BlockExpr *BE, CheckerContext &C) const;
   void checkPostStmt(const CastExpr *CE, CheckerContext &C) const;
 
@@ -3225,7 +3225,7 @@ void RetainCountChecker::checkReturnWithRetEffect(const ReturnStmt *S,
 // Check various ways a symbol can be invalidated.
 //===----------------------------------------------------------------------===//
 
-void RetainCountChecker::checkBind(SVal loc, SVal val,
+void RetainCountChecker::checkBind(SVal loc, SVal val, const Stmt *S,
                                    CheckerContext &C) const {
   // Are we storing to something that causes the value to "escape"?
   bool escapes = true;
index b0c4bee424f300310bcb0a5191191451e56ea6bd..5ca4a9fe46d2f110baf180a585b31bee0db1e89b 100644 (file)
@@ -27,11 +27,13 @@ class UndefinedAssignmentChecker
   mutable llvm::OwningPtr<BugType> BT;
 
 public:
-  void checkBind(SVal location, SVal val, CheckerContext &C) const;
+  void checkBind(SVal location, SVal val, const Stmt *S,
+                 CheckerContext &C) const;
 };
 }
 
 void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
+                                           const Stmt *StoreE,
                                            CheckerContext &C) const {
   if (!val.isUndef())
     return;
@@ -49,7 +51,6 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
   // Generate a report for this bug.
   const Expr *ex = 0;
 
-  const Stmt *StoreE = C.getStmt();
   while (StoreE) {
     if (const BinaryOperator *B = dyn_cast<BinaryOperator>(StoreE)) {
       if (B->isCompoundAssignmentOp()) {
index 6391cb3721cb528b107431beb9d1e11b547a4697..ac4358d6fe8a6f969d9c25e6c363d0eb3b6bb700 100644 (file)
@@ -219,7 +219,7 @@ namespace {
       CheckerContext C(Dst, Eng.getBuilder(), Eng, Pred, checkFn.Checker,
                        IsLoad ? ProgramPoint::PreLoadKind :
                        ProgramPoint::PreStoreKind, 0, S);
-      checkFn(Loc, IsLoad, C);
+      checkFn(Loc, IsLoad, S, C);
     }
   };
 }
@@ -253,7 +253,7 @@ namespace {
                     ExplodedNodeSet &Dst, ExplodedNode *Pred) {
       CheckerContext C(Dst, Eng.getBuilder(), Eng, Pred, checkFn.Checker,
                        ProgramPoint::PreStmtKind, 0, S);
-      checkFn(Loc, Val, C);
+      checkFn(Loc, Val, S, C);
     }
   };
 }