]> granicus.if.org Git - clang/commitdiff
Lift the pointer to alloca'ed region to the pointer to its first element.
authorZhongxing Xu <xuzhongxing@gmail.com>
Thu, 13 Nov 2008 07:58:20 +0000 (07:58 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Thu, 13 Nov 2008 07:58:20 +0000 (07:58 +0000)
This is required by some operations, e.g., *p = 1; p[0] = 1;.
Also set the AllocaRegion's type during the cast.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59232 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/GRExprEngine.cpp

index 5ef2524964bf6322b5cd7e76f6062c96e31ee2b6..76e356be4d3dec5418b6a5dac76df8246be510b3 100644 (file)
@@ -1277,7 +1277,7 @@ void GRExprEngine::VisitCallRec(CallExpr* CE, NodeTy* Pred,
             // FIXME: Refactor into StoreManager itself?
             MemRegionManager& RM = getStateManager().getRegionManager();
             const MemRegion* R =
-              RM.getAllocaRegion(CE, Builder->getCurrentBlockCount());            
+              RM.getAllocaRegion(CE, Builder->getCurrentBlockCount());
             MakeNode(Dst, CE, *DI, BindExpr(St, CE, loc::MemRegionVal(R)));
             continue;            
           }
@@ -1681,6 +1681,26 @@ void GRExprEngine::VisitCast(Expr* CastE, Expr* Ex, NodeTy* Pred, NodeSet& Dst){
       continue;
     }
 
+    // Cast alloca'ed pointer to typed pointer.
+    if (isa<loc::MemRegionVal>(V)) {
+      if (const AllocaRegion* AR = 
+          dyn_cast<AllocaRegion>(cast<loc::MemRegionVal>(V).getRegion())) {
+
+        // Set the AllocaRegion's type.
+        const_cast<AllocaRegion*>(AR)->setType(T);
+
+        // Set the CastExpr's value to a pointer to the first element.
+        MemRegionManager& RM = getStateManager().getRegionManager();
+
+        llvm::APSInt Zero(llvm::APInt::getNullValue(32), false);
+        SVal ZeroIdx(nonloc::ConcreteInt(getBasicVals().getValue(Zero)));
+        const ElementRegion* ER = RM.getElementRegion(ZeroIdx, AR);
+
+        MakeNode(Dst, CastE, N, BindExpr(St, CastE, loc::MemRegionVal(ER)));
+        continue;
+      }
+    }
+
     // All other cases.
     MakeNode(Dst, CastE, N, BindExpr(St, CastE, EvalCast(V, CastE->getType())));
   }