]> granicus.if.org Git - clang/commitdiff
Convert the offset to signed before making an ElementRegion with it. It seems
authorZhongxing Xu <xuzhongxing@gmail.com>
Thu, 19 Feb 2009 08:37:16 +0000 (08:37 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Thu, 19 Feb 2009 08:37:16 +0000 (08:37 +0000)
that this problem arises from time to time. We should find a fundamental
solution for it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65035 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/RegionStore.cpp

index 66aabcb49edd44efbf40f819ccc20e79d40f7c5a..58d8670d30a1ce51046fe0a17915e9a36756fd0c 100644 (file)
@@ -367,6 +367,16 @@ SVal RegionStoreManager::getLValueElement(const GRState* St,
     //
     //  Observe that 'p' binds to an AnonTypedRegion<AllocaRegion>.
     //
+
+    // Offset might be unsigned. We have to convert it to signed ConcreteInt.
+    if (nonloc::ConcreteInt* CI = dyn_cast<nonloc::ConcreteInt>(&Offset)) {
+      const llvm::APSInt& OffI = CI->getValue();
+      if (OffI.isUnsigned()) {
+        llvm::APSInt Tmp = OffI;
+        Tmp.setIsSigned(true);
+        Offset = NonLoc::MakeVal(getBasicVals(), Tmp);
+      }
+    }
     return loc::MemRegionVal(MRMgr.getElementRegion(Offset, BaseRegion));
   }
   
@@ -397,7 +407,7 @@ SVal RegionStoreManager::getLValueElement(const GRState* St,
     
     Tmp.setIsSigned(true);
     Tmp += BaseIdxI; // Compute the new offset.    
-    NewIdx = nonloc::ConcreteInt(getBasicVals().getValue(Tmp));    
+    NewIdx = NonLoc::MakeVal(getBasicVals(), Tmp);    
   }
   else
     NewIdx = nonloc::ConcreteInt(getBasicVals().getValue(BaseIdxI + OffI));