diff options
| author | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-06-23 05:23:38 +0000 |
|---|---|---|
| committer | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-06-23 05:23:38 +0000 |
| commit | b7cf95957d170943479f8a132a3439595336ff5b (patch) | |
| tree | aea28846256da42f40922dd4b63e7fa31b730dd5 /clang/lib/Analysis/RegionStore.cpp | |
| parent | c1835955342f7672ee2f03567aa2cc464498ada8 (diff) | |
| download | bcm5719-llvm-b7cf95957d170943479f8a132a3439595336ff5b.tar.gz bcm5719-llvm-b7cf95957d170943479f8a132a3439595336ff5b.zip | |
Instead of setting the default value of the array region, bind the rest of the
array elements to 0 explicitly. Create 0 values with the element type.
llvm-svn: 73946
Diffstat (limited to 'clang/lib/Analysis/RegionStore.cpp')
| -rw-r--r-- | clang/lib/Analysis/RegionStore.cpp | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/clang/lib/Analysis/RegionStore.cpp b/clang/lib/Analysis/RegionStore.cpp index 564ffec6cf9..ff2145e26e0 100644 --- a/clang/lib/Analysis/RegionStore.cpp +++ b/clang/lib/Analysis/RegionStore.cpp @@ -1079,17 +1079,11 @@ const GRState *RegionStoreManager::BindArray(const GRState *state, SVal Init) { QualType T = R->getValueType(getContext()); - assert(T->isArrayType()); - - // When we are binding the whole array, it always has default value 0. - state = state->set<RegionDefaultValue>(R, NonLoc::MakeIntVal(getBasicVals(), - 0, false)); - ConstantArrayType* CAT = cast<ConstantArrayType>(T.getTypePtr()); + QualType ElementTy = CAT->getElementType(); llvm::APSInt Size(CAT->getSize(), false); - llvm::APSInt i = getBasicVals().getValue(0, Size.getBitWidth(), - Size.isUnsigned()); + llvm::APSInt i(llvm::APInt::getNullValue(Size.getBitWidth()), false); // Check if the init expr is a StringLiteral. if (isa<loc::MemRegionVal>(Init)) { @@ -1106,10 +1100,8 @@ const GRState *RegionStoreManager::BindArray(const GRState *state, if (j >= len) break; - SVal Idx = NonLoc::MakeVal(getBasicVals(), i); - ElementRegion* ER = - MRMgr.getElementRegion(cast<ArrayType>(T)->getElementType(), - Idx, R, getContext()); + SVal Idx = ValMgr.makeNonLoc(i); + ElementRegion* ER = MRMgr.getElementRegion(ElementTy, Idx,R,getContext()); SVal V = NonLoc::MakeVal(getBasicVals(), str[j], sizeof(char)*8, true); state = Bind(state, loc::MemRegionVal(ER), V); @@ -1122,14 +1114,12 @@ const GRState *RegionStoreManager::BindArray(const GRState *state, nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); for (; i < Size; ++i, ++VI) { - // The init list might be shorter than the array decl. + // The init list might be shorter than the array length. if (VI == VE) break; - SVal Idx = NonLoc::MakeVal(getBasicVals(), i); - ElementRegion* ER = - MRMgr.getElementRegion(cast<ArrayType>(T)->getElementType(), - Idx, R, getContext()); + SVal Idx = ValMgr.makeNonLoc(i); + ElementRegion* ER = MRMgr.getElementRegion(ElementTy, Idx, R, getContext()); if (CAT->getElementType()->isStructureType()) state = BindStruct(state, ER, *VI); @@ -1137,6 +1127,18 @@ const GRState *RegionStoreManager::BindArray(const GRState *state, state = Bind(state, Loc::MakeVal(ER), *VI); } + // If the init list is shorter than the array length, bind the rest elements + // to 0. + if (ElementTy->isIntegerType()) { + while (i < Size) { + SVal Idx = ValMgr.makeNonLoc(i); + ElementRegion* ER = MRMgr.getElementRegion(ElementTy, Idx,R,getContext()); + SVal V = ValMgr.makeZeroVal(ElementTy); + state = Bind(state, Loc::MakeVal(ER), V); + ++i; + } + } + return state; } |

