summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2008-11-13 07:58:20 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2008-11-13 07:58:20 +0000
commit0dbeeaa886733e454531705ca17d0e8445dd529a (patch)
tree40e141f8281955e0199f99b1c42517b99258709e /clang/lib
parent4af89f7e7dd90fca4c63800e90e043c8fd0260fb (diff)
downloadbcm5719-llvm-0dbeeaa886733e454531705ca17d0e8445dd529a.tar.gz
bcm5719-llvm-0dbeeaa886733e454531705ca17d0e8445dd529a.zip
Lift the pointer to alloca'ed region to the pointer to its first element.
This is required by some operations, e.g., *p = 1; p[0] = 1;. Also set the AllocaRegion's type during the cast. llvm-svn: 59232
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Analysis/GRExprEngine.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/clang/lib/Analysis/GRExprEngine.cpp b/clang/lib/Analysis/GRExprEngine.cpp
index 5ef2524964b..76e356be4d3 100644
--- a/clang/lib/Analysis/GRExprEngine.cpp
+++ b/clang/lib/Analysis/GRExprEngine.cpp
@@ -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())));
}
OpenPOWER on IntegriCloud