diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-07-06 23:47:19 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-07-06 23:47:19 +0000 |
commit | 169077dde4d91270a7495793f1e00b22aa0bc7ca (patch) | |
tree | b280151da70a25983ace6d50f6a78b025db5871d /lib/Analysis/Store.cpp | |
parent | db5f266be075aba0f4ca1690e358245a726c9c61 (diff) |
NewCastRegion: Handle casts *from* pointers to incomplete structs to other types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74884 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/Store.cpp')
-rw-r--r-- | lib/Analysis/Store.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/Analysis/Store.cpp b/lib/Analysis/Store.cpp index 4ca0208522..bc5d6c25a9 100644 --- a/lib/Analysis/Store.cpp +++ b/lib/Analysis/Store.cpp @@ -35,6 +35,16 @@ StoreManager::MakeElementRegion(const GRState *state, const MemRegion *region, ValMgr.getContext())); } +static bool IsCompleteType(ASTContext &Ctx, QualType Ty) { + if (const RecordType *RT = Ty->getAsRecordType()) { + const RecordDecl *D = RT->getDecl(); + if (!D->getDefinition(Ctx)) + return false; + } + + return true; +} + StoreManager::CastResult StoreManager::NewCastRegion(const GRState *state, const MemRegion* R, QualType CastToTy) { @@ -53,7 +63,7 @@ StoreManager::NewCastRegion(const GRState *state, const MemRegion* R, // Now assume we are casting from pointer to pointer. Other cases should // already be handled. QualType PointeeTy = CastToTy->getAsPointerType()->getPointeeType(); - + // Process region cast according to the kind of the region being cast. switch (R->getKind()) { case MemRegion::BEG_TYPED_REGIONS: @@ -96,15 +106,15 @@ StoreManager::NewCastRegion(const GRState *state, const MemRegion* R, // the cast-to pointee type is of smaller size. In other cases, we return // the original VarRegion. - // If the pointee type is incomplete, do not compute its size, and return - // the original region. - if (const RecordType *RT = PointeeTy->getAsRecordType()) { - const RecordDecl *D = RT->getDecl(); - if (!D->getDefinition(Ctx)) - return CastResult(state, R); - } - + // If the pointee or object type is incomplete, do compute their sizes, + // and return the original region. QualType ObjTy = cast<TypedRegion>(R)->getValueType(Ctx); + + if (!IsCompleteType(Ctx, PointeeTy) || !IsCompleteType(Ctx, ObjTy)) { + state = setCastType(state, R, ToTy); + break; + } + uint64_t PointeeTySize = Ctx.getTypeSize(PointeeTy); uint64_t ObjTySize = Ctx.getTypeSize(ObjTy); |