[llvm-branch-commits] [cfe-branch] r71326 - in /cfe/branches/Apple/Dib: lib/Analysis/RegionStore.cpp test/Analysis/rdar-6541136-region.c

Mike Stump mrs at apple.com
Fri May 8 23:10:00 PDT 2009


Author: mrs
Date: Sat May  9 01:10:00 2009
New Revision: 71326

URL: http://llvm.org/viewvc/llvm-project?rev=71326&view=rev
Log:
Merge in 71074:

Implement a heuristic type size comparison method for now.

Modified:
    cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp
    cfe/branches/Apple/Dib/test/Analysis/rdar-6541136-region.c

Modified: cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp?rev=71326&r1=71325&r2=71326&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp Sat May  9 01:10:00 2009
@@ -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)) {

Modified: cfe/branches/Apple/Dib/test/Analysis/rdar-6541136-region.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/test/Analysis/rdar-6541136-region.c?rev=71326&r1=71325&r2=71326&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/test/Analysis/rdar-6541136-region.c (original)
+++ cfe/branches/Apple/Dib/test/Analysis/rdar-6541136-region.c Sat May  9 01:10:00 2009
@@ -13,5 +13,7 @@
   struct load_wine *cmd = (void*) &wonky[1];
   cmd = cmd;
   char *p = (void*) &wonky[1];
-  *p = 1; // expected-warning{{Load or store into an out-of-bound memory}}
+  *p = 1; 
+  kernel_tea_cheese_t *q = &wonky[1];
+  kernel_tea_cheese_t r = *q; // expected-warning{{out-of-bound memory position}}
 }





More information about the llvm-branch-commits mailing list