diff options
author | Zhongxing Xu <xuzhongxing@gmail.com> | 2010-01-18 08:54:31 +0000 |
---|---|---|
committer | Zhongxing Xu <xuzhongxing@gmail.com> | 2010-01-18 08:54:31 +0000 |
commit | 228b0d4defb85b2e7acbb642b9f0b5dfc49d3fe7 (patch) | |
tree | d013b6e660ba68e6581a56df03a9ec628df4fe80 /clang/lib/Analysis/MallocChecker.cpp | |
parent | d382d17f09e9123e29d4080a112fdef84f75696f (diff) | |
download | bcm5719-llvm-228b0d4defb85b2e7acbb642b9f0b5dfc49d3fe7.tar.gz bcm5719-llvm-228b0d4defb85b2e7acbb642b9f0b5dfc49d3fe7.zip |
Add support for computing size in elements for symbolic regions obtained from
malloc().
llvm-svn: 93722
Diffstat (limited to 'clang/lib/Analysis/MallocChecker.cpp')
-rw-r--r-- | clang/lib/Analysis/MallocChecker.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/clang/lib/Analysis/MallocChecker.cpp b/clang/lib/Analysis/MallocChecker.cpp index 5bd27912e41..28f4db78806 100644 --- a/clang/lib/Analysis/MallocChecker.cpp +++ b/clang/lib/Analysis/MallocChecker.cpp @@ -72,7 +72,7 @@ public: private: void MallocMem(CheckerContext &C, const CallExpr *CE); const GRState *MallocMemAux(CheckerContext &C, const CallExpr *CE, - const GRState *state); + const Expr *SizeEx, const GRState *state); void FreeMem(CheckerContext &C, const CallExpr *CE); const GRState *FreeMemAux(CheckerContext &C, const CallExpr *CE, const GRState *state); @@ -136,18 +136,24 @@ bool MallocChecker::EvalCallExpr(CheckerContext &C, const CallExpr *CE) { } void MallocChecker::MallocMem(CheckerContext &C, const CallExpr *CE) { - const GRState *state = MallocMemAux(C, CE, C.getState()); + const GRState *state = MallocMemAux(C, CE, CE->getArg(0), C.getState()); C.addTransition(state); } const GRState *MallocChecker::MallocMemAux(CheckerContext &C, const CallExpr *CE, + const Expr *SizeEx, const GRState *state) { unsigned Count = C.getNodeBuilder().getCurrentBlockCount(); ValueManager &ValMgr = C.getValueManager(); SVal RetVal = ValMgr.getConjuredSymbolVal(NULL, CE, CE->getType(), Count); + SVal Size = state->getSVal(SizeEx); + + state = C.getEngine().getStoreManager().setExtent(state, RetVal.getAsRegion(), + Size); + state = state->BindExpr(CE, RetVal); SymbolRef Sym = RetVal.getAsLocSymbol(); @@ -216,7 +222,7 @@ void MallocChecker::ReallocMem(CheckerContext &C, const CallExpr *CE) { if (Sym) stateEqual = stateEqual->set<RegionState>(Sym, RefState::getReleased(CE)); - const GRState *stateMalloc = MallocMemAux(C, CE, stateEqual); + const GRState *stateMalloc = MallocMemAux(C, CE, CE->getArg(1), stateEqual); C.addTransition(stateMalloc); } @@ -237,7 +243,8 @@ void MallocChecker::ReallocMem(CheckerContext &C, const CallExpr *CE) { const GRState *stateFree = FreeMemAux(C, CE, stateSizeNotZero); if (stateFree) { // FIXME: We should copy the content of the original buffer. - const GRState *stateRealloc = MallocMemAux(C, CE, stateFree); + const GRState *stateRealloc = MallocMemAux(C, CE, CE->getArg(1), + stateFree); C.addTransition(stateRealloc); } } |