aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/BasicStore.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-12-09 21:20:27 +0000
committerTed Kremenek <kremenek@apple.com>2008-12-09 21:20:27 +0000
commit7d71b296c719cc055f9a599fbcb2bb5900e3f2b1 (patch)
tree901dbd46b06b18c58f1249a21e8a315c12a12fba /lib/Analysis/BasicStore.cpp
parentd82565fee66c623950852742dd7dc4ad987d53f6 (diff)
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
Diffstat (limited to 'lib/Analysis/BasicStore.cpp')
-rw-r--r--lib/Analysis/BasicStore.cpp39
1 files 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<Loc>(Base);
+ const MemRegion* BaseR = 0;
+
+ switch(BaseL.getSubKind()) {
+ case loc::SymbolValKind:
+ BaseR = MRMgr.getSymbolicRegion(cast<loc::SymbolVal>(&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<loc::MemRegionVal>(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) {