]> granicus.if.org Git - clang/commitdiff
Have BasicStoreManager::getLValueElement() have logic similar to BasicStoreManager...
authorTed Kremenek <kremenek@apple.com>
Tue, 9 Dec 2008 21:20:27 +0000 (21:20 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 9 Dec 2008 21:20:27 +0000 (21:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60795 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/BasicStore.cpp

index c3146cba408f7ecf5ef9f48e2d4b67d430eb23a3..31d392e80f44878cdaf23f44c977df6f6bbe4f02 100644 (file)
@@ -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) {