Implement a heuristic type size comparison method for now.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71074 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp
index 145559e..5f8e6c3 100644
--- a/lib/Analysis/RegionStore.cpp
+++ b/lib/Analysis/RegionStore.cpp
@@ -554,6 +554,10 @@
     return UnknownVal();
   }
 
+  if (isa<ElementRegion>(R)) {
+    return UnknownVal();
+  }
+
   assert(0 && "Other regions are not supported yet.");
   return UnknownVal();
 }
@@ -585,6 +589,13 @@
   return loc::MemRegionVal(ER);                    
 }
 
+static bool isSmallerThan(QualType T1, QualType T2) {
+  if (T1->isCharType())
+    return true;
+  else
+    return false;
+}
+
 RegionStoreManager::CastResult
 RegionStoreManager::CastRegion(const GRState* state, const MemRegion* R,
                          QualType CastToTy) {
@@ -637,9 +648,14 @@
   // VarRegion.
   if (isa<VarRegion>(R) || isa<ElementRegion>(R) || isa<FieldRegion>(R)
       || isa<ObjCIvarRegion>(R) || isa<CompoundLiteralRegion>(R)) {
-    // FIXME: create an ElementRegion when the size of the pointee type is
-    // smaller than the region.
-    return CastResult(state, R);
+    if (isSmallerThan(PointeeTy, 
+                      cast<TypedRegion>(R)->getRValueType(getContext()))) {
+      SVal Idx = ValMgr.makeZeroArrayIndex();
+      ElementRegion* ER = MRMgr.getElementRegion(PointeeTy, Idx, 
+                                                 cast<TypedRegion>(R));
+      return CastResult(state, ER);
+    } else
+      return CastResult(state, R);
   }
 
   if (isa<TypedViewRegion>(R)) {