[llvm-branch-commits] [cfe-branch] r71380 - /cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp

Mike Stump mrs at apple.com
Sat May 9 20:12:44 PDT 2009


Author: mrs
Date: Sat May  9 22:12:43 2009
New Revision: 71380

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

When evaluating pointer arithmetic, if the base location is a symbolic region,
convert it to the first element region.
Also do not assume the array region is typed.

Modified:
    cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp

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=71380&r1=71379&r2=71380&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp Sat May  9 22:12:43 2009
@@ -688,26 +688,24 @@
 }
 
 SVal RegionStoreManager::EvalBinOp(BinaryOperator::Opcode Op, Loc L, NonLoc R) {
-  // Assume the base location is MemRegionVal(ElementRegion).
+  // Assume the base location is MemRegionVal.
   if (!isa<loc::MemRegionVal>(L))
     return UnknownVal();
 
   const MemRegion* MR = cast<loc::MemRegionVal>(L).getRegion();
-  if (isa<SymbolicRegion>(MR))
-    return UnknownVal();
-
-  const TypedRegion* TR = cast<TypedRegion>(MR);
-  const ElementRegion* ER = dyn_cast<ElementRegion>(TR);
-  
-  if (!ER) {
-    // If the region is not element region, create one with index 0. This can
-    // happen in the following example:
-    // char *p = foo();
-    // p += 3;
-    // Note that p binds to a TypedViewRegion(SymbolicRegion).
-    nonloc::ConcreteInt Idx(getBasicVals().getZeroWithPtrWidth(false));
-    ER = MRMgr.getElementRegion(TR->getValueType(getContext()), Idx, TR);
-  }
+  const ElementRegion *ER = 0;
+  // If the operand is a symbolic region, we convert it to the first element
+  // region implicitly.
+  if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(MR)) {
+    // Get symbol's type. It should be a pointer type.
+    SymbolRef Sym = SR->getSymbol();
+    QualType T = Sym->getType(getContext());
+    QualType EleTy = cast<PointerType>(T.getTypePtr())->getPointeeType();
+
+    SVal ZeroIdx = ValMgr.makeZeroArrayIndex();
+    ER = MRMgr.getElementRegion(EleTy, ZeroIdx, SR);
+  } else
+    ER = cast<ElementRegion>(MR);
 
   SVal Idx = ER->getIndex();
 
@@ -726,8 +724,7 @@
                                                            Offset->getValue()));
     SVal NewIdx = Base->EvalBinOp(getBasicVals(), Op, OffConverted);
     const MemRegion* NewER =
-      MRMgr.getElementRegion(ER->getElementType(), NewIdx, 
-                             cast<TypedRegion>(ER->getSuperRegion()));
+      MRMgr.getElementRegion(ER->getElementType(), NewIdx,ER->getSuperRegion());
     return Loc::MakeVal(NewER);
 
   }





More information about the llvm-branch-commits mailing list