Array index might be unsigned. We have to generate a temporary signed value for

it to be evaluated by APSInt::operators.

llvm-svn: 59238
This commit is contained in:
Zhongxing Xu 2008-11-13 09:15:14 +00:00
parent 9182147f17
commit 189a30796a
1 changed files with 12 additions and 0 deletions

View File

@ -197,6 +197,18 @@ SVal RegionStoreManager::getLValueElement(const GRState* St,
// Only handle integer indices for now.
if ((CI1 = dyn_cast<nonloc::ConcreteInt>(&Idx)) &&
(CI2 = dyn_cast<nonloc::ConcreteInt>(&Offset))) {
// Temporary SVal to hold a potential signed APSInt.
SVal SignedInt;
// Index might be unsigned. We have to convert it to signed.
if (CI2->getValue().isUnsigned()) {
llvm::APSInt SI = CI2->getValue();
SI.setIsSigned(true);
SignedInt = nonloc::ConcreteInt(getBasicVals().getValue(SI));
CI2 = cast<nonloc::ConcreteInt>(&SignedInt);
}
SVal NewIdx = CI1->EvalBinOp(StateMgr.getBasicVals(), BinaryOperator::Add,
*CI2);
return loc::MemRegionVal(MRMgr.getElementRegion(NewIdx,