Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 1 | //= GRState*cpp - Path-Sens. "State" for tracking valuues -----*- C++ -*--=// |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 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 | // |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 10 | // This file defines SymbolID, ExprBindKey, and GRState* |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Ted Kremenek | e7aa9a1 | 2008-08-17 02:59:30 +0000 | [diff] [blame] | 14 | #include "clang/Analysis/PathSensitive/GRStateTrait.h" |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 15 | #include "clang/Analysis/PathSensitive/GRState.h" |
Ted Kremenek | 90e1481 | 2008-02-14 23:25:54 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/SmallSet.h" |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 17 | #include "clang/Analysis/PathSensitive/GRTransferFuncs.h" |
Ted Kremenek | f66ea2cd | 2008-02-04 21:59:22 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace clang; |
| 20 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 21 | GRStateManager::~GRStateManager() { |
| 22 | for (std::vector<GRState::Printer*>::iterator I=Printers.begin(), |
| 23 | E=Printers.end(); I!=E; ++I) |
| 24 | delete *I; |
| 25 | |
| 26 | for (GDMContextsTy::iterator I=GDMContexts.begin(), E=GDMContexts.end(); |
| 27 | I!=E; ++I) |
| 28 | I->second.second(I->second.first); |
| 29 | } |
| 30 | |
| 31 | //===----------------------------------------------------------------------===// |
| 32 | // Basic symbolic analysis. This will eventually be refactored into a |
| 33 | // separate component. |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | |
| 36 | typedef llvm::ImmutableMap<SymbolID,GRState::IntSetTy> ConstNotEqTy; |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 37 | typedef llvm::ImmutableMap<SymbolID,const llvm::APSInt*> ConstEqTy; |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 38 | |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 39 | static int ConstEqTyIndex = 0; |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 40 | static int ConstNotEqTyIndex = 0; |
| 41 | |
| 42 | namespace clang { |
Ted Kremenek | e7aa9a1 | 2008-08-17 02:59:30 +0000 | [diff] [blame] | 43 | template<> |
| 44 | struct GRStateTrait<ConstNotEqTy> : public GRStatePartialTrait<ConstNotEqTy> { |
| 45 | static inline void* GDMIndex() { return &ConstNotEqTyIndex; } |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 46 | }; |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 47 | |
| 48 | template<> |
| 49 | struct GRStateTrait<ConstEqTy> : public GRStatePartialTrait<ConstEqTy> { |
| 50 | static inline void* GDMIndex() { return &ConstEqTyIndex; } |
| 51 | }; |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 54 | bool GRState::isNotEqual(SymbolID sym, const llvm::APSInt& V) const { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 55 | |
| 56 | // Retrieve the NE-set associated with the given symbol. |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 57 | const ConstNotEqTy::data_type* T = get<ConstNotEqTy>(sym); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 58 | |
| 59 | // See if V is present in the NE-set. |
Ted Kremenek | e8fdc83 | 2008-07-07 16:21:19 +0000 | [diff] [blame] | 60 | return T ? T->contains(&V) : false; |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 63 | bool GRState::isEqual(SymbolID sym, const llvm::APSInt& V) const { |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 64 | // Retrieve the EQ-set associated with the given symbol. |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 65 | const ConstEqTy::data_type* T = get<ConstEqTy>(sym); |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 66 | // See if V is present in the EQ-set. |
| 67 | return T ? **T == V : false; |
| 68 | } |
| 69 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 70 | const llvm::APSInt* GRState::getSymVal(SymbolID sym) const { |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 71 | const ConstEqTy::data_type* T = get<ConstEqTy>(sym); |
Ted Kremenek | e8fdc83 | 2008-07-07 16:21:19 +0000 | [diff] [blame] | 72 | return T ? *T : NULL; |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 75 | const GRState* |
| 76 | GRStateManager::RemoveDeadBindings(const GRState* St, Stmt* Loc, |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 77 | const LiveVariables& Liveness, |
| 78 | DeadSymbolsTy& DSymbols) { |
Ted Kremenek | b87d909 | 2008-02-08 19:17:19 +0000 | [diff] [blame] | 79 | |
| 80 | // This code essentially performs a "mark-and-sweep" of the VariableBindings. |
| 81 | // The roots are any Block-level exprs and Decls that our liveness algorithm |
| 82 | // tells us are live. We then see what Decls they may reference, and keep |
| 83 | // those around. This code more than likely can be made faster, and the |
| 84 | // frequency of which this method is called should be experimented with |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 85 | // for optimum performance. |
| 86 | DRoots.clear(); |
| 87 | StoreManager::LiveSymbolsTy LSymbols; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 88 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 89 | GRState NewSt = *St; |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 90 | |
| 91 | // FIXME: Put this in environment. |
| 92 | // Clean up the environment. |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 93 | |
| 94 | // Drop bindings for subexpressions. |
Ted Kremenek | 8133a26 | 2008-07-08 21:46:56 +0000 | [diff] [blame] | 95 | NewSt.Env = EnvMgr.RemoveSubExprBindings(NewSt.Env); |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 96 | |
| 97 | // Iterate over the block-expr bindings. |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 98 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 99 | for (GRState::beb_iterator I = St->beb_begin(), E = St->beb_end(); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 100 | I!=E ; ++I) { |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 101 | Expr* BlkExpr = I.getKey(); |
Ted Kremenek | b87d909 | 2008-02-08 19:17:19 +0000 | [diff] [blame] | 102 | |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 103 | if (Liveness.isLive(Loc, BlkExpr)) { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 104 | RVal X = I.getData(); |
Ted Kremenek | 90e1481 | 2008-02-14 23:25:54 +0000 | [diff] [blame] | 105 | |
| 106 | if (isa<lval::DeclVal>(X)) { |
| 107 | lval::DeclVal LV = cast<lval::DeclVal>(X); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 108 | DRoots.push_back(LV.getDecl()); |
Ted Kremenek | b87d909 | 2008-02-08 19:17:19 +0000 | [diff] [blame] | 109 | } |
Ted Kremenek | 90e1481 | 2008-02-14 23:25:54 +0000 | [diff] [blame] | 110 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 111 | for (RVal::symbol_iterator SI = X.symbol_begin(), SE = X.symbol_end(); |
| 112 | SI != SE; ++SI) { |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 113 | LSymbols.insert(*SI); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 114 | } |
Ted Kremenek | b87d909 | 2008-02-08 19:17:19 +0000 | [diff] [blame] | 115 | } |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 116 | else { |
| 117 | RVal X = I.getData(); |
| 118 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 119 | if (X.isUndef() && cast<UndefinedVal>(X).getData()) |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 120 | continue; |
| 121 | |
Ted Kremenek | 8133a26 | 2008-07-08 21:46:56 +0000 | [diff] [blame] | 122 | NewSt.Env = EnvMgr.RemoveBlkExpr(NewSt.Env, BlkExpr); |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 123 | } |
Ted Kremenek | b87d909 | 2008-02-08 19:17:19 +0000 | [diff] [blame] | 124 | } |
Ted Kremenek | 016f52f | 2008-02-08 21:10:02 +0000 | [diff] [blame] | 125 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 126 | // Clean up the store. |
| 127 | DSymbols.clear(); |
| 128 | NewSt.St = StMgr->RemoveDeadBindings(St->getStore(), Loc, Liveness, DRoots, |
| 129 | LSymbols, DSymbols); |
Ted Kremenek | b87d909 | 2008-02-08 19:17:19 +0000 | [diff] [blame] | 130 | |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 131 | |
| 132 | GRStateRef state(getPersistentState(NewSt), *this); |
| 133 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 134 | // Remove the dead symbols from the symbol tracker. |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 135 | // FIXME: Refactor into something else that manages symbol values. |
Ted Kremenek | 77d7ef8 | 2008-04-24 18:31:42 +0000 | [diff] [blame] | 136 | |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 137 | ConstEqTy CE = state.get<ConstEqTy>(); |
| 138 | ConstEqTy::Factory& CEFactory = state.get_context<ConstEqTy>(); |
| 139 | |
| 140 | for (ConstEqTy::iterator I = CE.begin(), E = CE.end(); I!=E; ++I) { |
| 141 | SymbolID sym = I.getKey(); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 142 | if (!LSymbols.count(sym)) { |
| 143 | DSymbols.insert(sym); |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 144 | CE = CEFactory.Remove(CE, sym); |
Ted Kremenek | 77d7ef8 | 2008-04-24 18:31:42 +0000 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 148 | ConstNotEqTy CNE = state.get<ConstNotEqTy>(); |
| 149 | ConstNotEqTy::Factory& CNEFactory = state.get_context<ConstNotEqTy>(); |
| 150 | |
| 151 | for (ConstNotEqTy::iterator I = CNE.begin(), E = CNE.end(); I != E; ++I) { |
| 152 | SymbolID sym = I.getKey(); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 153 | if (!LSymbols.count(sym)) { |
| 154 | DSymbols.insert(sym); |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 155 | CNE = CNEFactory.Remove(CNE, sym); |
Ted Kremenek | 77d7ef8 | 2008-04-24 18:31:42 +0000 | [diff] [blame] | 156 | } |
| 157 | } |
Ted Kremenek | 90e1481 | 2008-02-14 23:25:54 +0000 | [diff] [blame] | 158 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 159 | return state.set<ConstNotEqTy>(CNE); |
Ted Kremenek | b87d909 | 2008-02-08 19:17:19 +0000 | [diff] [blame] | 160 | } |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 161 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 162 | const GRState* GRStateManager::SetRVal(const GRState* St, LVal LV, |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 163 | RVal V) { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 164 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 165 | Store OldStore = St->getStore(); |
| 166 | Store NewStore = StMgr->SetRVal(OldStore, LV, V); |
Ted Kremenek | 3271f8d | 2008-02-07 04:16:04 +0000 | [diff] [blame] | 167 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 168 | if (NewStore == OldStore) |
| 169 | return St; |
Ted Kremenek | 692416c | 2008-02-18 22:57:02 +0000 | [diff] [blame] | 170 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 171 | GRState NewSt = *St; |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 172 | NewSt.St = NewStore; |
| 173 | return getPersistentState(NewSt); |
Ted Kremenek | f66ea2cd | 2008-02-04 21:59:22 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 176 | const GRState* GRStateManager::Unbind(const GRState* St, LVal LV) { |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 177 | Store OldStore = St->getStore(); |
| 178 | Store NewStore = StMgr->Remove(OldStore, LV); |
| 179 | |
| 180 | if (NewStore == OldStore) |
| 181 | return St; |
| 182 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 183 | GRState NewSt = *St; |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 184 | NewSt.St = NewStore; |
| 185 | return getPersistentState(NewSt); |
| 186 | } |
| 187 | |
| 188 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 189 | const GRState* GRStateManager::AddNE(const GRState* St, SymbolID sym, |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 190 | const llvm::APSInt& V) { |
| 191 | |
| 192 | GRStateRef state(St, *this); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 193 | |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 194 | // First, retrieve the NE-set associated with the given symbol. |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 195 | ConstNotEqTy::data_type* T = state.get<ConstNotEqTy>(sym); |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 196 | GRState::IntSetTy S = T ? *T : ISetFactory.GetEmptySet(); |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 197 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 198 | // Now add V to the NE set. |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 199 | S = ISetFactory.Add(S, &V); |
| 200 | |
| 201 | // Create a new state with the old binding replaced. |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 202 | return state.set<ConstNotEqTy>(sym, S); |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 205 | const GRState* GRStateManager::AddEQ(const GRState* St, SymbolID sym, |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 206 | const llvm::APSInt& V) { |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 207 | // Create a new state with the old binding replaced. |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 208 | GRStateRef state(St, *this); |
| 209 | return state.set<ConstEqTy>(sym, &V); |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 212 | const GRState* GRStateManager::getInitialState() { |
Ted Kremenek | 5a7b382 | 2008-02-26 23:37:01 +0000 | [diff] [blame] | 213 | |
Ted Kremenek | 72cd17f | 2008-08-14 21:16:54 +0000 | [diff] [blame] | 214 | GRState StateImpl(EnvMgr.getInitialEnvironment(), StMgr->getInitialStore(), |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 215 | GDMFactory.GetEmptyMap()); |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 216 | |
| 217 | return getPersistentState(StateImpl); |
| 218 | } |
| 219 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 220 | const GRState* GRStateManager::getPersistentState(GRState& State) { |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 221 | |
| 222 | llvm::FoldingSetNodeID ID; |
| 223 | State.Profile(ID); |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 224 | void* InsertPos; |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 225 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 226 | if (GRState* I = StateSet.FindNodeOrInsertPos(ID, InsertPos)) |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 227 | return I; |
| 228 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 229 | GRState* I = (GRState*) Alloc.Allocate<GRState>(); |
| 230 | new (I) GRState(State); |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 231 | StateSet.InsertNode(I, InsertPos); |
| 232 | return I; |
| 233 | } |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 234 | |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 235 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 236 | //===----------------------------------------------------------------------===// |
| 237 | // State pretty-printing. |
| 238 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 461f977 | 2008-03-11 18:57:24 +0000 | [diff] [blame] | 239 | |
Ted Kremenek | ae6814e | 2008-08-13 21:24:49 +0000 | [diff] [blame] | 240 | void GRState::print(std::ostream& Out, Printer** Beg, Printer** End, |
| 241 | const char* nl, const char* sep) const { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 242 | |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 243 | // Print Variable Bindings |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 244 | Out << "Variables:" << nl; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 245 | |
| 246 | bool isFirst = true; |
| 247 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 248 | for (vb_iterator I = vb_begin(), E = vb_end(); I != E; ++I) { |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 249 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 250 | if (isFirst) isFirst = false; |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 251 | else Out << nl; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 252 | |
| 253 | Out << ' ' << I.getKey()->getName() << " : "; |
| 254 | I.getData().print(Out); |
| 255 | } |
| 256 | |
| 257 | // Print Subexpression bindings. |
| 258 | |
| 259 | isFirst = true; |
| 260 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 261 | for (seb_iterator I = seb_begin(), E = seb_end(); I != E; ++I) { |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 262 | |
| 263 | if (isFirst) { |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 264 | Out << nl << nl << "Sub-Expressions:" << nl; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 265 | isFirst = false; |
| 266 | } |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 267 | else { Out << nl; } |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 268 | |
| 269 | Out << " (" << (void*) I.getKey() << ") "; |
| 270 | I.getKey()->printPretty(Out); |
| 271 | Out << " : "; |
| 272 | I.getData().print(Out); |
| 273 | } |
| 274 | |
| 275 | // Print block-expression bindings. |
| 276 | |
| 277 | isFirst = true; |
| 278 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 279 | for (beb_iterator I = beb_begin(), E = beb_end(); I != E; ++I) { |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 280 | |
| 281 | if (isFirst) { |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 282 | Out << nl << nl << "Block-level Expressions:" << nl; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 283 | isFirst = false; |
| 284 | } |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 285 | else { Out << nl; } |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 286 | |
| 287 | Out << " (" << (void*) I.getKey() << ") "; |
| 288 | I.getKey()->printPretty(Out); |
| 289 | Out << " : "; |
| 290 | I.getData().print(Out); |
| 291 | } |
| 292 | |
| 293 | // Print equality constraints. |
Ted Kremenek | ae6814e | 2008-08-13 21:24:49 +0000 | [diff] [blame] | 294 | // FIXME: Make just another printer do this. |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 295 | ConstEqTy CE = get<ConstEqTy>(); |
| 296 | |
| 297 | if (!CE.isEmpty()) { |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 298 | Out << nl << sep << "'==' constraints:"; |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 299 | |
| 300 | for (ConstEqTy::iterator I = CE.begin(), E = CE.end(); I!=E; ++I) |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 301 | Out << nl << " $" << I.getKey() |
Chris Lattner | 9aa77f1 | 2008-08-17 07:19:51 +0000 | [diff] [blame^] | 302 | << " : " << *I.getData(); |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 303 | } |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 304 | |
| 305 | // Print != constraints. |
Ted Kremenek | ae6814e | 2008-08-13 21:24:49 +0000 | [diff] [blame] | 306 | // FIXME: Make just another printer do this. |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 307 | |
| 308 | ConstNotEqTy CNE = get<ConstNotEqTy>(); |
| 309 | |
| 310 | if (!CNE.isEmpty()) { |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 311 | Out << nl << sep << "'!=' constraints:"; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 312 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 313 | for (ConstNotEqTy::iterator I = CNE.begin(), EI = CNE.end(); I!=EI; ++I) { |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 314 | Out << nl << " $" << I.getKey() << " : "; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 315 | isFirst = true; |
| 316 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 317 | IntSetTy::iterator J = I.getData().begin(), EJ = I.getData().end(); |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 318 | |
| 319 | for ( ; J != EJ; ++J) { |
| 320 | if (isFirst) isFirst = false; |
| 321 | else Out << ", "; |
| 322 | |
Chris Lattner | 9aa77f1 | 2008-08-17 07:19:51 +0000 | [diff] [blame^] | 323 | Out << *J; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | } |
Ted Kremenek | 461f977 | 2008-03-11 18:57:24 +0000 | [diff] [blame] | 327 | |
Ted Kremenek | ae6814e | 2008-08-13 21:24:49 +0000 | [diff] [blame] | 328 | // Print checker-specific data. |
| 329 | for ( ; Beg != End ; ++Beg) (*Beg)->Print(Out, this, nl, sep); |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 330 | } |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 331 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 332 | void GRStateRef::printDOT(std::ostream& Out) const { |
| 333 | print(Out, "\\l", "\\|"); |
| 334 | } |
| 335 | |
| 336 | void GRStateRef::printStdErr() const { |
| 337 | print(*llvm::cerr); |
| 338 | } |
| 339 | |
| 340 | void GRStateRef::print(std::ostream& Out, const char* nl, const char* sep)const{ |
| 341 | GRState::Printer **beg = Mgr->Printers.empty() ? 0 : &Mgr->Printers[0]; |
| 342 | GRState::Printer **end = !beg ? 0 : beg + Mgr->Printers.size(); |
| 343 | St->print(Out, beg, end, nl, sep); |
| 344 | } |
| 345 | |
Ted Kremenek | 72cd17f | 2008-08-14 21:16:54 +0000 | [diff] [blame] | 346 | //===----------------------------------------------------------------------===// |
| 347 | // Generic Data Map. |
| 348 | //===----------------------------------------------------------------------===// |
| 349 | |
| 350 | void* const* GRState::FindGDM(void* K) const { |
| 351 | return GDM.lookup(K); |
| 352 | } |
| 353 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 354 | void* |
| 355 | GRStateManager::FindGDMContext(void* K, |
| 356 | void* (*CreateContext)(llvm::BumpPtrAllocator&), |
| 357 | void (*DeleteContext)(void*)) { |
| 358 | |
| 359 | std::pair<void*, void (*)(void*)>& p = GDMContexts[K]; |
| 360 | if (!p.first) { |
| 361 | p.first = CreateContext(Alloc); |
| 362 | p.second = DeleteContext; |
| 363 | } |
| 364 | |
| 365 | return p.first; |
| 366 | } |
| 367 | |
Ted Kremenek | 72cd17f | 2008-08-14 21:16:54 +0000 | [diff] [blame] | 368 | const GRState* GRStateManager::addGDM(const GRState* St, void* Key, void* Data){ |
| 369 | GRState::GenericDataMap M1 = St->getGDM(); |
| 370 | GRState::GenericDataMap M2 = GDMFactory.Add(M1, Key, Data); |
| 371 | |
| 372 | if (M1 == M2) |
| 373 | return St; |
| 374 | |
| 375 | GRState NewSt = *St; |
| 376 | NewSt.GDM = M2; |
| 377 | return getPersistentState(NewSt); |
| 378 | } |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 379 | |
| 380 | //===----------------------------------------------------------------------===// |
| 381 | // Queries. |
| 382 | //===----------------------------------------------------------------------===// |
| 383 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 384 | bool GRStateManager::isEqual(const GRState* state, Expr* Ex, |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 385 | const llvm::APSInt& Y) { |
| 386 | |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 387 | RVal V = GetRVal(state, Ex); |
| 388 | |
| 389 | if (lval::ConcreteInt* X = dyn_cast<lval::ConcreteInt>(&V)) |
| 390 | return X->getValue() == Y; |
| 391 | |
| 392 | if (nonlval::ConcreteInt* X = dyn_cast<nonlval::ConcreteInt>(&V)) |
| 393 | return X->getValue() == Y; |
| 394 | |
| 395 | if (nonlval::SymbolVal* X = dyn_cast<nonlval::SymbolVal>(&V)) |
| 396 | return state->isEqual(X->getSymbol(), Y); |
| 397 | |
| 398 | if (lval::SymbolVal* X = dyn_cast<lval::SymbolVal>(&V)) |
| 399 | return state->isEqual(X->getSymbol(), Y); |
| 400 | |
| 401 | return false; |
| 402 | } |
| 403 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 404 | bool GRStateManager::isEqual(const GRState* state, Expr* Ex, uint64_t x) { |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 405 | return isEqual(state, Ex, BasicVals.getValue(x, Ex->getType())); |
| 406 | } |
| 407 | |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 408 | //===----------------------------------------------------------------------===// |
| 409 | // "Assume" logic. |
| 410 | //===----------------------------------------------------------------------===// |
| 411 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 412 | const GRState* GRStateManager::Assume(const GRState* St, LVal Cond, |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 413 | bool Assumption, bool& isFeasible) { |
| 414 | |
| 415 | St = AssumeAux(St, Cond, Assumption, isFeasible); |
| 416 | |
| 417 | return isFeasible ? TF->EvalAssume(*this, St, Cond, Assumption, isFeasible) |
| 418 | : St; |
| 419 | } |
| 420 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 421 | const GRState* GRStateManager::AssumeAux(const GRState* St, LVal Cond, |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 422 | bool Assumption, bool& isFeasible) { |
| 423 | |
| 424 | switch (Cond.getSubKind()) { |
| 425 | default: |
| 426 | assert (false && "'Assume' not implemented for this LVal."); |
| 427 | return St; |
| 428 | |
| 429 | case lval::SymbolValKind: |
| 430 | if (Assumption) |
| 431 | return AssumeSymNE(St, cast<lval::SymbolVal>(Cond).getSymbol(), |
| 432 | BasicVals.getZeroWithPtrWidth(), isFeasible); |
| 433 | else |
| 434 | return AssumeSymEQ(St, cast<lval::SymbolVal>(Cond).getSymbol(), |
| 435 | BasicVals.getZeroWithPtrWidth(), isFeasible); |
| 436 | |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 437 | case lval::DeclValKind: |
| 438 | case lval::FuncValKind: |
| 439 | case lval::GotoLabelKind: |
| 440 | case lval::StringLiteralValKind: |
| 441 | isFeasible = Assumption; |
| 442 | return St; |
| 443 | |
| 444 | case lval::FieldOffsetKind: |
| 445 | return AssumeAux(St, cast<lval::FieldOffset>(Cond).getBase(), |
| 446 | Assumption, isFeasible); |
| 447 | |
| 448 | case lval::ArrayOffsetKind: |
| 449 | return AssumeAux(St, cast<lval::ArrayOffset>(Cond).getBase(), |
| 450 | Assumption, isFeasible); |
| 451 | |
| 452 | case lval::ConcreteIntKind: { |
| 453 | bool b = cast<lval::ConcreteInt>(Cond).getValue() != 0; |
| 454 | isFeasible = b ? Assumption : !Assumption; |
| 455 | return St; |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 460 | const GRState* GRStateManager::Assume(const GRState* St, NonLVal Cond, |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 461 | bool Assumption, bool& isFeasible) { |
| 462 | |
| 463 | St = AssumeAux(St, Cond, Assumption, isFeasible); |
| 464 | |
| 465 | return isFeasible ? TF->EvalAssume(*this, St, Cond, Assumption, isFeasible) |
| 466 | : St; |
| 467 | } |
| 468 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 469 | const GRState* GRStateManager::AssumeAux(const GRState* St, NonLVal Cond, |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 470 | bool Assumption, bool& isFeasible) { |
| 471 | switch (Cond.getSubKind()) { |
| 472 | default: |
| 473 | assert (false && "'Assume' not implemented for this NonLVal."); |
| 474 | return St; |
| 475 | |
| 476 | |
| 477 | case nonlval::SymbolValKind: { |
| 478 | nonlval::SymbolVal& SV = cast<nonlval::SymbolVal>(Cond); |
| 479 | SymbolID sym = SV.getSymbol(); |
| 480 | |
| 481 | if (Assumption) |
| 482 | return AssumeSymNE(St, sym, BasicVals.getValue(0, SymMgr.getType(sym)), |
| 483 | isFeasible); |
| 484 | else |
| 485 | return AssumeSymEQ(St, sym, BasicVals.getValue(0, SymMgr.getType(sym)), |
| 486 | isFeasible); |
| 487 | } |
| 488 | |
| 489 | case nonlval::SymIntConstraintValKind: |
| 490 | return |
| 491 | AssumeSymInt(St, Assumption, |
| 492 | cast<nonlval::SymIntConstraintVal>(Cond).getConstraint(), |
| 493 | isFeasible); |
| 494 | |
| 495 | case nonlval::ConcreteIntKind: { |
| 496 | bool b = cast<nonlval::ConcreteInt>(Cond).getValue() != 0; |
| 497 | isFeasible = b ? Assumption : !Assumption; |
| 498 | return St; |
| 499 | } |
| 500 | |
| 501 | case nonlval::LValAsIntegerKind: { |
| 502 | return AssumeAux(St, cast<nonlval::LValAsInteger>(Cond).getLVal(), |
| 503 | Assumption, isFeasible); |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 508 | |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 509 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 510 | const GRState* GRStateManager::AssumeSymInt(const GRState* St, |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 511 | bool Assumption, |
| 512 | const SymIntConstraint& C, |
| 513 | bool& isFeasible) { |
| 514 | |
| 515 | switch (C.getOpcode()) { |
| 516 | default: |
| 517 | // No logic yet for other operators. |
| 518 | isFeasible = true; |
| 519 | return St; |
| 520 | |
| 521 | case BinaryOperator::EQ: |
| 522 | if (Assumption) |
| 523 | return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible); |
| 524 | else |
| 525 | return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible); |
| 526 | |
| 527 | case BinaryOperator::NE: |
| 528 | if (Assumption) |
| 529 | return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible); |
| 530 | else |
| 531 | return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible); |
Ted Kremenek | 2619be0 | 2008-08-07 22:30:22 +0000 | [diff] [blame] | 532 | |
| 533 | case BinaryOperator::GE: |
| 534 | if (Assumption) |
| 535 | return AssumeSymGE(St, C.getSymbol(), C.getInt(), isFeasible); |
| 536 | else |
| 537 | return AssumeSymLT(St, C.getSymbol(), C.getInt(), isFeasible); |
| 538 | |
| 539 | case BinaryOperator::LE: |
| 540 | if (Assumption) |
| 541 | return AssumeSymLE(St, C.getSymbol(), C.getInt(), isFeasible); |
| 542 | else |
| 543 | return AssumeSymGT(St, C.getSymbol(), C.getInt(), isFeasible); |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 544 | } |
| 545 | } |
Ted Kremenek | 2619be0 | 2008-08-07 22:30:22 +0000 | [diff] [blame] | 546 | |
| 547 | //===----------------------------------------------------------------------===// |
| 548 | // FIXME: This should go into a plug-in constraint engine. |
| 549 | //===----------------------------------------------------------------------===// |
| 550 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 551 | const GRState* |
| 552 | GRStateManager::AssumeSymNE(const GRState* St, SymbolID sym, |
Ted Kremenek | 2619be0 | 2008-08-07 22:30:22 +0000 | [diff] [blame] | 553 | const llvm::APSInt& V, bool& isFeasible) { |
| 554 | |
| 555 | // First, determine if sym == X, where X != V. |
| 556 | if (const llvm::APSInt* X = St->getSymVal(sym)) { |
| 557 | isFeasible = *X != V; |
| 558 | return St; |
| 559 | } |
| 560 | |
| 561 | // Second, determine if sym != V. |
| 562 | if (St->isNotEqual(sym, V)) { |
| 563 | isFeasible = true; |
| 564 | return St; |
| 565 | } |
| 566 | |
| 567 | // If we reach here, sym is not a constant and we don't know if it is != V. |
| 568 | // Make that assumption. |
| 569 | |
| 570 | isFeasible = true; |
| 571 | return AddNE(St, sym, V); |
| 572 | } |
| 573 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 574 | const GRState* |
| 575 | GRStateManager::AssumeSymEQ(const GRState* St, SymbolID sym, |
Ted Kremenek | 2619be0 | 2008-08-07 22:30:22 +0000 | [diff] [blame] | 576 | const llvm::APSInt& V, bool& isFeasible) { |
| 577 | |
| 578 | // First, determine if sym == X, where X != V. |
| 579 | if (const llvm::APSInt* X = St->getSymVal(sym)) { |
| 580 | isFeasible = *X == V; |
| 581 | return St; |
| 582 | } |
| 583 | |
| 584 | // Second, determine if sym != V. |
| 585 | if (St->isNotEqual(sym, V)) { |
| 586 | isFeasible = false; |
| 587 | return St; |
| 588 | } |
| 589 | |
| 590 | // If we reach here, sym is not a constant and we don't know if it is == V. |
| 591 | // Make that assumption. |
| 592 | |
| 593 | isFeasible = true; |
| 594 | return AddEQ(St, sym, V); |
| 595 | } |
| 596 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 597 | const GRState* |
| 598 | GRStateManager::AssumeSymLT(const GRState* St, SymbolID sym, |
Ted Kremenek | 2619be0 | 2008-08-07 22:30:22 +0000 | [diff] [blame] | 599 | const llvm::APSInt& V, bool& isFeasible) { |
| 600 | |
| 601 | // FIXME: For now have assuming x < y be the same as assuming sym != V; |
| 602 | return AssumeSymNE(St, sym, V, isFeasible); |
| 603 | } |
| 604 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 605 | const GRState* |
| 606 | GRStateManager::AssumeSymGT(const GRState* St, SymbolID sym, |
Ted Kremenek | 2619be0 | 2008-08-07 22:30:22 +0000 | [diff] [blame] | 607 | const llvm::APSInt& V, bool& isFeasible) { |
| 608 | |
| 609 | // FIXME: For now have assuming x > y be the same as assuming sym != V; |
| 610 | return AssumeSymNE(St, sym, V, isFeasible); |
| 611 | } |
| 612 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 613 | const GRState* |
| 614 | GRStateManager::AssumeSymGE(const GRState* St, SymbolID sym, |
Ted Kremenek | 2619be0 | 2008-08-07 22:30:22 +0000 | [diff] [blame] | 615 | const llvm::APSInt& V, bool& isFeasible) { |
| 616 | |
| 617 | // FIXME: Primitive logic for now. Only reject a path if the value of |
| 618 | // sym is a constant X and !(X >= V). |
| 619 | |
| 620 | if (const llvm::APSInt* X = St->getSymVal(sym)) { |
| 621 | isFeasible = *X >= V; |
| 622 | return St; |
| 623 | } |
| 624 | |
| 625 | isFeasible = true; |
| 626 | return St; |
| 627 | } |
| 628 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 629 | const GRState* |
| 630 | GRStateManager::AssumeSymLE(const GRState* St, SymbolID sym, |
Ted Kremenek | 2619be0 | 2008-08-07 22:30:22 +0000 | [diff] [blame] | 631 | const llvm::APSInt& V, bool& isFeasible) { |
| 632 | |
| 633 | // FIXME: Primitive logic for now. Only reject a path if the value of |
| 634 | // sym is a constant X and !(X <= V). |
| 635 | |
| 636 | if (const llvm::APSInt* X = St->getSymVal(sym)) { |
| 637 | isFeasible = *X <= V; |
| 638 | return St; |
| 639 | } |
| 640 | |
| 641 | isFeasible = true; |
| 642 | return St; |
| 643 | } |
| 644 | |