diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-03-30 17:53:05 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-03-30 17:53:05 +0000 |
commit | 4967c8979e8aa11a59c8d1e46ebdc88f7f9f0646 (patch) | |
tree | 14e9bb7bcc06cc9469fe2833bbebb1cf4b56790c | |
parent | 9d98cc6b93cf423c582c3ec6782cf5325b4b4950 (diff) | |
download | bcm5719-llvm-4967c8979e8aa11a59c8d1e46ebdc88f7f9f0646.tar.gz bcm5719-llvm-4967c8979e8aa11a59c8d1e46ebdc88f7f9f0646.zip |
Add version of GRExprEngine::AddCheck that registered a GRSimpleAPICheck that
will be called for every expression in a basic block.
llvm-svn: 68041
-rw-r--r-- | clang/include/clang/Analysis/PathSensitive/GRExprEngine.h | 1 | ||||
-rw-r--r-- | clang/lib/Analysis/GRExprEngine.cpp | 36 |
2 files changed, 27 insertions, 10 deletions
diff --git a/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h b/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h index 4c0abdcb094..1dee5d267ad 100644 --- a/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h +++ b/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h @@ -395,6 +395,7 @@ public: } void AddCheck(GRSimpleAPICheck* A, Stmt::StmtClass C); + void AddCheck(GRSimpleAPICheck* A); /// ProcessStmt - Called by GRCoreEngine. Used to generate new successor /// nodes by processing the 'effects' of a block-level statement. diff --git a/clang/lib/Analysis/GRExprEngine.cpp b/clang/lib/Analysis/GRExprEngine.cpp index 41f6453a903..2b5808f562e 100644 --- a/clang/lib/Analysis/GRExprEngine.cpp +++ b/clang/lib/Analysis/GRExprEngine.cpp @@ -46,9 +46,11 @@ class VISIBILITY_HIDDEN MappedBatchAuditor : public GRSimpleAPICheck { MapTy M; Checks::Factory F; + Checks AllStmts; public: - MappedBatchAuditor(llvm::BumpPtrAllocator& Alloc) : F(Alloc) {} + MappedBatchAuditor(llvm::BumpPtrAllocator& Alloc) : + F(Alloc), AllStmts(F.GetEmptyList()) {} virtual ~MappedBatchAuditor() { llvm::DenseSet<GRSimpleAPICheck*> AlreadyVisited; @@ -66,26 +68,33 @@ public: } } - void AddCheck(GRSimpleAPICheck* A, Stmt::StmtClass C) { + void AddCheck(GRSimpleAPICheck *A, Stmt::StmtClass C) { assert (A && "Check cannot be null."); void* key = reinterpret_cast<void*>((uintptr_t) C); MapTy::iterator I = M.find(key); M[key] = F.Concat(A, I == M.end() ? F.GetEmptyList() : I->second); } + + void AddCheck(GRSimpleAPICheck *A) { + assert (A && "Check cannot be null."); + AllStmts = F.Concat(A, AllStmts); + } virtual bool Audit(NodeTy* N, GRStateManager& VMgr) { + // First handle the auditors that accept all statements. + bool isSink = false; + for (Checks::iterator I = AllStmts.begin(), E = AllStmts.end(); I!=E; ++I) + isSink |= (*I)->Audit(N, VMgr); + + // Next handle the auditors that accept only specific statements. 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()) - return false; - - bool isSink = false; + if (MI != M.end()) { + for (Checks::iterator I=MI->second.begin(), E=MI->second.end(); I!=E; ++I) + isSink |= (*I)->Audit(N, VMgr); + } - for (Checks::iterator I=MI->second.begin(), E=MI->second.end(); I!=E; ++I) - isSink |= (*I)->Audit(N, VMgr); - return isSink; } }; @@ -143,6 +152,13 @@ void GRExprEngine::AddCheck(GRSimpleAPICheck* A, Stmt::StmtClass C) { ((MappedBatchAuditor*) BatchAuditor.get())->AddCheck(A, C); } +void GRExprEngine::AddCheck(GRSimpleAPICheck *A) { + if (!BatchAuditor) + BatchAuditor.reset(new MappedBatchAuditor(getGraph().getAllocator())); + + ((MappedBatchAuditor*) BatchAuditor.get())->AddCheck(A); +} + const GRState* GRExprEngine::getInitialState() { return StateMgr.getInitialState(); } |