Zhongxing Xu | d19e21b | 2008-08-29 15:09:12 +0000 | [diff] [blame] | 1 | //== BasicConstraintManager.cpp - Manage basic 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 BasicConstraintManager, a class that tracks simple |
| 11 | // equality and inequality constraints on symbolic values of GRState. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 15 | #include "clang/Analysis/PathSensitive/ConstraintManager.h" |
| 16 | #include "clang/Analysis/PathSensitive/GRState.h" |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 17 | #include "clang/Analysis/PathSensitive/GRStateTrait.h" |
Ted Kremenek | 2fb78a7 | 2008-12-17 21:50:35 +0000 | [diff] [blame] | 18 | #include "clang/Analysis/PathSensitive/GRTransferFuncs.h" |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Compiler.h" |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace clang; |
| 23 | |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 24 | |
| 25 | namespace { class VISIBILITY_HIDDEN ConstNotEq {}; } |
| 26 | namespace { class VISIBILITY_HIDDEN ConstEq {}; } |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 27 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 28 | typedef llvm::ImmutableMap<SymbolRef,GRState::IntSetTy> ConstNotEqTy; |
| 29 | typedef llvm::ImmutableMap<SymbolRef,const llvm::APSInt*> ConstEqTy; |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 30 | |
| 31 | static int ConstEqIndex = 0; |
| 32 | static int ConstNotEqIndex = 0; |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 33 | |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 34 | namespace clang { |
| 35 | template<> |
| 36 | struct GRStateTrait<ConstNotEq> : public GRStatePartialTrait<ConstNotEqTy> { |
| 37 | static inline void* GDMIndex() { return &ConstNotEqIndex; } |
| 38 | }; |
| 39 | |
| 40 | template<> |
| 41 | struct GRStateTrait<ConstEq> : public GRStatePartialTrait<ConstEqTy> { |
| 42 | static inline void* GDMIndex() { return &ConstEqIndex; } |
| 43 | }; |
| 44 | } |
| 45 | |
| 46 | namespace { |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 47 | // BasicConstraintManager only tracks equality and inequality constraints of |
| 48 | // constants and integer variables. |
| 49 | class VISIBILITY_HIDDEN BasicConstraintManager : public ConstraintManager { |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 50 | GRStateManager& StateMgr; |
Zhongxing Xu | f0bc50e | 2008-11-27 06:08:40 +0000 | [diff] [blame] | 51 | GRState::IntSetTy::Factory ISetFactory; |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 52 | public: |
Zhongxing Xu | f0bc50e | 2008-11-27 06:08:40 +0000 | [diff] [blame] | 53 | BasicConstraintManager(GRStateManager& statemgr) |
| 54 | : StateMgr(statemgr), ISetFactory(statemgr.getAllocator()) {} |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 55 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 56 | virtual const GRState* Assume(const GRState* St, SVal Cond, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 57 | bool Assumption, bool& isFeasible); |
| 58 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 59 | const GRState* Assume(const GRState* St, Loc Cond, bool Assumption, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 60 | bool& isFeasible); |
| 61 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 62 | const GRState* AssumeAux(const GRState* St, Loc Cond,bool Assumption, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 63 | bool& isFeasible); |
| 64 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 65 | const GRState* Assume(const GRState* St, NonLoc Cond, bool Assumption, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 66 | bool& isFeasible); |
| 67 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 68 | const GRState* AssumeAux(const GRState* St, NonLoc Cond, bool Assumption, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 69 | bool& isFeasible); |
| 70 | |
| 71 | const GRState* AssumeSymInt(const GRState* St, bool Assumption, |
| 72 | const SymIntConstraint& C, bool& isFeasible); |
| 73 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 74 | const GRState* AssumeSymNE(const GRState* St, SymbolRef sym, |
Ted Kremenek | b2bf7cd | 2009-01-28 22:27:59 +0000 | [diff] [blame] | 75 | const llvm::APSInt& V, bool& isFeasible); |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 76 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 77 | const GRState* AssumeSymEQ(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 78 | const llvm::APSInt& V, bool& isFeasible); |
| 79 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 80 | const GRState* AssumeSymLT(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 81 | const llvm::APSInt& V, bool& isFeasible); |
| 82 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 83 | const GRState* AssumeSymGT(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 84 | const llvm::APSInt& V, bool& isFeasible); |
| 85 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 86 | const GRState* AssumeSymGE(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 87 | const llvm::APSInt& V, bool& isFeasible); |
| 88 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 89 | const GRState* AssumeSymLE(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 90 | const llvm::APSInt& V, bool& isFeasible); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 91 | |
Zhongxing Xu | e8a964b | 2008-11-22 13:21:46 +0000 | [diff] [blame] | 92 | const GRState* AssumeInBound(const GRState* St, SVal Idx, SVal UpperBound, |
| 93 | bool Assumption, bool& isFeasible); |
| 94 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 95 | const GRState* AddEQ(const GRState* St, SymbolRef sym, const llvm::APSInt& V); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 96 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 97 | const GRState* AddNE(const GRState* St, SymbolRef sym, const llvm::APSInt& V); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 98 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 99 | const llvm::APSInt* getSymVal(const GRState* St, SymbolRef sym); |
| 100 | bool isNotEqual(const GRState* St, SymbolRef sym, const llvm::APSInt& V) const; |
| 101 | bool isEqual(const GRState* St, SymbolRef sym, const llvm::APSInt& V) const; |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 102 | |
Ted Kremenek | 241677a | 2009-01-21 22:26:05 +0000 | [diff] [blame] | 103 | const GRState* RemoveDeadBindings(const GRState* St, SymbolReaper& SymReaper); |
| 104 | |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 105 | |
| 106 | void print(const GRState* St, std::ostream& Out, |
| 107 | const char* nl, const char *sep); |
Zhongxing Xu | e8a964b | 2008-11-22 13:21:46 +0000 | [diff] [blame] | 108 | |
| 109 | private: |
| 110 | BasicValueFactory& getBasicVals() { return StateMgr.getBasicVals(); } |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 111 | }; |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 112 | |
| 113 | } // end anonymous namespace |
| 114 | |
| 115 | ConstraintManager* clang::CreateBasicConstraintManager(GRStateManager& StateMgr) |
| 116 | { |
| 117 | return new BasicConstraintManager(StateMgr); |
| 118 | } |
| 119 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 120 | const GRState* BasicConstraintManager::Assume(const GRState* St, SVal Cond, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 121 | bool Assumption, bool& isFeasible) { |
| 122 | if (Cond.isUnknown()) { |
| 123 | isFeasible = true; |
| 124 | return St; |
| 125 | } |
| 126 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 127 | if (isa<NonLoc>(Cond)) |
| 128 | return Assume(St, cast<NonLoc>(Cond), Assumption, isFeasible); |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 129 | else |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 130 | return Assume(St, cast<Loc>(Cond), Assumption, isFeasible); |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 133 | const GRState* BasicConstraintManager::Assume(const GRState* St, Loc Cond, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 134 | bool Assumption, bool& isFeasible) { |
| 135 | St = AssumeAux(St, Cond, Assumption, isFeasible); |
Ted Kremenek | 2fb78a7 | 2008-12-17 21:50:35 +0000 | [diff] [blame] | 136 | |
| 137 | if (!isFeasible) |
| 138 | return St; |
| 139 | |
| 140 | // EvalAssume is used to call into the GRTransferFunction object to perform |
| 141 | // any checker-specific update of the state based on this assumption being |
| 142 | // true or false. |
| 143 | return StateMgr.getTransferFuncs().EvalAssume(StateMgr, St, Cond, Assumption, |
| 144 | isFeasible); |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 147 | const GRState* BasicConstraintManager::AssumeAux(const GRState* St, Loc Cond, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 148 | bool Assumption, bool& isFeasible) { |
| 149 | BasicValueFactory& BasicVals = StateMgr.getBasicVals(); |
| 150 | |
| 151 | switch (Cond.getSubKind()) { |
| 152 | default: |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 153 | assert (false && "'Assume' not implemented for this Loc."); |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 154 | return St; |
| 155 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 156 | case loc::SymbolValKind: |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 157 | if (Assumption) |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 158 | return AssumeSymNE(St, cast<loc::SymbolVal>(Cond).getSymbol(), |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 159 | BasicVals.getZeroWithPtrWidth(), isFeasible); |
| 160 | else |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 161 | return AssumeSymEQ(St, cast<loc::SymbolVal>(Cond).getSymbol(), |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 162 | BasicVals.getZeroWithPtrWidth(), isFeasible); |
| 163 | |
Ted Kremenek | c523471 | 2008-10-17 21:22:20 +0000 | [diff] [blame] | 164 | case loc::MemRegionKind: { |
| 165 | // FIXME: Should this go into the storemanager? |
| 166 | |
| 167 | const MemRegion* R = cast<loc::MemRegionVal>(Cond).getRegion(); |
Zhongxing Xu | 026c663 | 2009-02-05 06:57:29 +0000 | [diff] [blame] | 168 | const SubRegion* SubR = dyn_cast<SubRegion>(R); |
| 169 | |
| 170 | while (SubR) { |
| 171 | // FIXME: now we only find the first symbolic region. |
| 172 | if (const SymbolicRegion* SymR = dyn_cast<SymbolicRegion>(SubR)) |
Ted Kremenek | c523471 | 2008-10-17 21:22:20 +0000 | [diff] [blame] | 173 | return AssumeAux(St, loc::SymbolVal(SymR->getSymbol()), Assumption, |
| 174 | isFeasible); |
Zhongxing Xu | 026c663 | 2009-02-05 06:57:29 +0000 | [diff] [blame] | 175 | SubR = dyn_cast<SubRegion>(SubR->getSuperRegion()); |
Ted Kremenek | c523471 | 2008-10-17 21:22:20 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | // FALL-THROUGH. |
| 179 | } |
| 180 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 181 | case loc::FuncValKind: |
| 182 | case loc::GotoLabelKind: |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 183 | isFeasible = Assumption; |
| 184 | return St; |
| 185 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 186 | case loc::ConcreteIntKind: { |
| 187 | bool b = cast<loc::ConcreteInt>(Cond).getValue() != 0; |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 188 | isFeasible = b ? Assumption : !Assumption; |
| 189 | return St; |
| 190 | } |
| 191 | } // end switch |
| 192 | } |
| 193 | |
| 194 | const GRState* |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 195 | BasicConstraintManager::Assume(const GRState* St, NonLoc Cond, bool Assumption, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 196 | bool& isFeasible) { |
| 197 | St = AssumeAux(St, Cond, Assumption, isFeasible); |
Ted Kremenek | 2fb78a7 | 2008-12-17 21:50:35 +0000 | [diff] [blame] | 198 | |
| 199 | if (!isFeasible) |
| 200 | return St; |
| 201 | |
| 202 | // EvalAssume is used to call into the GRTransferFunction object to perform |
| 203 | // any checker-specific update of the state based on this assumption being |
| 204 | // true or false. |
| 205 | return StateMgr.getTransferFuncs().EvalAssume(StateMgr, St, Cond, Assumption, |
| 206 | isFeasible); |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | const GRState* |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 210 | BasicConstraintManager::AssumeAux(const GRState* St,NonLoc Cond, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 211 | bool Assumption, bool& isFeasible) { |
| 212 | BasicValueFactory& BasicVals = StateMgr.getBasicVals(); |
| 213 | SymbolManager& SymMgr = StateMgr.getSymbolManager(); |
| 214 | |
| 215 | switch (Cond.getSubKind()) { |
| 216 | default: |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 217 | assert(false && "'Assume' not implemented for this NonLoc"); |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 218 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 219 | case nonloc::SymbolValKind: { |
| 220 | nonloc::SymbolVal& SV = cast<nonloc::SymbolVal>(Cond); |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 221 | SymbolRef sym = SV.getSymbol(); |
Ted Kremenek | 9ab6b9c | 2009-01-22 18:23:34 +0000 | [diff] [blame] | 222 | QualType T = SymMgr.getType(sym); |
| 223 | |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 224 | if (Assumption) |
Ted Kremenek | 9ab6b9c | 2009-01-22 18:23:34 +0000 | [diff] [blame] | 225 | return AssumeSymNE(St, sym, BasicVals.getValue(0, T), isFeasible); |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 226 | else |
Ted Kremenek | 9ab6b9c | 2009-01-22 18:23:34 +0000 | [diff] [blame] | 227 | return AssumeSymEQ(St, sym, BasicVals.getValue(0, T), isFeasible); |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 230 | case nonloc::SymIntConstraintValKind: |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 231 | return |
| 232 | AssumeSymInt(St, Assumption, |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 233 | cast<nonloc::SymIntConstraintVal>(Cond).getConstraint(), |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 234 | isFeasible); |
| 235 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 236 | case nonloc::ConcreteIntKind: { |
| 237 | bool b = cast<nonloc::ConcreteInt>(Cond).getValue() != 0; |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 238 | isFeasible = b ? Assumption : !Assumption; |
| 239 | return St; |
| 240 | } |
| 241 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 242 | case nonloc::LocAsIntegerKind: |
| 243 | return AssumeAux(St, cast<nonloc::LocAsInteger>(Cond).getLoc(), |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 244 | Assumption, isFeasible); |
| 245 | } // end switch |
| 246 | } |
| 247 | |
| 248 | const GRState* |
| 249 | BasicConstraintManager::AssumeSymInt(const GRState* St, bool Assumption, |
| 250 | const SymIntConstraint& C, bool& isFeasible) { |
| 251 | |
| 252 | switch (C.getOpcode()) { |
| 253 | default: |
| 254 | // No logic yet for other operators. |
| 255 | isFeasible = true; |
| 256 | return St; |
| 257 | |
| 258 | case BinaryOperator::EQ: |
| 259 | if (Assumption) |
| 260 | return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible); |
| 261 | else |
| 262 | return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible); |
| 263 | |
| 264 | case BinaryOperator::NE: |
| 265 | if (Assumption) |
| 266 | return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible); |
| 267 | else |
| 268 | return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible); |
| 269 | |
Zhongxing Xu | 94b8312 | 2008-09-19 06:07:59 +0000 | [diff] [blame] | 270 | case BinaryOperator::GT: |
| 271 | if (Assumption) |
| 272 | return AssumeSymGT(St, C.getSymbol(), C.getInt(), isFeasible); |
| 273 | else |
| 274 | return AssumeSymLE(St, C.getSymbol(), C.getInt(), isFeasible); |
| 275 | |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 276 | case BinaryOperator::GE: |
| 277 | if (Assumption) |
| 278 | return AssumeSymGE(St, C.getSymbol(), C.getInt(), isFeasible); |
| 279 | else |
| 280 | return AssumeSymLT(St, C.getSymbol(), C.getInt(), isFeasible); |
| 281 | |
Ted Kremenek | 8c3e7fb | 2008-09-16 23:24:45 +0000 | [diff] [blame] | 282 | case BinaryOperator::LT: |
| 283 | if (Assumption) |
| 284 | return AssumeSymLT(St, C.getSymbol(), C.getInt(), isFeasible); |
| 285 | else |
| 286 | return AssumeSymGE(St, C.getSymbol(), C.getInt(), isFeasible); |
| 287 | |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 288 | case BinaryOperator::LE: |
| 289 | if (Assumption) |
| 290 | return AssumeSymLE(St, C.getSymbol(), C.getInt(), isFeasible); |
| 291 | else |
| 292 | return AssumeSymGT(St, C.getSymbol(), C.getInt(), isFeasible); |
| 293 | } // end switch |
| 294 | } |
| 295 | |
| 296 | const GRState* |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 297 | BasicConstraintManager::AssumeSymNE(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 298 | const llvm::APSInt& V, bool& isFeasible) { |
| 299 | // First, determine if sym == X, where X != V. |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 300 | if (const llvm::APSInt* X = getSymVal(St, sym)) { |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 301 | isFeasible = (*X != V); |
| 302 | return St; |
| 303 | } |
| 304 | |
| 305 | // Second, determine if sym != V. |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 306 | if (isNotEqual(St, sym, V)) { |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 307 | isFeasible = true; |
| 308 | return St; |
| 309 | } |
| 310 | |
| 311 | // If we reach here, sym is not a constant and we don't know if it is != V. |
| 312 | // Make that assumption. |
| 313 | isFeasible = true; |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 314 | return AddNE(St, sym, V); |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | const GRState* |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 318 | BasicConstraintManager::AssumeSymEQ(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 319 | const llvm::APSInt& V, bool& isFeasible) { |
| 320 | // First, determine if sym == X, where X != V. |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 321 | if (const llvm::APSInt* X = getSymVal(St, sym)) { |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 322 | isFeasible = *X == V; |
| 323 | return St; |
| 324 | } |
| 325 | |
| 326 | // Second, determine if sym != V. |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 327 | if (isNotEqual(St, sym, V)) { |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 328 | isFeasible = false; |
| 329 | return St; |
| 330 | } |
| 331 | |
| 332 | // If we reach here, sym is not a constant and we don't know if it is == V. |
| 333 | // Make that assumption. |
| 334 | |
| 335 | isFeasible = true; |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 336 | return AddEQ(St, sym, V); |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | // These logic will be handled in another ConstraintManager. |
| 340 | const GRState* |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 341 | BasicConstraintManager::AssumeSymLT(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 342 | const llvm::APSInt& V, bool& isFeasible) { |
Ted Kremenek | 73abd13 | 2008-12-03 18:56:12 +0000 | [diff] [blame] | 343 | |
| 344 | // Is 'V' the smallest possible value? |
Chris Lattner | 071e04e | 2009-01-30 01:58:33 +0000 | [diff] [blame] | 345 | if (V == llvm::APSInt::getMinValue(V.getBitWidth(), V.isUnsigned())) { |
Ted Kremenek | 73abd13 | 2008-12-03 18:56:12 +0000 | [diff] [blame] | 346 | // sym cannot be any value less than 'V'. This path is infeasible. |
| 347 | isFeasible = false; |
| 348 | return St; |
| 349 | } |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 350 | |
| 351 | // FIXME: For now have assuming x < y be the same as assuming sym != V; |
| 352 | return AssumeSymNE(St, sym, V, isFeasible); |
| 353 | } |
| 354 | |
| 355 | const GRState* |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 356 | BasicConstraintManager::AssumeSymGT(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 357 | const llvm::APSInt& V, bool& isFeasible) { |
| 358 | |
Ted Kremenek | d7ff487 | 2008-12-03 19:06:30 +0000 | [diff] [blame] | 359 | // Is 'V' the largest possible value? |
Chris Lattner | 071e04e | 2009-01-30 01:58:33 +0000 | [diff] [blame] | 360 | if (V == llvm::APSInt::getMaxValue(V.getBitWidth(), V.isUnsigned())) { |
Ted Kremenek | d7ff487 | 2008-12-03 19:06:30 +0000 | [diff] [blame] | 361 | // sym cannot be any value greater than 'V'. This path is infeasible. |
| 362 | isFeasible = false; |
| 363 | return St; |
| 364 | } |
| 365 | |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 366 | // FIXME: For now have assuming x > y be the same as assuming sym != V; |
| 367 | return AssumeSymNE(St, sym, V, isFeasible); |
| 368 | } |
| 369 | |
| 370 | const GRState* |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 371 | BasicConstraintManager::AssumeSymGE(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 372 | const llvm::APSInt& V, bool& isFeasible) { |
| 373 | |
Ted Kremenek | 8c3e7fb | 2008-09-16 23:24:45 +0000 | [diff] [blame] | 374 | // Reject a path if the value of sym is a constant X and !(X >= V). |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 375 | if (const llvm::APSInt* X = getSymVal(St, sym)) { |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 376 | isFeasible = *X >= V; |
| 377 | return St; |
| 378 | } |
Ted Kremenek | d7ff487 | 2008-12-03 19:06:30 +0000 | [diff] [blame] | 379 | |
| 380 | // Sym is not a constant, but it is worth looking to see if V is the |
| 381 | // maximum integer value. |
Chris Lattner | 071e04e | 2009-01-30 01:58:33 +0000 | [diff] [blame] | 382 | if (V == llvm::APSInt::getMaxValue(V.getBitWidth(), V.isUnsigned())) { |
Ted Kremenek | d7ff487 | 2008-12-03 19:06:30 +0000 | [diff] [blame] | 383 | // If we know that sym != V, then this condition is infeasible since |
| 384 | // there is no other value greater than V. |
| 385 | isFeasible = !isNotEqual(St, sym, V); |
| 386 | |
| 387 | // If the path is still feasible then as a consequence we know that |
| 388 | // 'sym == V' because we cannot have 'sym > V' (no larger values). |
| 389 | // Add this constraint. |
| 390 | if (isFeasible) |
| 391 | return AddEQ(St, sym, V); |
| 392 | } |
| 393 | else |
| 394 | isFeasible = true; |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 395 | |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 396 | return St; |
| 397 | } |
| 398 | |
| 399 | const GRState* |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 400 | BasicConstraintManager::AssumeSymLE(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 401 | const llvm::APSInt& V, bool& isFeasible) { |
| 402 | |
Ted Kremenek | 73abd13 | 2008-12-03 18:56:12 +0000 | [diff] [blame] | 403 | // Reject a path if the value of sym is a constant X and !(X <= V). |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 404 | if (const llvm::APSInt* X = getSymVal(St, sym)) { |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 405 | isFeasible = *X <= V; |
| 406 | return St; |
| 407 | } |
Ted Kremenek | 0a41e5a | 2008-09-19 18:00:36 +0000 | [diff] [blame] | 408 | |
Ted Kremenek | 73abd13 | 2008-12-03 18:56:12 +0000 | [diff] [blame] | 409 | // Sym is not a constant, but it is worth looking to see if V is the |
| 410 | // minimum integer value. |
Chris Lattner | 071e04e | 2009-01-30 01:58:33 +0000 | [diff] [blame] | 411 | if (V == llvm::APSInt::getMinValue(V.getBitWidth(), V.isUnsigned())) { |
Ted Kremenek | 73abd13 | 2008-12-03 18:56:12 +0000 | [diff] [blame] | 412 | // If we know that sym != V, then this condition is infeasible since |
| 413 | // there is no other value less than V. |
| 414 | isFeasible = !isNotEqual(St, sym, V); |
| 415 | |
| 416 | // If the path is still feasible then as a consequence we know that |
| 417 | // 'sym == V' because we cannot have 'sym < V' (no smaller values). |
| 418 | // Add this constraint. |
| 419 | if (isFeasible) |
| 420 | return AddEQ(St, sym, V); |
| 421 | } |
| 422 | else |
| 423 | isFeasible = true; |
| 424 | |
Zhongxing Xu | 30ad167 | 2008-08-27 14:03:33 +0000 | [diff] [blame] | 425 | return St; |
| 426 | } |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 427 | |
Zhongxing Xu | e8a964b | 2008-11-22 13:21:46 +0000 | [diff] [blame] | 428 | const GRState* |
| 429 | BasicConstraintManager::AssumeInBound(const GRState* St, SVal Idx, |
| 430 | SVal UpperBound, bool Assumption, |
| 431 | bool& isFeasible) { |
| 432 | // Only support ConcreteInt for now. |
| 433 | if (!(isa<nonloc::ConcreteInt>(Idx) && isa<nonloc::ConcreteInt>(UpperBound))){ |
| 434 | isFeasible = true; |
| 435 | return St; |
| 436 | } |
| 437 | |
| 438 | const llvm::APSInt& Zero = getBasicVals().getZeroWithPtrWidth(false); |
Sebastian Redl | e95db4f | 2008-11-24 19:35:33 +0000 | [diff] [blame] | 439 | llvm::APSInt IdxV = cast<nonloc::ConcreteInt>(Idx).getValue(); |
| 440 | // IdxV might be too narrow. |
| 441 | if (IdxV.getBitWidth() < Zero.getBitWidth()) |
| 442 | IdxV.extend(Zero.getBitWidth()); |
| 443 | // UBV might be too narrow, too. |
| 444 | llvm::APSInt UBV = cast<nonloc::ConcreteInt>(UpperBound).getValue(); |
| 445 | if (UBV.getBitWidth() < Zero.getBitWidth()) |
| 446 | UBV.extend(Zero.getBitWidth()); |
Zhongxing Xu | e8a964b | 2008-11-22 13:21:46 +0000 | [diff] [blame] | 447 | |
| 448 | bool InBound = (Zero <= IdxV) && (IdxV < UBV); |
| 449 | |
| 450 | isFeasible = Assumption ? InBound : !InBound; |
| 451 | |
| 452 | return St; |
| 453 | } |
| 454 | |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 455 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 456 | const GRState* BasicConstraintManager::AddEQ(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 457 | const llvm::APSInt& V) { |
| 458 | // Create a new state with the old binding replaced. |
| 459 | GRStateRef state(St, StateMgr); |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 460 | return state.set<ConstEq>(sym, &V); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 463 | const GRState* BasicConstraintManager::AddNE(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 464 | const llvm::APSInt& V) { |
Zhongxing Xu | f0bc50e | 2008-11-27 06:08:40 +0000 | [diff] [blame] | 465 | |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 466 | GRStateRef state(St, StateMgr); |
| 467 | |
| 468 | // First, retrieve the NE-set associated with the given symbol. |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 469 | ConstNotEqTy::data_type* T = state.get<ConstNotEq>(sym); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 470 | GRState::IntSetTy S = T ? *T : ISetFactory.GetEmptySet(); |
| 471 | |
| 472 | |
| 473 | // Now add V to the NE set. |
| 474 | S = ISetFactory.Add(S, &V); |
| 475 | |
| 476 | // Create a new state with the old binding replaced. |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 477 | return state.set<ConstNotEq>(sym, S); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | const llvm::APSInt* BasicConstraintManager::getSymVal(const GRState* St, |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 481 | SymbolRef sym) { |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 482 | const ConstEqTy::data_type* T = St->get<ConstEq>(sym); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 483 | return T ? *T : NULL; |
| 484 | } |
| 485 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 486 | bool BasicConstraintManager::isNotEqual(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 487 | const llvm::APSInt& V) const { |
| 488 | |
| 489 | // Retrieve the NE-set associated with the given symbol. |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 490 | const ConstNotEqTy::data_type* T = St->get<ConstNotEq>(sym); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 491 | |
| 492 | // See if V is present in the NE-set. |
| 493 | return T ? T->contains(&V) : false; |
| 494 | } |
| 495 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 496 | bool BasicConstraintManager::isEqual(const GRState* St, SymbolRef sym, |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 497 | const llvm::APSInt& V) const { |
| 498 | // Retrieve the EQ-set associated with the given symbol. |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 499 | const ConstEqTy::data_type* T = St->get<ConstEq>(sym); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 500 | // See if V is present in the EQ-set. |
| 501 | return T ? **T == V : false; |
| 502 | } |
| 503 | |
Zhongxing Xu | 8fd9b35 | 2008-11-27 02:39:34 +0000 | [diff] [blame] | 504 | /// Scan all symbols referenced by the constraints. If the symbol is not alive |
| 505 | /// as marked in LSymbols, mark it as dead in DSymbols. |
Ted Kremenek | 241677a | 2009-01-21 22:26:05 +0000 | [diff] [blame] | 506 | const GRState* |
| 507 | BasicConstraintManager::RemoveDeadBindings(const GRState* St, |
| 508 | SymbolReaper& SymReaper) { |
| 509 | |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 510 | GRStateRef state(St, StateMgr); |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 511 | ConstEqTy CE = state.get<ConstEq>(); |
| 512 | ConstEqTy::Factory& CEFactory = state.get_context<ConstEq>(); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 513 | |
| 514 | for (ConstEqTy::iterator I = CE.begin(), E = CE.end(); I!=E; ++I) { |
Ted Kremenek | 241677a | 2009-01-21 22:26:05 +0000 | [diff] [blame] | 515 | SymbolRef sym = I.getKey(); |
| 516 | if (SymReaper.maybeDead(sym)) CE = CEFactory.Remove(CE, sym); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 517 | } |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 518 | state = state.set<ConstEq>(CE); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 519 | |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 520 | ConstNotEqTy CNE = state.get<ConstNotEq>(); |
| 521 | ConstNotEqTy::Factory& CNEFactory = state.get_context<ConstNotEq>(); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 522 | |
| 523 | for (ConstNotEqTy::iterator I = CNE.begin(), E = CNE.end(); I != E; ++I) { |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 524 | SymbolRef sym = I.getKey(); |
Ted Kremenek | 241677a | 2009-01-21 22:26:05 +0000 | [diff] [blame] | 525 | if (SymReaper.maybeDead(sym)) CNE = CNEFactory.Remove(CNE, sym); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 528 | return state.set<ConstNotEq>(CNE); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | void BasicConstraintManager::print(const GRState* St, std::ostream& Out, |
| 532 | const char* nl, const char *sep) { |
| 533 | // Print equality constraints. |
| 534 | |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 535 | ConstEqTy CE = St->get<ConstEq>(); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 536 | |
| 537 | if (!CE.isEmpty()) { |
| 538 | Out << nl << sep << "'==' constraints:"; |
| 539 | |
| 540 | for (ConstEqTy::iterator I = CE.begin(), E = CE.end(); I!=E; ++I) { |
| 541 | Out << nl << " $" << I.getKey(); |
| 542 | llvm::raw_os_ostream OS(Out); |
| 543 | OS << " : " << *I.getData(); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | // Print != constraints. |
| 548 | |
Ted Kremenek | 8ee74d5 | 2009-01-26 06:04:53 +0000 | [diff] [blame] | 549 | ConstNotEqTy CNE = St->get<ConstNotEq>(); |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 550 | |
| 551 | if (!CNE.isEmpty()) { |
| 552 | Out << nl << sep << "'!=' constraints:"; |
| 553 | |
| 554 | for (ConstNotEqTy::iterator I = CNE.begin(), EI = CNE.end(); I!=EI; ++I) { |
| 555 | Out << nl << " $" << I.getKey() << " : "; |
| 556 | bool isFirst = true; |
| 557 | |
| 558 | GRState::IntSetTy::iterator J = I.getData().begin(), |
| 559 | EJ = I.getData().end(); |
| 560 | |
| 561 | for ( ; J != EJ; ++J) { |
| 562 | if (isFirst) isFirst = false; |
| 563 | else Out << ", "; |
| 564 | |
Zhongxing Xu | 7d94e26 | 2008-11-10 05:00:06 +0000 | [diff] [blame] | 565 | Out << (*J)->getSExtValue(); // Hack: should print to raw_ostream. |
Zhongxing Xu | 39cfed3 | 2008-08-29 14:52:36 +0000 | [diff] [blame] | 566 | } |
| 567 | } |
| 568 | } |
Daniel Dunbar | 0e194dd | 2008-08-30 02:06:22 +0000 | [diff] [blame] | 569 | } |