[cfe-commits] r76809 - in /cfe/trunk: include/clang/Analysis/PathSensitive/BugReporter.h include/clang/Analysis/PathSensitive/GRCoreEngine.h include/clang/Analysis/PathSensitive/GRState.h include/clang/Analysis/ProgramPoint.h lib/Analysis/BasicObjCFoundationChecks.cpp lib/Analysis/BugReporter.cpp lib/Analysis/BugReporterVisitors.cpp lib/Analysis/CFRefCount.cpp lib/Analysis/GRCoreEngine.cpp lib/Analysis/GRExprEngine.cpp lib/Analysis/GRExprEngineInternalChecks.cpp lib/Analysis/GRState.cpp

Ted Kremenek kremenek at apple.com
Wed Jul 22 15:35:28 PDT 2009


Author: kremenek
Date: Wed Jul 22 17:35:28 2009
New Revision: 76809

URL: http://llvm.org/viewvc/llvm-project?rev=76809&view=rev
Log:
Refactor 'PostStmt' and 'PreStmt' to subclass a common parent 'StmtPoint'.

Educate GRExprEngine::VisitGraph() about 'PreStmt'.

Mark the constructor of 'PostStmt' to be explicit, preventing implicit
conversions and the selection of the wrong 'generateNode' method in
GRStmtNodeBuilder.

Constify a bunch of arguments, which falls out of the changes to ProgramPoint.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
    cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h
    cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
    cfe/trunk/include/clang/Analysis/ProgramPoint.h
    cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp
    cfe/trunk/lib/Analysis/BugReporter.cpp
    cfe/trunk/lib/Analysis/BugReporterVisitors.cpp
    cfe/trunk/lib/Analysis/CFRefCount.cpp
    cfe/trunk/lib/Analysis/GRCoreEngine.cpp
    cfe/trunk/lib/Analysis/GRExprEngine.cpp
    cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp
    cfe/trunk/lib/Analysis/GRState.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=76809&r1=76808&r2=76809&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Wed Jul 22 17:35:28 2009
@@ -101,7 +101,7 @@
   // object.
   // FIXME: If we do need it, we can probably just make it private to
   // BugReporter.
-  Stmt* getStmt(BugReporter& BR) const;
+  const Stmt* getStmt(BugReporter& BR) const;
   
   const std::string& getDescription() const { return Description; }
 

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h Wed Jul 22 17:35:28 2009
@@ -146,12 +146,12 @@
                    ExplodedNodeImpl* Pred);
   
   ExplodedNodeImpl*
