diff options
-rw-r--r-- | include/clang/Analysis/PathSensitive/BugReporter.h | 2 | ||||
-rw-r--r-- | include/clang/Analysis/PathSensitive/GRCoreEngine.h | 14 | ||||
-rw-r--r-- | include/clang/Analysis/PathSensitive/GRState.h | 4 | ||||
-rw-r--r-- | include/clang/Analysis/ProgramPoint.h | 41 | ||||
-rw-r--r-- | lib/Analysis/BasicObjCFoundationChecks.cpp | 27 | ||||
-rw-r--r-- | lib/Analysis/BugReporter.cpp | 49 | ||||
-rw-r--r-- | lib/Analysis/BugReporterVisitors.cpp | 4 | ||||
-rw-r--r-- | lib/Analysis/CFRefCount.cpp | 25 | ||||
-rw-r--r-- | lib/Analysis/GRCoreEngine.cpp | 4 | ||||
-rw-r--r-- | lib/Analysis/GRExprEngine.cpp | 11 | ||||
-rw-r--r-- | lib/Analysis/GRExprEngineInternalChecks.cpp | 16 | ||||
-rw-r--r-- | lib/Analysis/GRState.cpp | 4 |
12 files changed, 107 insertions, 94 deletions
diff --git a/include/clang/Analysis/PathSensitive/BugReporter.h b/include/clang/Analysis/PathSensitive/BugReporter.h index c90e5597b6..042564e0e0 100644 --- a/include/clang/Analysis/PathSensitive/BugReporter.h +++ b/include/clang/Analysis/PathSensitive/BugReporter.h @@ -101,7 +101,7 @@ public: // 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; } diff --git a/include/clang/Analysis/PathSensitive/GRCoreEngine.h b/include/clang/Analysis/PathSensitive/GRCoreEngine.h index 3d8b0ea18e..8fb2506fa1 100644 --- a/include/clang/Analysis/PathSensitive/GRCoreEngine.h +++ b/include/clang/Analysis/PathSensitive/GRCoreEngine.h @@ -146,12 +146,12 @@ public: 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 @@ public: } 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 @@ public: 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); } diff --git a/include/clang/Analysis/PathSensitive/GRState.h b/include/clang/Analysis/PathSensitive/GRState.h index 1551f961cf..e6e7960869 100644 --- a/include/clang/Analysis/PathSensitive/GRState.h +++ b/include/clang/Analysis/PathSensitive/GRState.h @@ -525,8 +525,8 @@ public: 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. diff --git a/include/clang/Analysis/ProgramPoint.h b/include/clang/Analysis/ProgramPoint.h index a22fd25f28..8951e83a7c 100644 --- a/include/clang/Analysis/ProgramPoint.h +++ b/include/clang/Analysis/ProgramPoint.h @@ -130,40 +130,47 @@ public: 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(); diff --git a/lib/Analysis/BasicObjCFoundationChecks.cpp b/lib/Analysis/BasicObjCFoundationChecks.cpp index 8bbf94c072..7620377987 100644 --- a/lib/Analysis/BasicObjCFoundationChecks.cpp +++ b/lib/Analysis/BasicObjCFoundationChecks.cpp @@ -63,10 +63,10 @@ class VISIBILITY_HIDDEN BasicObjCFoundationChecks : public GRSimpleAPICheck { 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 @@ public: 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 @@ clang::CreateBasicObjCFoundationChecks(ASTContext& Ctx, BugReporter& BR) { 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 @@ static inline bool isNil(SVal X) { //===----------------------------------------------------------------------===// 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::isNSString(const ObjCInterfaceType *T, } bool BasicObjCFoundationChecks::AuditNSString(NodeTy* N, - ObjCMessageExpr* ME) { + const ObjCMessageExpr* ME) { Selector S = ME->getSelector(); @@ -257,7 +257,7 @@ public: 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 @@ static const char* GetCFNumberTypeStr(uint64_t i) { #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 @@ bool AuditCFNumberCreate::Audit(ExplodedNode<GRState>* N,GRStateManager&){ 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 @@ public: 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) diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp index a691bb67aa..43e1e6c8bc 100644 --- a/lib/Analysis/BugReporter.cpp +++ b/lib/Analysis/BugReporter.cpp @@ -40,7 +40,7 @@ BugReporterContext::~BugReporterContext() { // 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 @@ GetSuccessorNode(const ExplodedNode<GRState>* N) { 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 @@ static Stmt* GetNextStmt(const ExplodedNode<GRState>* N) { 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 @@ public: 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 @@ GetMostRecentVarDeclBinding(const ExplodedNode<GRState>* N, 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 @@ GetMostRecentVarDeclBinding(const ExplodedNode<GRState>* N, 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 @@ class VISIBILITY_HIDDEN ScanNotableSymbols 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 @@ static void GenerateMinimalPathDiagnostic(PathDiagnostic& PD, case Stmt::GotoStmtClass: case Stmt::IndirectGotoStmtClass: { - Stmt* S = GetNextStmt(N); + const Stmt* S = GetNextStmt(N); if (!S) continue; @@ -1199,14 +1201,15 @@ void BugType::FlushReports(BugReporter &BR) {} 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 @@ PathDiagnosticPiece* 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 @@ BugReport::getEndPath(BugReporterContext& BRC, 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 @@ void BugReport::getRanges(BugReporter& BR, const SourceRange*& beg, 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(); diff --git a/lib/Analysis/BugReporterVisitors.cpp b/lib/Analysis/BugReporterVisitors.cpp index 7096f66b22..2efa4c6857 100644 --- a/lib/Analysis/BugReporterVisitors.cpp +++ b/lib/Analysis/BugReporterVisitors.cpp @@ -200,7 +200,7 @@ public: } // 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 @@ public: 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)) { diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 908211ad7a..04f9cb82a2 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -2298,9 +2298,9 @@ PathDiagnosticPiece* CFRefReport::VisitNode(const ExplodedNode<GRState>* N, // 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 @@ PathDiagnosticPiece* CFRefReport::VisitNode(const ExplodedNode<GRState>* N, 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 @@ PathDiagnosticPiece* CFRefReport::VisitNode(const ExplodedNode<GRState>* N, 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 @@ PathDiagnosticPiece* CFRefReport::VisitNode(const ExplodedNode<GRState>* N, // 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 @@ PathDiagnosticPiece* CFRefReport::VisitNode(const ExplodedNode<GRState>* N, 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 @@ CFRefLeakReport::getEndPath(BugReporterContext& BRC, // 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()); diff --git a/lib/Analysis/GRCoreEngine.cpp b/lib/Analysis/GRCoreEngine.cpp index 5a45ad2ce4..5a92143e18 100644 --- a/lib/Analysis/GRCoreEngine.cpp +++ b/lib/Analysis/GRCoreEngine.cpp @@ -390,7 +390,7 @@ void GRStmtNodeBuilderImpl::GenerateAutoTransition(ExplodedNodeImpl* N) { 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 @@ static inline PostStmt GetPostLoc(Stmt* S, ProgramPoint::Kind K, } ExplodedNodeImpl* -GRStmtNodeBuilderImpl::generateNodeImpl(Stmt* S, const void* State, +GRStmtNodeBuilderImpl::generateNodeImpl(const Stmt* S, const void* State, ExplodedNodeImpl* Pred, ProgramPoint::Kind K, const void *tag) { diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index 24e4cfaaa1..eb31f84b0c 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -89,7 +89,7 @@ public: 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 @@ struct VISIBILITY_HIDDEN DOTGraphTraits<GRExprEngine::NodeTy*> : 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 @@ struct VISIBILITY_HIDDEN DOTGraphTraits<GRExprEngine::NodeTy*> : << "\\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"; diff --git a/lib/Analysis/GRExprEngineInternalChecks.cpp b/lib/Analysis/GRExprEngineInternalChecks.cpp index c84b6c001b..91fb6a8c03 100644 --- a/lib/Analysis/GRExprEngineInternalChecks.cpp +++ b/lib/Analysis/GRExprEngineInternalChecks.cpp @@ -120,7 +120,7 @@ public: 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 @@ public: 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 @@ public: // 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 @@ public: 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 @@ public: // 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); diff --git a/lib/Analysis/GRState.cpp b/lib/Analysis/GRState.cpp index b849bea0b5..5728aae3ff 100644 --- a/lib/Analysis/GRState.cpp +++ b/lib/Analysis/GRState.cpp @@ -324,7 +324,7 @@ bool GRState::scanReachableSymbols(SVal val, SymbolVisitor& visitor) const { // 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 @@ bool GRStateManager::isEqual(const GRState* state, Expr* Ex, 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())); } |