diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-07-06 22:23:45 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-07-06 22:23:45 +0000 |
commit | c5ab3a0eabda7f35cf5e6d25e27f558ccf59ba12 (patch) | |
tree | 00e0a2d17a724722cf1471980251944da2934b54 /clang/lib/Analysis/Store.cpp | |
parent | e63b0e6f79302826b863a8f5cc949f60e914dd44 (diff) | |
download | bcm5719-llvm-c5ab3a0eabda7f35cf5e6d25e27f558ccf59ba12.tar.gz bcm5719-llvm-c5ab3a0eabda7f35cf5e6d25e27f558ccf59ba12.zip |
StoreManager::NewCastRegion:
- Refactor logic that creates ElementRegions into a help method 'MakeElementRegion'.
- Fix crash due to not handling StringRegions. Casts of StringRegions now
result in a new ElementRegion layered on the original StringRegion.
llvm-svn: 74867
Diffstat (limited to 'clang/lib/Analysis/Store.cpp')
-rw-r--r-- | clang/lib/Analysis/Store.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/clang/lib/Analysis/Store.cpp b/clang/lib/Analysis/Store.cpp index cd123995faa..08db2c565f3 100644 --- a/clang/lib/Analysis/Store.cpp +++ b/clang/lib/Analysis/Store.cpp @@ -23,6 +23,19 @@ StoreManager::StoreManager(GRStateManager &stateMgr, bool useNewCastRegion) MRMgr(ValMgr.getRegionManager()) {} StoreManager::CastResult +StoreManager::MakeElementRegion(const GRState *state, const MemRegion *region, + QualType pointeeTy, QualType castToTy) { + + // Record the cast type of the region. + state = setCastType(state, region, castToTy); + + // Create a new ElementRegion at offset 0. + SVal idx = ValMgr.makeZeroArrayIndex(); + return CastResult(state, MRMgr.getElementRegion(pointeeTy, idx, region, + ValMgr.getContext())); +} + +StoreManager::CastResult StoreManager::NewCastRegion(const GRState *state, const MemRegion* R, QualType CastToTy) { @@ -38,19 +51,23 @@ StoreManager::NewCastRegion(const GRState *state, const MemRegion* R, && CastToTy->getAsPointerType()->getPointeeType()->isVoidType())); return CastResult(state, R); } - + // Check cast to ObjCQualifiedID type. if (ToTy->isObjCQualifiedIdType()) { // FIXME: Record the type information aside. return CastResult(state, R); } - + // Now assume we are casting from pointer to pointer. Other cases should // already be handled. QualType PointeeTy = cast<PointerType>(ToTy.getTypePtr())->getPointeeType(); - + // Process region cast according to the kind of the region being cast. + // Handle casts of string literals. + if (isa<StringRegion>(R)) + return MakeElementRegion(state, R, PointeeTy, ToTy); + // FIXME: Need to handle arbitrary downcasts. if (isa<SymbolicRegion>(R) || isa<AllocaRegion>(R)) { state = setCastType(state, R, ToTy); @@ -77,13 +94,8 @@ StoreManager::NewCastRegion(const GRState *state, const MemRegion* R, if ((PointeeTySize > 0 && PointeeTySize < ObjTySize) || (ObjTy->isAggregateType() && PointeeTy->isScalarType()) || - ObjTySize == 0 /* R has 'void*' type. */) { - // Record the cast type of the region. - state = setCastType(state, R, ToTy); - - SVal Idx = ValMgr.makeZeroArrayIndex(); - ElementRegion* ER = MRMgr.getElementRegion(PointeeTy, Idx,R, Ctx); - return CastResult(state, ER); + ObjTySize == 0 /* R has 'void*' type. */) { + return MakeElementRegion(state, R, PointeeTy, ToTy); } else { state = setCastType(state, R, ToTy); return CastResult(state, R); |