-  generateNodeImpl(Stmt* S, const void* State, ExplodedNodeImpl* Pred,
+  generateNodeImpl(const Stmt* S, const void* State, ExplodedNodeImpl* Pred,
                    ProgramPoint::Kind K = ProgramPoint::PostStmtKind,
                    const void *tag = 0);
 
   ExplodedNodeImpl*
-  generateNodeImpl(Stmt* S, const void* State,
+  generateNodeImpl(const Stmt* S, const void* State,
                    ProgramPoint::Kind K = ProgramPoint::PostStmtKind,
                    const void *tag = 0) {
     ExplodedNodeImpl* N = getLastNode();
@@ -160,7 +160,7 @@
   }
   
   ExplodedNodeImpl*
-  generateNodeImpl(Stmt* S, const void* State, const void *tag = 0) {
+  generateNodeImpl(const Stmt* S, const void* State, const void *tag = 0) {
     ExplodedNodeImpl* N = getLastNode();
     assert (N && "Predecessor of new node is infeasible.");
     return generateNodeImpl(S, State, N, ProgramPoint::PostStmtKind, tag);
@@ -211,24 +211,24 @@
     return static_cast<NodeTy*>(NB.generateNodeImpl(PP, St, Pred));
   }
   
-  NodeTy* generateNode(Stmt* S, const StateTy* St, NodeTy* Pred,
+  NodeTy* generateNode(const Stmt* S, const StateTy* St, NodeTy* Pred,
                        ProgramPoint::Kind K) {
     HasGeneratedNode = true;
     if (PurgingDeadSymbols) K = ProgramPoint::PostPurgeDeadSymbolsKind;      
     return static_cast<NodeTy*>(NB.generateNodeImpl(S, St, Pred, K, Tag));
   }
   
-  NodeTy* generateNode(Stmt* S, const StateTy* St, NodeTy* Pred) {
+  NodeTy* generateNode(const Stmt* S, const StateTy* St, NodeTy* Pred) {
     return generateNode(S, St, Pred, PointKind);
   }
   
-  NodeTy* generateNode(Stmt* S, const StateTy* St, ProgramPoint::Kind K) {
+  NodeTy* generateNode(const Stmt* S, const StateTy* St, ProgramPoint::Kind K) {
     HasGeneratedNode = true;
     if (PurgingDeadSymbols) K = ProgramPoint::PostPurgeDeadSymbolsKind;      
     return static_cast<NodeTy*>(NB.generateNodeImpl(S, St, K, Tag));
   }
   
-  NodeTy* generateNode(Stmt* S, const StateTy* St) {
+  NodeTy* generateNode(const Stmt* S, const StateTy* St) {
     return generateNode(S, St, PointKind);
   }
 

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h Wed Jul 22 17:35:28 2009
@@ -525,8 +525,8 @@
 
   const GRState* getPersistentState(GRState& Impl);
 
-  bool isEqual(const GRState* state, Expr* Ex, const llvm::APSInt& V);
-  bool isEqual(const GRState* state, Expr* Ex, uint64_t);
+  bool isEqual(const GRState* state, const Expr* Ex, const llvm::APSInt& V);
+  bool isEqual(const GRState* state, const Expr* Ex, uint64_t);
   
   //==---------------------------------------------------------------------==//
   // Generic Data Map methods.

Modified: cfe/trunk/include/clang/Analysis/ProgramPoint.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ProgramPoint.h?rev=76809&r1=76808&r2=76809&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/ProgramPoint.h (original)
+++ cfe/trunk/include/clang/Analysis/ProgramPoint.h Wed Jul 22 17:35:28 2009
@@ -130,40 +130,47 @@
     return Location->getKind() == BlockExitKind;
   }
 };
+  
+class StmtPoint : public ProgramPoint {
+public:
+  StmtPoint(const Stmt *S, const void *p2, Kind k, const void *tag)
+  : ProgramPoint(S, p2, k, tag) {}
+  
+  const Stmt *getStmt() const { return (const Stmt*) getData1(); }
+  
+  template <typename T>
+  const T* getStmtAs() const { return llvm::dyn_cast<T>(getStmt()); }
+  
+  static bool classof(const ProgramPoint* Location) {
+    unsigned k = Location->getKind();
+    return k >= PreStmtKind && k <= MaxPostStmtKind;
+  }
+};  
 
-class PreStmt : public ProgramPoint {
+  
+class PreStmt : public StmtPoint {
 public:
   PreStmt(const Stmt *S, const void *tag, const Stmt *SubStmt = 0)
-    : ProgramPoint(S, SubStmt, PreStmtKind, tag) {}
+    : StmtPoint(S, SubStmt, PreStmtKind, tag) {}
 
-  const Stmt *getStmt() const { return (const Stmt*) getData1(); }
   const Stmt *getSubStmt() const { return (const Stmt*) getData2(); }  
 
-  template <typename T>
-  const T* getStmtAs() const { return llvm::dyn_cast<T>(getStmt()); }
-    
   static bool classof(const ProgramPoint* Location) {
     return Location->getKind() == PreStmtKind;
   }
 };
 
-class PostStmt : public ProgramPoint {
+class PostStmt : public StmtPoint {
 protected:
   PostStmt(const Stmt* S, Kind k, const void *tag = 0)
-    : ProgramPoint(S, k, tag) {}
+    : StmtPoint(S, NULL, k, tag) {}
 
   PostStmt(const Stmt* S, const void* data, Kind k, const void *tag =0)
-    : ProgramPoint(S, data, k, tag) {}
+    : StmtPoint(S, data, k, tag) {}
   
 public:
-  PostStmt(const Stmt* S, const void *tag = 0)
-    : ProgramPoint(S, PostStmtKind, tag) {}
-
-      
-  Stmt* getStmt() const { return (Stmt*) getData1(); }
-  
-  template <typename T>
-  T* getStmtAs() const { return llvm::dyn_cast<T>(getStmt()); }
+  explicit PostStmt(const Stmt* S, const void *tag = 0)
+    : StmtPoint(S, NULL, PostStmtKind, tag) {}
 
   static bool classof(const ProgramPoint* Location) {
     unsigned k = Location->getKind();

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

==============================================================================
--- cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp Wed Jul 22 17:35:28 2009
@@ -63,10 +63,10 @@
   ASTContext &Ctx;
       
   bool isNSString(const ObjCInterfaceType *T, const char* suffix);
-  bool AuditNSString(NodeTy* N, ObjCMessageExpr* ME);
+  bool AuditNSString(NodeTy* N, const ObjCMessageExpr* ME);
       
-  void Warn(NodeTy* N, Expr* E, const std::string& s);  
-  void WarnNilArg(NodeTy* N, Expr* E);
+  void Warn(NodeTy* N, const Expr* E, const std::string& s);  
+  void WarnNilArg(NodeTy* N, const Expr* E);
   
   bool CheckNilArg(NodeTy* N, unsigned Arg);
 
@@ -77,7 +77,7 @@
   bool Audit(ExplodedNode<GRState>* N, GRStateManager&);
   
 private:  
-  void WarnNilArg(NodeTy* N, ObjCMessageExpr* ME, unsigned Arg) {    
+  void WarnNilArg(NodeTy* N, const ObjCMessageExpr* ME, unsigned Arg) {    
     std::string sbuf;
     llvm::raw_string_ostream os(sbuf);
     os << "Argument to '" << GetReceiverNameType(ME) << "' method '"
@@ -106,7 +106,7 @@
 bool BasicObjCFoundationChecks::Audit(ExplodedNode<GRState>* N,
                                       GRStateManager&) {
   
-  ObjCMessageExpr* ME =
+  const ObjCMessageExpr* ME =
     cast<ObjCMessageExpr>(cast<PostStmt>(N->getLocation()).getStmt());
 
   const ObjCInterfaceType *ReceiverType = GetReceiverType(ME);
@@ -140,10 +140,10 @@
 //===----------------------------------------------------------------------===//
 
 bool BasicObjCFoundationChecks::CheckNilArg(NodeTy* N, unsigned Arg) {
-  ObjCMessageExpr* ME =
+  const ObjCMessageExpr* ME =
     cast<ObjCMessageExpr>(cast<PostStmt>(N->getLocation()).getStmt());
   
-  Expr * E = ME->getArg(Arg);
+  const Expr * E = ME->getArg(Arg);
   
   if (isNil(N->getState()->getSVal(E))) {
     WarnNilArg(N, ME, Arg);
@@ -163,7 +163,7 @@
 }
 
 bool BasicObjCFoundationChecks::AuditNSString(NodeTy* N, 
-                                              ObjCMessageExpr* ME) {
+                                              const ObjCMessageExpr* ME) {
   
   Selector S = ME->getSelector();
   
@@ -257,7 +257,7 @@
   bool Audit(ExplodedNode<GRState>* N, GRStateManager&);
   
 private:
-  void AddError(const TypedRegion* R, Expr* Ex, ExplodedNode<GRState> *N,
+  void AddError(const TypedRegion* R, const Expr* Ex, ExplodedNode<GRState> *N,
                 uint64_t SourceSize, uint64_t TargetSize, uint64_t NumberKind);  
 };
 } // end anonymous namespace
@@ -356,8 +356,9 @@
 #endif
 
 bool AuditCFNumberCreate::Audit(ExplodedNode<GRState>* N,GRStateManager&){  
-  CallExpr* CE = cast<CallExpr>(cast<PostStmt>(N->getLocation()).getStmt());
-  Expr* Callee = CE->getCallee();  
+  const CallExpr* CE =
+    cast<CallExpr>(cast<PostStmt>(N->getLocation()).getStmt());
+  const Expr* Callee = CE->getCallee();  
   SVal CallV = N->getState()->getSVal(Callee);  
   const FunctionDecl* FD = CallV.getAsFunctionDecl();
 
@@ -423,7 +424,7 @@
   return SourceSize < TargetSize;
 }
 
-void AuditCFNumberCreate::AddError(const TypedRegion* R, Expr* Ex,
+void AuditCFNumberCreate::AddError(const TypedRegion* R, const Expr* Ex,
                                    ExplodedNode<GRState> *N,
                                    uint64_t SourceSize, uint64_t TargetSize,
                                    uint64_t NumberKind) {
@@ -486,7 +487,7 @@
 
 
 bool AuditCFRetainRelease::Audit(ExplodedNode<GRState>* N, GRStateManager&) {
-  CallExpr* CE = cast<CallExpr>(cast<PostStmt>(N->getLocation()).getStmt());
+  const CallExpr* CE = cast<CallExpr>(cast<PostStmt>(N->getLocation()).getStmt());
   
   // If the CallExpr doesn't have exactly 1 argument just give up checking.
   if (CE->getNumArgs() != 1)

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

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Wed Jul 22 17:35:28 2009
@@ -40,7 +40,7 @@
 // Helper routines for walking the ExplodedGraph and fetching statements.
 //===----------------------------------------------------------------------===//
 
-static inline Stmt* GetStmt(ProgramPoint P) {
+static inline const Stmt* GetStmt(ProgramPoint P) {
   if (const PostStmt* PS = dyn_cast<PostStmt>(&P))
     return PS->getStmt();
   else if (const BlockEdge* BE = dyn_cast<BlockEdge>(&P))
@@ -59,17 +59,17 @@
   return N->succ_empty() ? NULL : *(N->succ_begin());
 }
 
-static Stmt* GetPreviousStmt(const ExplodedNode<GRState>* N) {
+static const Stmt* GetPreviousStmt(const ExplodedNode<GRState>* N) {
   for (N = GetPredecessorNode(N); N; N = GetPredecessorNode(N))
-    if (Stmt *S = GetStmt(N->getLocation()))
+    if (const Stmt *S = GetStmt(N->getLocation()))
       return S;
   
   return 0;
 }
 
-static Stmt* GetNextStmt(const ExplodedNode<GRState>* N) {
+static const Stmt* GetNextStmt(const ExplodedNode<GRState>* N) {
   for (N = GetSuccessorNode(N); N; N = GetSuccessorNode(N))
-    if (Stmt *S = GetStmt(N->getLocation())) {
+    if (const Stmt *S = GetStmt(N->getLocation())) {
       // Check if the statement is '?' or '&&'/'||'.  These are "merges",
       // not actual statement points.
       switch (S->getStmtClass()) {
@@ -90,15 +90,17 @@
   return 0;
 }
 
-static inline Stmt* GetCurrentOrPreviousStmt(const ExplodedNode<GRState>* N) {  
-  if (Stmt *S = GetStmt(N->getLocation()))
+static inline const Stmt*
+GetCurrentOrPreviousStmt(const ExplodedNode<GRState>* N) {  
+  if (const Stmt *S = GetStmt(N->getLocation()))
     return S;
   
   return GetPreviousStmt(N);
 }
         
-static inline Stmt* GetCurrentOrNextStmt(const ExplodedNode<GRState>* N) {  
-  if (Stmt *S = GetStmt(N->getLocation()))
+static inline const Stmt*
+GetCurrentOrNextStmt(const ExplodedNode<GRState>* N) {  
+  if (const Stmt *S = GetStmt(N->getLocation()))
     return S;
           
   return GetNextStmt(N);
@@ -179,7 +181,7 @@
 
 PathDiagnosticLocation
 PathDiagnosticBuilder::ExecutionContinues(const ExplodedNode<GRState>* N) {
-  if (Stmt *S = GetNextStmt(N))
+  if (const Stmt *S = GetNextStmt(N))
     return PathDiagnosticLocation(S, getSourceManager());
 
   return FullSourceLoc(getCodeDecl().getBodyRBrace(), getSourceManager());
@@ -330,7 +332,7 @@
     if (!isa<PostStmt>(P))
       continue;
     
-    DeclRefExpr* DR = dyn_cast<DeclRefExpr>(cast<PostStmt>(P).getStmt());
+    const DeclRefExpr* DR = dyn_cast<DeclRefExpr>(cast<PostStmt>(P).getStmt());
     
     if (!DR)
       continue;
@@ -340,7 +342,7 @@
     if (X != Y)
       continue;
     
-    VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl());
+    const VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl());
     
     if (!VD)
       continue;
@@ -457,13 +459,13 @@
   
   llvm::SmallSet<SymbolRef, 10> AlreadyProcessed;
   const ExplodedNode<GRState>* N;
-  Stmt* S;
+  const Stmt* S;
   GRBugReporter& BR;
   PathDiagnostic& PD;
   
 public:
-  ScanNotableSymbols(const ExplodedNode<GRState>* n, Stmt* s, GRBugReporter& br,
-                     PathDiagnostic& pd)
+  ScanNotableSymbols(const ExplodedNode<GRState>* n, const Stmt* s,
+                     GRBugReporter& br, PathDiagnostic& pd)
   : N(n), S(s), BR(br), PD(pd) {}
   
   bool HandleBinding(StoreManager& SMgr, Store store,
@@ -523,7 +525,7 @@
           
         case Stmt::GotoStmtClass:
         case Stmt::IndirectGotoStmtClass: {          
-          Stmt* S = GetNextStmt(N);
+          const Stmt* S = GetNextStmt(N);
           
           if (!S)
             continue;
@@ -1199,14 +1201,15 @@
 BugReport::~BugReport() {}
 RangedBugReport::~RangedBugReport() {}
 
-Stmt* BugReport::getStmt(BugReporter& BR) const {  
+const Stmt* BugReport::getStmt(BugReporter& BR) const {  
   ProgramPoint ProgP = EndNode->getLocation();  
-  Stmt *S = NULL;
+  const Stmt *S = NULL;
   
   if (BlockEntrance* BE = dyn_cast<BlockEntrance>(&ProgP)) {
     if (BE->getBlock() == &BR.getCFG()->getExit()) S = GetPreviousStmt(EndNode);
   }
-  if (!S) S = GetStmt(ProgP);  
+  if (!S)
+    S = GetStmt(ProgP);  
   
   return S;  
 }
@@ -1215,7 +1218,7 @@
 BugReport::getEndPath(BugReporterContext& BRC,
                       const ExplodedNode<GRState>* EndPathNode) {
   
-  Stmt* S = getStmt(BRC.getBugReporter());
+  const Stmt* S = getStmt(BRC.getBugReporter());
   
   if (!S)
     return NULL;
@@ -1238,7 +1241,7 @@
 void BugReport::getRanges(BugReporter& BR, const SourceRange*& beg,
                           const SourceRange*& end) {  
   
-  if (Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) {
+  if (const Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) {
     R = E->getSourceRange();
     assert(R.isValid());
     beg = &R;
@@ -1250,9 +1253,9 @@
 
 SourceLocation BugReport::getLocation() const {  
   if (EndNode)
-    if (Stmt* S = GetCurrentOrPreviousStmt(EndNode)) {
+    if (const Stmt* S = GetCurrentOrPreviousStmt(EndNode)) {
       // For member expressions, return the location of the '.' or '->'.
-      if (MemberExpr* ME = dyn_cast<MemberExpr>(S))
+      if (const MemberExpr* ME = dyn_cast<MemberExpr>(S))
         return ME->getMemberLoc();
 
       return S->getLocStart();

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

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporterVisitors.cpp Wed Jul 22 17:35:28 2009
@@ -200,7 +200,7 @@
     }
     
     // FIXME: Refactor this into BugReporterContext.
-    Stmt *S = 0;      
+    const Stmt *S = 0;      
     ProgramPoint P = N->getLocation();
     
     if (BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
@@ -266,7 +266,7 @@
         return NULL;
       
       // FIXME: Refactor this into BugReporterContext.
-      Stmt *S = 0;      
+      const Stmt *S = 0;      
       ProgramPoint P = N->getLocation();
       
       if (BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {

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

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Wed Jul 22 17:35:28 2009
@@ -2298,9 +2298,9 @@
   // This is the allocation site since the previous node had no bindings
   // for this symbol.
   if (!PrevT) {
-    Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
+    const Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
     
-    if (CallExpr *CE = dyn_cast<CallExpr>(S)) {
+    if (const CallExpr *CE = dyn_cast<CallExpr>(S)) {
       // Get the name of the callee (if it is available).
       SVal X = CurrSt->getSValAsScalarOrLoc(CE->getCallee());
       if (const FunctionDecl* FD = X.getAsFunctionDecl())
@@ -2347,14 +2347,14 @@
         TF.getSummaryOfNode(BRC.getNodeResolver().getOriginalNode(N))) {
     // We only have summaries attached to nodes after evaluating CallExpr and
     // ObjCMessageExprs.
-    Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
+    const Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
     
-    if (CallExpr *CE = dyn_cast<CallExpr>(S)) {
+    if (const CallExpr *CE = dyn_cast<CallExpr>(S)) {
       // Iterate through the parameter expressions and see if the symbol
       // was ever passed as an argument.
       unsigned i = 0;
       
-      for (CallExpr::arg_iterator AI=CE->arg_begin(), AE=CE->arg_end();
+      for (CallExpr::const_arg_iterator AI=CE->arg_begin(), AE=CE->arg_end();
            AI!=AE; ++AI, ++i) {
         
         // Retrieve the value of the argument.  Is it the symbol
@@ -2366,8 +2366,8 @@
         AEffects.push_back(Summ->getArg(i));
       }
     }
-    else if (ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(S)) {      
-      if (Expr *receiver = ME->getReceiver())
+    else if (const ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(S)) {      
+      if (const Expr *receiver = ME->getReceiver())
         if (CurrSt->getSValAsScalarOrLoc(receiver).getAsLocSymbol() == Sym) {
           // The symbol we are tracking is the receiver.
           AEffects.push_back(Summ->getReceiverEffect());
@@ -2395,7 +2395,7 @@
     // Specially handle CFMakeCollectable and friends.
     if (contains(AEffects, MakeCollectable)) {
       // Get the name of the function.
-      Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
+      const Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
       SVal X = CurrSt->getSValAsScalarOrLoc(cast<CallExpr>(S)->getCallee());
       const FunctionDecl* FD = X.getAsFunctionDecl();
       const std::string& FName = FD->getNameAsString();
@@ -2499,14 +2499,15 @@
   if (os.str().empty())
     return 0; // We have nothing to say!
 
-  Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
+  const Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
   PathDiagnosticLocation Pos(S, BRC.getSourceManager());
   PathDiagnosticPiece* P = new PathDiagnosticEventPiece(Pos, os.str());
   
   // Add the range by scanning the children of the statement for any bindings
   // to Sym.
-  for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
-    if (Expr* Exp = dyn_cast_or_null<Expr>(*I))
+  for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end(); 
+       I!=E; ++I)
+    if (const Expr* Exp = dyn_cast_or_null<Expr>(*I))
       if (CurrSt->getSValAsScalarOrLoc(Exp).getAsLocSymbol() == Sym) {
         P->addRange(Exp->getSourceRange());
         break;
@@ -2602,7 +2603,7 @@
   
   // Get the allocate site.  
   assert(AllocNode);
-  Stmt* FirstStmt = cast<PostStmt>(AllocNode->getLocation()).getStmt();
+  const Stmt* FirstStmt = cast<PostStmt>(AllocNode->getLocation()).getStmt();
   
   SourceManager& SMgr = BRC.getSourceManager();
   unsigned AllocLine =SMgr.getInstantiationLineNumber(FirstStmt->getLocStart());

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRCoreEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRCoreEngine.cpp Wed Jul 22 17:35:28 2009
@@ -390,7 +390,7 @@
     Eng.WList->Enqueue(Succ, B, Idx+1);
 }
 
-static inline PostStmt GetPostLoc(Stmt* S, ProgramPoint::Kind K,
+static inline PostStmt GetPostLoc(const Stmt* S, ProgramPoint::Kind K,
                                   const void *tag) {
   switch (K) {
     default:
@@ -426,7 +426,7 @@
 }
 
 ExplodedNodeImpl*
-GRStmtNodeBuilderImpl::generateNodeImpl(Stmt* S, const void* State,
+GRStmtNodeBuilderImpl::generateNodeImpl(const Stmt* S, const void* State,
                                         ExplodedNodeImpl* Pred,
                                         ProgramPoint::Kind K,
                                         const void *tag) {

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Wed Jul 22 17:35:28 2009
@@ -89,7 +89,7 @@
       isSink |= (*I)->Audit(N, VMgr);
     
     // Next handle the auditors that accept only specific statements.
-    Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
+    const Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
     void* key = reinterpret_cast<void*>((uintptr_t) S->getStmtClass());
     MapTy::iterator MI = M.find(key);
     if (MI != M.end()) {    
@@ -3096,9 +3096,8 @@
         break;
         
       default: {
-        if (isa<PostStmt>(Loc)) {
-          const PostStmt& L = cast<PostStmt>(Loc);        
-          Stmt* S = L.getStmt();
+        if (StmtPoint *L = dyn_cast<StmtPoint>(&Loc)) {
+          const Stmt* S = L->getStmt();
           SourceLocation SLoc = S->getLocStart();
 
           Out << S->getStmtClassName() << ' ' << (void*) S << ' ';        
@@ -3113,7 +3112,9 @@
               << "\\l";
           }
           
-          if (isa<PostLoad>(Loc))
+          if (isa<PreStmt>(Loc))
+            Out << "\\lPreStmt\\l;";          
+          else if (isa<PostLoad>(Loc))
             Out << "\\lPostLoad\\l;";
           else if (isa<PostStore>(Loc))
             Out << "\\lPostStore\\l";

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp Wed Jul 22 17:35:28 2009
@@ -120,7 +120,7 @@
       std::string sbuf;
       llvm::raw_string_ostream os(sbuf);
       PostStmt P = cast<PostStmt>((*I)->getLocation());
-      ObjCMessageExpr *ME = cast<ObjCMessageExpr>(P.getStmt());
+      const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(P.getStmt());
       os << "The receiver in the message expression is 'nil' and results in the"
             " returned value (of type '"
          << ME->getType().getAsString()
@@ -153,7 +153,7 @@
       std::string sbuf;
       llvm::raw_string_ostream os(sbuf);
       PostStmt P = cast<PostStmt>((*I)->getLocation());
-      ObjCMessageExpr *ME = cast<ObjCMessageExpr>(P.getStmt());
+      const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(P.getStmt());
       os << "The receiver in the message expression is 'nil' and results in the"
       " returned value (of type '"
       << ME->getType().getAsString()
@@ -305,8 +305,8 @@
       // Generate a report for this bug.
       BuiltinBugReport *report = new BuiltinBugReport(*this, desc.c_str(), *I);
       ExplodedNode<GRState>* N = *I;
-      Stmt *S = cast<PostStmt>(N->getLocation()).getStmt();
-      Expr* E = cast<ObjCMessageExpr>(S)->getReceiver();
+      const Stmt *S = cast<PostStmt>(N->getLocation()).getStmt();
+      const Expr* E = cast<ObjCMessageExpr>(S)->getReceiver();
       assert (E && "Receiver cannot be NULL");
       report->addRange(E->getSourceRange());
       BR.EmitReport(report);
@@ -330,9 +330,9 @@
          End = Eng.ret_stackaddr_end(); I!=End; ++I) {
 
       ExplodedNode<GRState>* N = *I;
-      Stmt *S = cast<PostStmt>(N->getLocation()).getStmt();
-      Expr* E = cast<ReturnStmt>(S)->getRetValue();
-      assert (E && "Return expression cannot be NULL");
+      const Stmt *S = cast<PostStmt>(N->getLocation()).getStmt();
+      const Expr* E = cast<ReturnStmt>(S)->getRetValue();
+      assert(E && "Return expression cannot be NULL");
       
       // Get the value associated with E.
       loc::MemRegionVal V = cast<loc::MemRegionVal>(N->getState()->getSVal(E));
@@ -493,7 +493,7 @@
       // undefined size.
       GRExprEngine::NodeTy* N = *I;
       PostStmt PS = cast<PostStmt>(N->getLocation());      
-      DeclStmt *DS = cast<DeclStmt>(PS.getStmt());
+      const DeclStmt *DS = cast<DeclStmt>(PS.getStmt());
       VarDecl* VD = cast<VarDecl>(*DS->decl_begin());
       QualType T = Eng.getContext().getCanonicalType(VD->getType());
       VariableArrayType* VT = cast<VariableArrayType>(T);

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRState.cpp (original)
+++ cfe/trunk/lib/Analysis/GRState.cpp Wed Jul 22 17:35:28 2009
@@ -324,7 +324,7 @@
 // Queries.
 //===----------------------------------------------------------------------===//
 
-bool GRStateManager::isEqual(const GRState* state, Expr* Ex,
+bool GRStateManager::isEqual(const GRState* state, const Expr* Ex,
                              const llvm::APSInt& Y) {
   
   SVal V = state->getSVal(Ex);
@@ -341,7 +341,7 @@
   return false;
 }
   
-bool GRStateManager::isEqual(const GRState* state, Expr* Ex, uint64_t x) {
+bool GRStateManager::isEqual(const GRState* state, const Expr* Ex, uint64_t x) {
   return isEqual(state, Ex, getBasicVals().getValue(x, Ex->getType()));
 }
 





More information about the cfe-commits mailing list