2009/6/24 Ted Kremenek <[email protected]>: > Hi Zhongxing, > > Is this approach going to scale? For even moderate sized arrays this seems > like it is going to result in a bunch of excess storage. For large arrays > this might not scale at all. Was there some particular motivation behind > this change?
I was to make the array case consistent with the struct case. But now I realized that for the array case we can use the uniform default value safely. I'll revert to that approach. > > Ted > > On Jun 22, 2009, at 10:23 PM, Zhongxing Xu wrote: > >> Author: zhongxingxu >> Date: Tue Jun 23 00:23:38 2009 >> New Revision: 73946 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=73946&view=rev >> Log: >> 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. >> >> Modified: >> cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h >> cfe/trunk/lib/Analysis/RegionStore.cpp >> cfe/trunk/lib/Analysis/SVals.cpp >> >> Modified: cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h?rev=73946&r1=73945&r2=73946&view=diff >> >> >> ============================================================================== >> --- cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h >> (original) >> +++ cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h Tue Jun >> 23 00:23:38 2009 >> @@ -89,6 +89,8 @@ >> SVal getFunctionPointer(const FunctionDecl* FD); >> >> NonLoc makeNonLoc(SymbolRef sym); >> + >> + NonLoc makeNonLoc(const llvm::APSInt& V); >> >> NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op, >> const llvm::APSInt& rhs, QualType T); >> >> Modified: cfe/trunk/lib/Analysis/RegionStore.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=73946&r1=73945&r2=73946&view=diff >> >> >> ============================================================================== >> --- cfe/trunk/lib/Analysis/RegionStore.cpp (original) >> +++ cfe/trunk/lib/Analysis/RegionStore.cpp Tue Jun 23 00:23:38 2009 >> @@ -1079,17 +1079,11 @@ >> 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 @@ >> 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 @@ >> 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 @@ >> 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; >> } >> >> >> Modified: cfe/trunk/lib/Analysis/SVals.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/SVals.cpp?rev=73946&r1=73945&r2=73946&view=diff >> >> >> ============================================================================== >> --- cfe/trunk/lib/Analysis/SVals.cpp (original) >> +++ cfe/trunk/lib/Analysis/SVals.cpp Tue Jun 23 00:23:38 2009 >> @@ -264,6 +264,10 @@ >> return nonloc::SymbolVal(sym); >> } >> >> +NonLoc ValueManager::makeNonLoc(const APSInt& V) { >> + return nonloc::ConcreteInt(BasicVals.getValue(V)); >> +} >> + >> NonLoc ValueManager::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode >> op, >> const APSInt& v, QualType T) { >> // The Environment ensures we always get a persistent APSInt in >> >> >> _______________________________________________ >> cfe-commits mailing list >> [email protected] >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > > _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
