// Turn all [A, B] ranges to [-B, -A]. Ranges [MIN, B] are turned to range set // [MIN, MIN] U [-B, MAX], when MIN and MAX are the minimal and the maximal // signed values of the type. RangeSet RangeSet::Negate(BasicValueFactory &BV, Factory &F) const { PrimRangeSet newRanges = F.getEmptySet(); for (iterator i = begin(), e = end(); i != e; ++i) { const llvm::APSInt &from = i->From(), &to = i->To(); const llvm::APSInt &newTo = (from.isMinSignedValue() ? BV.getMaxValue(from) : BV.getValue(- from)); if (to.isMaxSignedValue() && !newRanges.isEmpty() && newRanges.begin()->From().isMinSignedValue()) { assert(newRanges.begin()->To().isMinSignedValue() && "Ranges should not overlap"); assert(!from.isMinSignedValue() && "Ranges should not overlap"); const llvm::APSInt &newFrom = newRanges.begin()->From(); newRanges = F.add(F.remove(newRanges, *newRanges.begin()), Range(newFrom, newTo)); } else if (!to.isMinSignedValue()) { const llvm::APSInt &newFrom = BV.getValue(- to); newRanges = F.add(newRanges, Range(newFrom, newTo)); } if (from.isMinSignedValue()) { newRanges = F.add(newRanges, Range(BV.getMinValue(from), BV.getMinValue(from))); } } return newRanges; }
void RangeSet::IntersectInRange(BasicValueFactory &BV, Factory &F, const llvm::APSInt &Lower, const llvm::APSInt &Upper, PrimRangeSet &newRanges, PrimRangeSet::iterator &i, PrimRangeSet::iterator &e) const { // There are six cases for each range R in the set: // 1. R is entirely before the intersection range. // 2. R is entirely after the intersection range. // 3. R contains the entire intersection range. // 4. R starts before the intersection range and ends in the middle. // 5. R starts in the middle of the intersection range and ends after it. // 6. R is entirely contained in the intersection range. // These correspond to each of the conditions below. for (/* i = begin(), e = end() */; i != e; ++i) { if (i->To() < Lower) { continue; } if (i->From() > Upper) { break; } if (i->Includes(Lower)) { if (i->Includes(Upper)) { newRanges = F.add(newRanges, Range(BV.getValue(Lower), BV.getValue(Upper))); break; } else newRanges = F.add(newRanges, Range(BV.getValue(Lower), i->To())); } else { if (i->Includes(Upper)) { newRanges = F.add(newRanges, Range(i->From(), BV.getValue(Upper))); break; } else newRanges = F.add(newRanges, *i); } } }
NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, const llvm::APInt& I, bool isUnsigned) { return nonloc::ConcreteInt(BasicVals.getValue(I, isUnsigned)); }
NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, const llvm::APSInt& I) { return nonloc::ConcreteInt(BasicVals.getValue(I)); }
NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, IntegerLiteral* I) { return nonloc::ConcreteInt(BasicVals.getValue(APSInt(I->getValue(), I->getType()->isUnsignedIntegerType()))); }
NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, uint64_t X, QualType T) { return nonloc::ConcreteInt(BasicVals.getValue(X, T)); }
NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, uint64_t X, unsigned BitWidth, bool isUnsigned) { return nonloc::ConcreteInt(BasicVals.getValue(X, BitWidth, isUnsigned)); }
nonloc::ConcreteInt nonloc::ConcreteInt::EvalMinus(BasicValueFactory& BasicVals, UnaryOperator* U) const { assert (U->getType() == U->getSubExpr()->getType()); assert (U->getType()->isIntegerType()); return BasicVals.getValue(-getValue()); }
nonloc::ConcreteInt nonloc::ConcreteInt::EvalComplement(BasicValueFactory& BasicVals) const { return BasicVals.getValue(~getValue()); }