From 7d71b296c719cc055f9a599fbcb2bb5900e3f2b1 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 9 Dec 2008 21:20:27 +0000 Subject: [PATCH] Have BasicStoreManager::getLValueElement() have logic similar to BasicStoreManager::getLValueField() (i.e., don't just return the 'base' as the SVal) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60795 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/BasicStore.cpp | 39 +++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp index c3146cba40..31d392e80f 100644 --- a/lib/Analysis/BasicStore.cpp +++ b/lib/Analysis/BasicStore.cpp @@ -165,8 +165,43 @@ SVal BasicStoreManager::getLValueField(const GRState* St, SVal Base, SVal BasicStoreManager::getLValueElement(const GRState* St, SVal Base, SVal Offset) { - // Total hack: Just return "Base" for now. - return Base; + + + if (Base.isUnknownOrUndef()) + return Base; + + Loc BaseL = cast(Base); + const MemRegion* BaseR = 0; + + switch(BaseL.getSubKind()) { + case loc::SymbolValKind: + BaseR = MRMgr.getSymbolicRegion(cast(&BaseL)->getSymbol()); + break; + + case loc::GotoLabelKind: + case loc::FuncValKind: + // Technically we can get here if people do funny things with casts. + return UndefinedVal(); + + case loc::MemRegionKind: + BaseR = cast(BaseL).getRegion(); + break; + + case loc::ConcreteIntKind: + // While these seem funny, this can happen through casts. + // FIXME: What we should return is the field offset. For example, + // add the field offset to the integer value. That way funny things + // like this work properly: &(((struct foo *) 0xa)->f) + return Base; + + default: + assert ("Unhandled Base."); + return Base; + } + + // We return an "unknown" index because we aren't reasoning about indices + // at all. + return loc::MemRegionVal(MRMgr.getElementRegion(UnknownVal(), BaseR)); } SVal BasicStoreManager::Retrieve(const GRState* state, Loc LV, QualType T) { -- 2.40.0