[cfe-commits] r83069 - in /cfe/trunk: lib/Analysis/RegionStore.cpp test/Analysis/misc-ps-region-store.m

Ted Kremenek kremenek at apple.com
Tue Sep 29 09:36:48 PDT 2009


Author: kremenek
Date: Tue Sep 29 11:36:48 2009
New Revision: 83069

URL: http://llvm.org/viewvc/llvm-project?rev=83069&view=rev
Log:
Fix: <rdar://problem/7261075> [RegionStore] crash when handling load: '*((unsigned int *)"????")'

This issue was originally reported via personal email by Thomas Clement!

Modified:
    cfe/trunk/lib/Analysis/RegionStore.cpp
    cfe/trunk/test/Analysis/misc-ps-region-store.m

Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=83069&r1=83068&r2=83069&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Tue Sep 29 11:36:48 2009
@@ -1060,6 +1060,13 @@
 
   // Check if the region is an element region of a string literal.
   if (const StringRegion *StrR=dyn_cast<StringRegion>(superR)) {
+    // FIXME: Handle loads from strings where the literal is treated as 
+    // an integer, e.g., *((unsigned int*)"hello")
+    ASTContext &Ctx = getContext();
+    QualType T = StrR->getValueType(Ctx)->getAs<ArrayType>()->getElementType();
+    if (T != Ctx.getCanonicalType(R->getElementType()))
+      return UnknownVal();
+    
     const StringLiteral *Str = StrR->getStringLiteral();
     SVal Idx = R->getIndex();
     if (nonloc::ConcreteInt *CI = dyn_cast<nonloc::ConcreteInt>(&Idx)) {
@@ -1072,7 +1079,7 @@
         return UnknownVal();
       }
       char c = (i == byteLength) ? '\0' : Str->getStrData()[i];
-      return ValMgr.makeIntVal(c, getContext().CharTy);
+      return ValMgr.makeIntVal(c, T);
     }
   }
 

Modified: cfe/trunk/test/Analysis/misc-ps-region-store.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps-region-store.m?rev=83069&r1=83068&r2=83069&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/misc-ps-region-store.m (original)
+++ cfe/trunk/test/Analysis/misc-ps-region-store.m Tue Sep 29 11:36:48 2009
@@ -278,3 +278,12 @@
   return p->z;  // no-warning
 }
 
+// <rdar://problem/7261075> [RegionStore] crash when 
+//   handling load: '*((unsigned int *)"????")'
+int rdar_7261075(void) {
+  unsigned int var = 0;
+  if (var == *((unsigned int *)"????"))
+    return 1;
+  return 0;
+}
+





More information about the cfe-commits mailing list