diff options
author | Jordy Rose <jediknil@belkadan.com> | 2010-06-25 23:23:04 +0000 |
---|---|---|
committer | Jordy Rose <jediknil@belkadan.com> | 2010-06-25 23:23:04 +0000 |
commit | c3bcc36a0bdb87ec56ec77da88a7ce8eb5051a81 (patch) | |
tree | cbf123e9151b54851215b09fa2fbd604fcba4671 /clang/lib/Checker/RegionStore.cpp | |
parent | f94c8c2bf94b81788f25b941ff39a30dec92e673 (diff) | |
download | bcm5719-llvm-c3bcc36a0bdb87ec56ec77da88a7ce8eb5051a81.tar.gz bcm5719-llvm-c3bcc36a0bdb87ec56ec77da88a7ce8eb5051a81.zip |
When a constant size array is casted to another type, its length should be scaled as well.
llvm-svn: 106911
Diffstat (limited to 'clang/lib/Checker/RegionStore.cpp')
-rw-r--r-- | clang/lib/Checker/RegionStore.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/clang/lib/Checker/RegionStore.cpp b/clang/lib/Checker/RegionStore.cpp index f7a0188a531..6b5e5e33f2d 100644 --- a/clang/lib/Checker/RegionStore.cpp +++ b/clang/lib/Checker/RegionStore.cpp @@ -797,23 +797,28 @@ DefinedOrUnknownSVal RegionStoreManager::getSizeInElements(const GRState *state, case MemRegion::VarRegionKind: { const VarRegion* VR = cast<VarRegion>(R); + ASTContext& Ctx = getContext(); // Get the type of the variable. - QualType T = VR->getDesugaredValueType(getContext()); + QualType T = VR->getDesugaredValueType(Ctx); // FIXME: Handle variable-length arrays. if (isa<VariableArrayType>(T)) return UnknownVal(); + CharUnits EleSize = Ctx.getTypeSizeInChars(EleTy); + if (const ConstantArrayType* CAT = dyn_cast<ConstantArrayType>(T)) { // return the size as signed integer. - return ValMgr.makeIntVal(CAT->getSize(), false); + CharUnits RealEleSize = Ctx.getTypeSizeInChars(CAT->getElementType()); + CharUnits::QuantityType EleRatio = RealEleSize / EleSize; + int64_t Length = CAT->getSize().getSExtValue(); + return ValMgr.makeIntVal(Length * EleRatio, false); } // Clients can reinterpret ordinary variables as arrays, possibly of // another type. The width is rounded down to ensure that an access is // entirely within bounds. - CharUnits VarSize = getContext().getTypeSizeInChars(T); - CharUnits EleSize = getContext().getTypeSizeInChars(EleTy); + CharUnits VarSize = Ctx.getTypeSizeInChars(T); return ValMgr.makeIntVal(VarSize / EleSize, false); } } |