RangeConstraintManager.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. //== RangeConstraintManager.cpp - Manage range constraints.------*- C++ -*--==//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines RangeConstraintManager, a class that tracks simple
  11. // equality and inequality constraints on symbolic values of ProgramState.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "SimpleConstraintManager.h"
  15. #include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
  16. #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
  17. #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
  18. #include "llvm/ADT/FoldingSet.h"
  19. #include "llvm/ADT/ImmutableSet.h"
  20. #include "llvm/Support/Debug.h"
  21. #include "llvm/Support/raw_ostream.h"
  22. using namespace clang;
  23. using namespace ento;
  24. /// A Range represents the closed range [from, to]. The caller must
  25. /// guarantee that from <= to. Note that Range is immutable, so as not
  26. /// to subvert RangeSet's immutability.
  27. namespace {
  28. class Range : public std::pair<const llvm::APSInt*,
  29. const llvm::APSInt*> {
  30. public:
  31. Range(const llvm::APSInt &from, const llvm::APSInt &to)
  32. : std::pair<const llvm::APSInt*, const llvm::APSInt*>(&from, &to) {
  33. assert(from <= to);
  34. }
  35. bool Includes(const llvm::APSInt &v) const {
  36. return *first <= v && v <= *second;
  37. }
  38. const llvm::APSInt &From() const {
  39. return *first;
  40. }
  41. const llvm::APSInt &To() const {
  42. return *second;
  43. }
  44. const llvm::APSInt *getConcreteValue() const {
  45. return &From() == &To() ? &From() : nullptr;
  46. }
  47. void Profile(llvm::FoldingSetNodeID &ID) const {
  48. ID.AddPointer(&From());
  49. ID.AddPointer(&To());
  50. }
  51. };
  52. class RangeTrait : public llvm::ImutContainerInfo<Range> {
  53. public:
  54. // When comparing if one Range is less than another, we should compare
  55. // the actual APSInt values instead of their pointers. This keeps the order
  56. // consistent (instead of comparing by pointer values) and can potentially
  57. // be used to speed up some of the operations in RangeSet.
  58. static inline bool isLess(key_type_ref lhs, key_type_ref rhs) {
  59. return *lhs.first < *rhs.first || (!(*rhs.first < *lhs.first) &&
  60. *lhs.second < *rhs.second);
  61. }
  62. };
  63. /// RangeSet contains a set of ranges. If the set is empty, then
  64. /// there the value of a symbol is overly constrained and there are no
  65. /// possible values for that symbol.
  66. class RangeSet {
  67. typedef llvm::ImmutableSet<Range, RangeTrait> PrimRangeSet;
  68. PrimRangeSet ranges; // no need to make const, since it is an
  69. // ImmutableSet - this allows default operator=
  70. // to work.
  71. public:
  72. typedef PrimRangeSet::Factory Factory;
  73. typedef PrimRangeSet::iterator iterator;
  74. RangeSet(PrimRangeSet RS) : ranges(RS) {}
  75. iterator begin() const { return ranges.begin(); }
  76. iterator end() const { return ranges.end(); }
  77. bool isEmpty() const { return ranges.isEmpty(); }
  78. /// Construct a new RangeSet representing '{ [from, to] }'.
  79. RangeSet(Factory &F, const llvm::APSInt &from, const llvm::APSInt &to)
  80. : ranges(F.add(F.getEmptySet(), Range(from, to))) {}
  81. /// Profile - Generates a hash profile of this RangeSet for use
  82. /// by FoldingSet.
  83. void Profile(llvm::FoldingSetNodeID &ID) const { ranges.Profile(ID); }
  84. /// getConcreteValue - If a symbol is contrained to equal a specific integer
  85. /// constant then this method returns that value. Otherwise, it returns
  86. /// NULL.
  87. const llvm::APSInt* getConcreteValue() const {
  88. return ranges.isSingleton() ? ranges.begin()->getConcreteValue() : nullptr;
  89. }
  90. private:
  91. void IntersectInRange(BasicValueFactory &BV, Factory &F,
  92. const llvm::APSInt &Lower,
  93. const llvm::APSInt &Upper,
  94. PrimRangeSet &newRanges,
  95. PrimRangeSet::iterator &i,
  96. PrimRangeSet::iterator &e) const {
  97. // There are six cases for each range R in the set:
  98. // 1. R is entirely before the intersection range.
  99. // 2. R is entirely after the intersection range.
  100. // 3. R contains the entire intersection range.
  101. // 4. R starts before the intersection range and ends in the middle.
  102. // 5. R starts in the middle of the intersection range and ends after it.
  103. // 6. R is entirely contained in the intersection range.
  104. // These correspond to each of the conditions below.
  105. for (/* i = begin(), e = end() */; i != e; ++i) {
  106. if (i->To() < Lower) {
  107. continue;
  108. }
  109. if (i->From() > Upper) {
  110. break;
  111. }
  112. if (i->Includes(Lower)) {
  113. if (i->Includes(Upper)) {
  114. newRanges = F.add(newRanges, Range(BV.getValue(Lower),
  115. BV.getValue(Upper)));
  116. break;
  117. } else
  118. newRanges = F.add(newRanges, Range(BV.getValue(Lower), i->To()));
  119. } else {
  120. if (i->Includes(Upper)) {
  121. newRanges = F.add(newRanges, Range(i->From(), BV.getValue(Upper)));
  122. break;
  123. } else
  124. newRanges = F.add(newRanges, *i);
  125. }
  126. }
  127. }
  128. const llvm::APSInt &getMinValue() const {
  129. assert(!isEmpty());
  130. return ranges.begin()->From();
  131. }
  132. bool pin(llvm::APSInt &Lower, llvm::APSInt &Upper) const {
  133. // This function has nine cases, the cartesian product of range-testing
  134. // both the upper and lower bounds against the symbol's type.
  135. // Each case requires a different pinning operation.
  136. // The function returns false if the described range is entirely outside
  137. // the range of values for the associated symbol.
  138. APSIntType Type(getMinValue());
  139. APSIntType::RangeTestResultKind LowerTest = Type.testInRange(Lower, true);
  140. APSIntType::RangeTestResultKind UpperTest = Type.testInRange(Upper, true);
  141. switch (LowerTest) {
  142. case APSIntType::RTR_Below:
  143. switch (UpperTest) {
  144. case APSIntType::RTR_Below:
  145. // The entire range is outside the symbol's set of possible values.
  146. // If this is a conventionally-ordered range, the state is infeasible.
  147. if (Lower < Upper)
  148. return false;
  149. // However, if the range wraps around, it spans all possible values.
  150. Lower = Type.getMinValue();
  151. Upper = Type.getMaxValue();
  152. break;
  153. case APSIntType::RTR_Within:
  154. // The range starts below what's possible but ends within it. Pin.
  155. Lower = Type.getMinValue();
  156. Type.apply(Upper);
  157. break;
  158. case APSIntType::RTR_Above:
  159. // The range spans all possible values for the symbol. Pin.
  160. Lower = Type.getMinValue();
  161. Upper = Type.getMaxValue();
  162. break;
  163. }
  164. break;
  165. case APSIntType::RTR_Within:
  166. switch (UpperTest) {
  167. case APSIntType::RTR_Below:
  168. // The range wraps around, but all lower values are not possible.
  169. Type.apply(Lower);
  170. Upper = Type.getMaxValue();
  171. break;
  172. case APSIntType::RTR_Within:
  173. // The range may or may not wrap around, but both limits are valid.
  174. Type.apply(Lower);
  175. Type.apply(Upper);
  176. break;
  177. case APSIntType::RTR_Above:
  178. // The range starts within what's possible but ends above it. Pin.
  179. Type.apply(Lower);
  180. Upper = Type.getMaxValue();
  181. break;
  182. }
  183. break;
  184. case APSIntType::RTR_Above:
  185. switch (UpperTest) {
  186. case APSIntType::RTR_Below:
  187. // The range wraps but is outside the symbol's set of possible values.
  188. return false;
  189. case APSIntType::RTR_Within:
  190. // The range starts above what's possible but ends within it (wrap).
  191. Lower = Type.getMinValue();
  192. Type.apply(Upper);
  193. break;
  194. case APSIntType::RTR_Above:
  195. // The entire range is outside the symbol's set of possible values.
  196. // If this is a conventionally-ordered range, the state is infeasible.
  197. if (Lower < Upper)
  198. return false;
  199. // However, if the range wraps around, it spans all possible values.
  200. Lower = Type.getMinValue();
  201. Upper = Type.getMaxValue();
  202. break;
  203. }
  204. break;
  205. }
  206. return true;
  207. }
  208. public:
  209. // Returns a set containing the values in the receiving set, intersected with
  210. // the closed range [Lower, Upper]. Unlike the Range type, this range uses
  211. // modular arithmetic, corresponding to the common treatment of C integer
  212. // overflow. Thus, if the Lower bound is greater than the Upper bound, the
  213. // range is taken to wrap around. This is equivalent to taking the
  214. // intersection with the two ranges [Min, Upper] and [Lower, Max],
  215. // or, alternatively, /removing/ all integers between Upper and Lower.
  216. RangeSet Intersect(BasicValueFactory &BV, Factory &F,
  217. llvm::APSInt Lower, llvm::APSInt Upper) const {
  218. if (!pin(Lower, Upper))
  219. return F.getEmptySet();
  220. PrimRangeSet newRanges = F.getEmptySet();
  221. PrimRangeSet::iterator i = begin(), e = end();
  222. if (Lower <= Upper)
  223. IntersectInRange(BV, F, Lower, Upper, newRanges, i, e);
  224. else {
  225. // The order of the next two statements is important!
  226. // IntersectInRange() does not reset the iteration state for i and e.
  227. // Therefore, the lower range most be handled first.
  228. IntersectInRange(BV, F, BV.getMinValue(Upper), Upper, newRanges, i, e);
  229. IntersectInRange(BV, F, Lower, BV.getMaxValue(Lower), newRanges, i, e);
  230. }
  231. return newRanges;
  232. }
  233. void print(raw_ostream &os) const {
  234. bool isFirst = true;
  235. os << "{ ";
  236. for (iterator i = begin(), e = end(); i != e; ++i) {
  237. if (isFirst)
  238. isFirst = false;
  239. else
  240. os << ", ";
  241. os << '[' << i->From().toString(10) << ", " << i->To().toString(10)
  242. << ']';
  243. }
  244. os << " }";
  245. }
  246. bool operator==(const RangeSet &other) const {
  247. return ranges == other.ranges;
  248. }
  249. };
  250. } // end anonymous namespace
  251. REGISTER_TRAIT_WITH_PROGRAMSTATE(ConstraintRange,
  252. CLANG_ENTO_PROGRAMSTATE_MAP(SymbolRef,
  253. RangeSet))
  254. namespace {
  255. class RangeConstraintManager : public SimpleConstraintManager{
  256. RangeSet GetRange(ProgramStateRef state, SymbolRef sym);
  257. public:
  258. RangeConstraintManager(SubEngine *subengine, SValBuilder &SVB)
  259. : SimpleConstraintManager(subengine, SVB) {}
  260. ProgramStateRef assumeSymNE(ProgramStateRef state, SymbolRef sym,
  261. const llvm::APSInt& Int,
  262. const llvm::APSInt& Adjustment) override;
  263. ProgramStateRef assumeSymEQ(ProgramStateRef state, SymbolRef sym,
  264. const llvm::APSInt& Int,
  265. const llvm::APSInt& Adjustment) override;
  266. ProgramStateRef assumeSymLT(ProgramStateRef state, SymbolRef sym,
  267. const llvm::APSInt& Int,
  268. const llvm::APSInt& Adjustment) override;
  269. ProgramStateRef assumeSymGT(ProgramStateRef state, SymbolRef sym,
  270. const llvm::APSInt& Int,
  271. const llvm::APSInt& Adjustment) override;
  272. ProgramStateRef assumeSymGE(ProgramStateRef state, SymbolRef sym,
  273. const llvm::APSInt& Int,
  274. const llvm::APSInt& Adjustment) override;
  275. ProgramStateRef assumeSymLE(ProgramStateRef state, SymbolRef sym,
  276. const llvm::APSInt& Int,
  277. const llvm::APSInt& Adjustment) override;
  278. const llvm::APSInt* getSymVal(ProgramStateRef St,
  279. SymbolRef sym) const override;
  280. ConditionTruthVal checkNull(ProgramStateRef State, SymbolRef Sym) override;
  281. ProgramStateRef removeDeadBindings(ProgramStateRef St,
  282. SymbolReaper& SymReaper) override;
  283. void print(ProgramStateRef St, raw_ostream &Out,
  284. const char* nl, const char *sep) override;
  285. private:
  286. RangeSet::Factory F;
  287. };
  288. } // end anonymous namespace
  289. std::unique_ptr<ConstraintManager>
  290. ento::CreateRangeConstraintManager(ProgramStateManager &StMgr, SubEngine *Eng) {
  291. return llvm::make_unique<RangeConstraintManager>(Eng, StMgr.getSValBuilder());
  292. }
  293. const llvm::APSInt* RangeConstraintManager::getSymVal(ProgramStateRef St,
  294. SymbolRef sym) const {
  295. const ConstraintRangeTy::data_type *T = St->get<ConstraintRange>(sym);
  296. return T ? T->getConcreteValue() : nullptr;
  297. }
  298. ConditionTruthVal RangeConstraintManager::checkNull(ProgramStateRef State,
  299. SymbolRef Sym) {
  300. const RangeSet *Ranges = State->get<ConstraintRange>(Sym);
  301. // If we don't have any information about this symbol, it's underconstrained.
  302. if (!Ranges)
  303. return ConditionTruthVal();
  304. // If we have a concrete value, see if it's zero.
  305. if (const llvm::APSInt *Value = Ranges->getConcreteValue())
  306. return *Value == 0;
  307. BasicValueFactory &BV = getBasicVals();
  308. APSIntType IntType = BV.getAPSIntType(Sym->getType());
  309. llvm::APSInt Zero = IntType.getZeroValue();
  310. // Check if zero is in the set of possible values.
  311. if (Ranges->Intersect(BV, F, Zero, Zero).isEmpty())
  312. return false;
  313. // Zero is a possible value, but it is not the /only/ possible value.
  314. return ConditionTruthVal();
  315. }
  316. /// Scan all symbols referenced by the constraints. If the symbol is not alive
  317. /// as marked in LSymbols, mark it as dead in DSymbols.
  318. ProgramStateRef
  319. RangeConstraintManager::removeDeadBindings(ProgramStateRef state,
  320. SymbolReaper& SymReaper) {
  321. ConstraintRangeTy CR = state->get<ConstraintRange>();
  322. ConstraintRangeTy::Factory& CRFactory = state->get_context<ConstraintRange>();
  323. for (ConstraintRangeTy::iterator I = CR.begin(), E = CR.end(); I != E; ++I) {
  324. SymbolRef sym = I.getKey();
  325. if (SymReaper.maybeDead(sym))
  326. CR = CRFactory.remove(CR, sym);
  327. }
  328. return state->set<ConstraintRange>(CR);
  329. }
  330. RangeSet
  331. RangeConstraintManager::GetRange(ProgramStateRef state, SymbolRef sym) {
  332. if (ConstraintRangeTy::data_type* V = state->get<ConstraintRange>(sym))
  333. return *V;
  334. // Lazily generate a new RangeSet representing all possible values for the
  335. // given symbol type.
  336. BasicValueFactory &BV = getBasicVals();
  337. QualType T = sym->getType();
  338. RangeSet Result(F, BV.getMinValue(T), BV.getMaxValue(T));
  339. // Special case: references are known to be non-zero.
  340. if (T->isReferenceType()) {
  341. APSIntType IntType = BV.getAPSIntType(T);
  342. Result = Result.Intersect(BV, F, ++IntType.getZeroValue(),
  343. --IntType.getZeroValue());
  344. }
  345. return Result;
  346. }
  347. //===------------------------------------------------------------------------===
  348. // assumeSymX methods: public interface for RangeConstraintManager.
  349. //===------------------------------------------------------------------------===/
  350. // The syntax for ranges below is mathematical, using [x, y] for closed ranges
  351. // and (x, y) for open ranges. These ranges are modular, corresponding with
  352. // a common treatment of C integer overflow. This means that these methods
  353. // do not have to worry about overflow; RangeSet::Intersect can handle such a
  354. // "wraparound" range.
  355. // As an example, the range [UINT_MAX-1, 3) contains five values: UINT_MAX-1,
  356. // UINT_MAX, 0, 1, and 2.
  357. ProgramStateRef
  358. RangeConstraintManager::assumeSymNE(ProgramStateRef St, SymbolRef Sym,
  359. const llvm::APSInt &Int,
  360. const llvm::APSInt &Adjustment) {
  361. // Before we do any real work, see if the value can even show up.
  362. APSIntType AdjustmentType(Adjustment);
  363. if (AdjustmentType.testInRange(Int, true) != APSIntType::RTR_Within)
  364. return St;
  365. llvm::APSInt Lower = AdjustmentType.convert(Int) - Adjustment;
  366. llvm::APSInt Upper = Lower;
  367. --Lower;
  368. ++Upper;
  369. // [Int-Adjustment+1, Int-Adjustment-1]
  370. // Notice that the lower bound is greater than the upper bound.
  371. RangeSet New = GetRange(St, Sym).Intersect(getBasicVals(), F, Upper, Lower);
  372. return New.isEmpty() ? nullptr : St->set<ConstraintRange>(Sym, New);
  373. }
  374. ProgramStateRef
  375. RangeConstraintManager::assumeSymEQ(ProgramStateRef St, SymbolRef Sym,
  376. const llvm::APSInt &Int,
  377. const llvm::APSInt &Adjustment) {
  378. // Before we do any real work, see if the value can even show up.
  379. APSIntType AdjustmentType(Adjustment);
  380. if (AdjustmentType.testInRange(Int, true) != APSIntType::RTR_Within)
  381. return nullptr;
  382. // [Int-Adjustment, Int-Adjustment]
  383. llvm::APSInt AdjInt = AdjustmentType.convert(Int) - Adjustment;
  384. RangeSet New = GetRange(St, Sym).Intersect(getBasicVals(), F, AdjInt, AdjInt);
  385. return New.isEmpty() ? nullptr : St->set<ConstraintRange>(Sym, New);
  386. }
  387. ProgramStateRef
  388. RangeConstraintManager::assumeSymLT(ProgramStateRef St, SymbolRef Sym,
  389. const llvm::APSInt &Int,
  390. const llvm::APSInt &Adjustment) {
  391. // Before we do any real work, see if the value can even show up.
  392. APSIntType AdjustmentType(Adjustment);
  393. switch (AdjustmentType.testInRange(Int, true)) {
  394. case APSIntType::RTR_Below:
  395. return nullptr;
  396. case APSIntType::RTR_Within:
  397. break;
  398. case APSIntType::RTR_Above:
  399. return St;
  400. }
  401. // Special case for Int == Min. This is always false.
  402. llvm::APSInt ComparisonVal = AdjustmentType.convert(Int);
  403. llvm::APSInt Min = AdjustmentType.getMinValue();
  404. if (ComparisonVal == Min)
  405. return nullptr;
  406. llvm::APSInt Lower = Min-Adjustment;
  407. llvm::APSInt Upper = ComparisonVal-Adjustment;
  408. --Upper;
  409. RangeSet New = GetRange(St, Sym).Intersect(getBasicVals(), F, Lower, Upper);
  410. return New.isEmpty() ? nullptr : St->set<ConstraintRange>(Sym, New);
  411. }
  412. ProgramStateRef
  413. RangeConstraintManager::assumeSymGT(ProgramStateRef St, SymbolRef Sym,
  414. const llvm::APSInt &Int,
  415. const llvm::APSInt &Adjustment) {
  416. // Before we do any real work, see if the value can even show up.
  417. APSIntType AdjustmentType(Adjustment);
  418. switch (AdjustmentType.testInRange(Int, true)) {
  419. case APSIntType::RTR_Below:
  420. return St;
  421. case APSIntType::RTR_Within:
  422. break;
  423. case APSIntType::RTR_Above:
  424. return nullptr;
  425. }
  426. // Special case for Int == Max. This is always false.
  427. llvm::APSInt ComparisonVal = AdjustmentType.convert(Int);
  428. llvm::APSInt Max = AdjustmentType.getMaxValue();
  429. if (ComparisonVal == Max)
  430. return nullptr;
  431. llvm::APSInt Lower = ComparisonVal-Adjustment;
  432. llvm::APSInt Upper = Max-Adjustment;
  433. ++Lower;
  434. RangeSet New = GetRange(St, Sym).Intersect(getBasicVals(), F, Lower, Upper);
  435. return New.isEmpty() ? nullptr : St->set<ConstraintRange>(Sym, New);
  436. }
  437. ProgramStateRef
  438. RangeConstraintManager::assumeSymGE(ProgramStateRef St, SymbolRef Sym,
  439. const llvm::APSInt &Int,
  440. const llvm::APSInt &Adjustment) {
  441. // Before we do any real work, see if the value can even show up.
  442. APSIntType AdjustmentType(Adjustment);
  443. switch (AdjustmentType.testInRange(Int, true)) {
  444. case APSIntType::RTR_Below:
  445. return St;
  446. case APSIntType::RTR_Within:
  447. break;
  448. case APSIntType::RTR_Above:
  449. return nullptr;
  450. }
  451. // Special case for Int == Min. This is always feasible.
  452. llvm::APSInt ComparisonVal = AdjustmentType.convert(Int);
  453. llvm::APSInt Min = AdjustmentType.getMinValue();
  454. if (ComparisonVal == Min)
  455. return St;
  456. llvm::APSInt Max = AdjustmentType.getMaxValue();
  457. llvm::APSInt Lower = ComparisonVal-Adjustment;
  458. llvm::APSInt Upper = Max-Adjustment;
  459. RangeSet New = GetRange(St, Sym).Intersect(getBasicVals(), F, Lower, Upper);
  460. return New.isEmpty() ? nullptr : St->set<ConstraintRange>(Sym, New);
  461. }
  462. ProgramStateRef
  463. RangeConstraintManager::assumeSymLE(ProgramStateRef St, SymbolRef Sym,
  464. const llvm::APSInt &Int,
  465. const llvm::APSInt &Adjustment) {
  466. // Before we do any real work, see if the value can even show up.
  467. APSIntType AdjustmentType(Adjustment);
  468. switch (AdjustmentType.testInRange(Int, true)) {
  469. case APSIntType::RTR_Below:
  470. return nullptr;
  471. case APSIntType::RTR_Within:
  472. break;
  473. case APSIntType::RTR_Above:
  474. return St;
  475. }
  476. // Special case for Int == Max. This is always feasible.
  477. llvm::APSInt ComparisonVal = AdjustmentType.convert(Int);
  478. llvm::APSInt Max = AdjustmentType.getMaxValue();
  479. if (ComparisonVal == Max)
  480. return St;
  481. llvm::APSInt Min = AdjustmentType.getMinValue();
  482. llvm::APSInt Lower = Min-Adjustment;
  483. llvm::APSInt Upper = ComparisonVal-Adjustment;
  484. RangeSet New = GetRange(St, Sym).Intersect(getBasicVals(), F, Lower, Upper);
  485. return New.isEmpty() ? nullptr : St->set<ConstraintRange>(Sym, New);
  486. }
  487. //===------------------------------------------------------------------------===
  488. // Pretty-printing.
  489. //===------------------------------------------------------------------------===/
  490. void RangeConstraintManager::print(ProgramStateRef St, raw_ostream &Out,
  491. const char* nl, const char *sep) {
  492. ConstraintRangeTy Ranges = St->get<ConstraintRange>();
  493. if (Ranges.isEmpty()) {
  494. Out << nl << sep << "Ranges are empty." << nl;
  495. return;
  496. }
  497. Out << nl << sep << "Ranges of symbol values:";
  498. for (ConstraintRangeTy::iterator I=Ranges.begin(), E=Ranges.end(); I!=E; ++I){
  499. Out << nl << ' ' << I.getKey() << " : ";
  500. I.getData().print(Out);
  501. }
  502. Out << nl;
  503. }