From: Zhongxing Xu Date: Thu, 13 Nov 2008 09:15:14 +0000 (+0000) Subject: Array index might be unsigned. We have to generate a temporary signed value for X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cc0d0ec3a8d567f8b3fb70da177e38fe89efbc10;p=clang Array index might be unsigned. We have to generate a temporary signed value for it to be evaluated by APSInt::operators. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59238 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 562d584558..ec5acf57f4 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -197,6 +197,18 @@ SVal RegionStoreManager::getLValueElement(const GRState* St, // Only handle integer indices for now. if ((CI1 = dyn_cast(&Idx)) && (CI2 = dyn_cast(&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(&SignedInt); + } + SVal NewIdx = CI1->EvalBinOp(StateMgr.getBasicVals(), BinaryOperator::Add, *CI2); return loc::MemRegionVal(MRMgr.getElementRegion(NewIdx,