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

Ted Kremenek kremenek at apple.com
Wed Jul 1 16:19:52 PDT 2009


Author: kremenek
Date: Wed Jul  1 18:19:52 2009
New Revision: 74660

URL: http://llvm.org/viewvc/llvm-project?rev=74660&view=rev
Log:
Add a FIXME to RegionStore, do some minor code cleanup, and get RegionStore to
pass misc-ps.m. Currently RegionStore/BasicStore don't do any special reasoning
about clang-style vectors, so we should return UnknownVal (in all cases) when
accessing their values via an array.

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

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

==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Wed Jul  1 18:19:52 2009
@@ -918,12 +918,13 @@
                                          const ElementRegion* R) {
   // Check if the region has a binding.
   RegionBindingsTy B = GetRegionBindings(state->getStore());
-  const SVal* V = B.lookup(R);
-  if (V)
+  if (const SVal* V = B.lookup(R))
     return *V;
 
+  const MemRegion* superR = R->getSuperRegion();
+
   // Check if the region is an element region of a string literal.
-  if (const StringRegion *StrR=dyn_cast<StringRegion>(R->getSuperRegion())) {
+  if (const StringRegion *StrR=dyn_cast<StringRegion>(superR)) {
     const StringLiteral *Str = StrR->getStringLiteral();
     SVal Idx = R->getIndex();
     if (nonloc::ConcreteInt *CI = dyn_cast<nonloc::ConcreteInt>(&Idx)) {
@@ -937,12 +938,8 @@
     }
   }
 
-  const MemRegion* SuperR = R->getSuperRegion();
-
   // Check if the super region has a default value.
-  const SVal* D = state->get<RegionDefaultValue>(SuperR);
-
-  if (D) {
+  if (const SVal *D = state->get<RegionDefaultValue>(superR)) {
     if (D->hasConjuredSymbol())
       return ValMgr.getRegionValueSymbolVal(R);
     else
@@ -950,14 +947,29 @@
   }
 
   // Check if the super region has a binding.
-  D = B.lookup(SuperR);
-  if (D) {
+  if (B.lookup(superR)) {
     // We do not extract the bit value from super region for now.
     return ValMgr.makeUnknownVal();
   }
+  
+  if (R->hasHeapStorage()) {
+    // FIXME: If the region has heap storage and we know nothing special
+    // about its bindings, should we instead return UnknownVal?  Seems like
+    // we should only return UndefinedVal in the cases where we know the value
+    // will be undefined.
+    return UndefinedVal();
+  }
+
+  if (R->hasStackStorage()) {
+    // Currently we don't reason specially about Clang-style vectors.  Check
+    // if superR is a vector and if so return Unknown.
+    if (const TypedRegion *typedSuperR = dyn_cast<TypedRegion>(superR)) {
+      if (typedSuperR->getValueType(getContext())->isVectorType())
+        return UnknownVal();
+    }
 
-  if (R->hasHeapOrStackStorage())
     return UndefinedVal();
+  }
 
   QualType Ty = R->getValueType(getContext());
 

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

==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Wed Jul  1 18:19:52 2009
@@ -1,8 +1,7 @@
 // RUN: clang-cc -analyze -checker-cfref --analyzer-store=basic -analyzer-constraints=basic --verify -fblocks %s &&
-// RUN: clang-cc -analyze -checker-cfref --analyzer-store=basic -analyzer-constraints=range --verify -fblocks %s
-
-// NOWORK: clang-cc -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=basic --verify -fblocks %s &&
-// NOWORK: clang-cc -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=range --verify -fblocks %s
+// RUN: clang-cc -analyze -checker-cfref --analyzer-store=basic -analyzer-constraints=range --verify -fblocks %s &&
+// RUN: clang-cc -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=basic --verify -fblocks %s &&
+// RUN: clang-cc -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=range --verify -fblocks %s
 
 typedef struct objc_selector *SEL;
 typedef signed char BOOL;





More information about the cfe-commits mailing list