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