From: Zhongxing Xu Date: Wed, 6 May 2009 08:08:27 +0000 (+0000) Subject: Implement a heuristic type size comparison method for now. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ccb161603c3c280c378e6701986e9f3646898277;p=clang Implement a heuristic type size comparison method for now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71074 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 145559e8b8..5f8e6c3f92 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -554,6 +554,10 @@ SVal RegionStoreManager::getSizeInElements(const GRState* St, return UnknownVal(); } + if (isa(R)) { + return UnknownVal(); + } + assert(0 && "Other regions are not supported yet."); return UnknownVal(); } @@ -585,6 +589,13 @@ SVal RegionStoreManager::ArrayToPointer(Loc Array) { return loc::MemRegionVal(ER); } +static bool isSmallerThan(QualType T1, QualType T2) { + if (T1->isCharType()) + return true; + else + return false; +} + RegionStoreManager::CastResult RegionStoreManager::CastRegion(const GRState* state, const MemRegion* R, QualType CastToTy) { @@ -637,9 +648,14 @@ RegionStoreManager::CastRegion(const GRState* state, const MemRegion* R, // VarRegion. if (isa(R) || isa(R) || isa(R) || isa(R) || isa(R)) { - // FIXME: create an ElementRegion when the size of the pointee type is - // smaller than the region. - return CastResult(state, R); + if (isSmallerThan(PointeeTy, + cast(R)->getRValueType(getContext()))) { + SVal Idx = ValMgr.makeZeroArrayIndex(); + ElementRegion* ER = MRMgr.getElementRegion(PointeeTy, Idx, + cast(R)); + return CastResult(state, ER); + } else + return CastResult(state, R); } if (isa(R)) { diff --git a/test/Analysis/rdar-6541136-region.c b/test/Analysis/rdar-6541136-region.c index 59ee313f45..1e7a2d974b 100644 --- a/test/Analysis/rdar-6541136-region.c +++ b/test/Analysis/rdar-6541136-region.c @@ -13,5 +13,7 @@ void foo( void ) struct load_wine *cmd = (void*) &wonky[1]; cmd = cmd; char *p = (void*) &wonky[1]; - *p = 1; // expected-warning{{Load or store into an out-of-bound memory}} + *p = 1; + kernel_tea_cheese_t *q = &wonky[1]; + kernel_tea_cheese_t r = *q; // expected-warning{{out-of-bound memory position}} }