diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-10-06 01:39:48 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-10-06 01:39:48 +0000 |
commit | cd8f6ac9b613e1fe962ebf9c87d822ce765275e6 (patch) | |
tree | 9571f28a057b3d9bc021e9d6af2ab420fe7da2e6 /lib/Analysis/RegionStore.cpp | |
parent | 2e9f652d53346bf7e64c8a12a9ff06b004a3e489 (diff) |
Fix: <rdar://problem/7275774> Static analyzer warns about NULL pointer when
adding assert
This fix required a few changes:
SimpleSValuator:
- Eagerly replace a symbolic value with its constant value in EvalBinOpNN
when it is constrained to a constant. This allows us to better constant fold
values along a path.
- Handle trivial case of '<', '>' comparison of pointers when the two pointers
are exactly the same.
RegionStoreManager:
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83358 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/RegionStore.cpp')
-rw-r--r-- | lib/Analysis/RegionStore.cpp | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 7a433dd148..46e1d12a3c 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -826,7 +826,10 @@ SVal RegionStoreManager::EvalBinOp(const GRState *state, // Not yet handled. case MemRegion::VarRegionKind: - case MemRegion::StringRegionKind: + case MemRegion::StringRegionKind: { + + } + // Fall-through. case MemRegion::CompoundLiteralRegionKind: case MemRegion::FieldRegionKind: case MemRegion::ObjCObjectRegionKind: @@ -851,17 +854,27 @@ SVal RegionStoreManager::EvalBinOp(const GRState *state, SVal Idx = ER->getIndex(); nonloc::ConcreteInt* Base = dyn_cast<nonloc::ConcreteInt>(&Idx); - nonloc::ConcreteInt* Offset = dyn_cast<nonloc::ConcreteInt>(&R); - // Only support concrete integer indexes for now. - if (Base && Offset) { - // FIXME: Should use SValuator here. - SVal NewIdx = Base->evalBinOp(ValMgr, Op, + // For now, only support: + // (a) concrete integer indices that can easily be resolved + // (b) 0 + symbolic index + if (Base) { + if (nonloc::ConcreteInt *Offset = dyn_cast<nonloc::ConcreteInt>(&R)) { + // FIXME: Should use SValuator here. + SVal NewIdx = + Base->evalBinOp(ValMgr, Op, cast<nonloc::ConcreteInt>(ValMgr.convertToArrayIndex(*Offset))); - const MemRegion* NewER = - MRMgr.getElementRegion(ER->getElementType(), NewIdx, ER->getSuperRegion(), - getContext()); - return ValMgr.makeLoc(NewER); + const MemRegion* NewER = + MRMgr.getElementRegion(ER->getElementType(), NewIdx, + ER->getSuperRegion(), getContext()); + return ValMgr.makeLoc(NewER); + } + if (0 == Base->getValue()) { + const MemRegion* NewER = + MRMgr.getElementRegion(ER->getElementType(), R, + ER->getSuperRegion(), getContext()); + return ValMgr.makeLoc(NewER); + } } return UnknownVal(); |