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 | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 10 | // This file defines SymbolRef, 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 | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 16 | #include "clang/Analysis/PathSensitive/GRTransferFuncs.h" |
Ted Kremenek | 05125f1 | 2008-08-27 23:13:01 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/SmallSet.h" |
Chris Lattner | 405674c | 2008-08-23 22:23:37 +0000 | [diff] [blame] | 18 | #include "llvm/Support/raw_ostream.h" |
Ted Kremenek | 05125f1 | 2008-08-27 23:13:01 +0000 | [diff] [blame] | 19 | |
Ted Kremenek | f66ea2cd | 2008-02-04 21:59:22 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
Ted Kremenek | 05125f1 | 2008-08-27 23:13:01 +0000 | [diff] [blame] | 22 | // Give the vtable for ConstraintManager somewhere to live. |
| 23 | ConstraintManager::~ConstraintManager() {} |
| 24 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 25 | GRStateManager::~GRStateManager() { |
| 26 | for (std::vector<GRState::Printer*>::iterator I=Printers.begin(), |
| 27 | E=Printers.end(); I!=E; ++I) |
| 28 | delete *I; |
| 29 | |
| 30 | for (GDMContextsTy::iterator I=GDMContexts.begin(), E=GDMContexts.end(); |
| 31 | I!=E; ++I) |
| 32 | I->second.second(I->second.first); |
| 33 | } |
| 34 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 35 | const GRState* |
Ted Kremenek | 2ed14be | 2008-12-05 00:47:52 +0000 | [diff] [blame] | 36 | GRStateManager::RemoveDeadBindings(const GRState* state, Stmt* Loc, |
Ted Kremenek | 241677a | 2009-01-21 22:26:05 +0000 | [diff] [blame] | 37 | SymbolReaper& SymReaper) { |
| 38 | |
Ted Kremenek | b87d909 | 2008-02-08 19:17:19 +0000 | [diff] [blame] | 39 | // This code essentially performs a "mark-and-sweep" of the VariableBindings. |
| 40 | // The roots are any Block-level exprs and Decls that our liveness algorithm |
| 41 | // tells us are live. We then see what Decls they may reference, and keep |
| 42 | // those around. This code more than likely can be made faster, and the |
| 43 | // frequency of which this method is called should be experimented with |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 44 | // for optimum performance. |
| 45 | llvm::SmallVector<const MemRegion*, 10> RegionRoots; |
Ted Kremenek | 2ed14be | 2008-12-05 00:47:52 +0000 | [diff] [blame] | 46 | GRState NewState = *state; |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 47 | |
Ted Kremenek | 5216ad7 | 2009-02-14 03:16:10 +0000 | [diff] [blame] | 48 | NewState.Env = EnvMgr.RemoveDeadBindings(NewState.Env, Loc, SymReaper, *this, |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 49 | state, RegionRoots); |
Ted Kremenek | 016f52f | 2008-02-08 21:10:02 +0000 | [diff] [blame] | 50 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 51 | // Clean up the store. |
Ted Kremenek | 241677a | 2009-01-21 22:26:05 +0000 | [diff] [blame] | 52 | NewState.St = StoreMgr->RemoveDeadBindings(&NewState, Loc, SymReaper, |
| 53 | RegionRoots); |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 54 | |
Ted Kremenek | 2ed14be | 2008-12-05 00:47:52 +0000 | [diff] [blame] | 55 | return ConstraintMgr->RemoveDeadBindings(getPersistentState(NewState), |
Ted Kremenek | 241677a | 2009-01-21 22:26:05 +0000 | [diff] [blame] | 56 | SymReaper); |
Ted Kremenek | b87d909 | 2008-02-08 19:17:19 +0000 | [diff] [blame] | 57 | } |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 58 | |
Ted Kremenek | 76500d0 | 2009-06-23 20:38:51 +0000 | [diff] [blame] | 59 | const GRState *GRState::unbindLoc(Loc LV) const { |
| 60 | Store OldStore = getStore(); |
| 61 | Store NewStore = Mgr->StoreMgr->Remove(OldStore, LV); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 62 | |
| 63 | if (NewStore == OldStore) |
Ted Kremenek | 76500d0 | 2009-06-23 20:38:51 +0000 | [diff] [blame] | 64 | return this; |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 65 | |
Ted Kremenek | 76500d0 | 2009-06-23 20:38:51 +0000 | [diff] [blame] | 66 | GRState NewSt = *this; |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 67 | NewSt.St = NewStore; |
Ted Kremenek | 76500d0 | 2009-06-23 20:38:51 +0000 | [diff] [blame] | 68 | return Mgr->getPersistentState(NewSt); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 71 | const GRState* GRStateManager::getInitialState() { |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 72 | GRState StateImpl(this, EnvMgr.getInitialEnvironment(), |
Zhongxing Xu | 6d69b5d | 2008-10-16 06:09:51 +0000 | [diff] [blame] | 73 | StoreMgr->getInitialStore(), |
Ted Kremenek | ffdbefd | 2008-08-17 03:10:22 +0000 | [diff] [blame] | 74 | GDMFactory.GetEmptyMap()); |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 75 | |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 76 | return getPersistentState(StateImpl); |
| 77 | } |
| 78 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 79 | const GRState* GRStateManager::getPersistentState(GRState& State) { |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 80 | |
| 81 | llvm::FoldingSetNodeID ID; |
| 82 | State.Profile(ID); |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 83 | void* InsertPos; |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 84 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 85 | if (GRState* I = StateSet.FindNodeOrInsertPos(ID, InsertPos)) |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 86 | return I; |
| 87 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 88 | GRState* I = (GRState*) Alloc.Allocate<GRState>(); |
| 89 | new (I) GRState(State); |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 90 | StateSet.InsertNode(I, InsertPos); |
| 91 | return I; |
| 92 | } |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 93 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 94 | const GRState* GRState::makeWithStore(Store store) const { |
| 95 | GRState NewSt = *this; |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 96 | NewSt.St = store; |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 97 | return Mgr->getPersistentState(NewSt); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 100 | //===----------------------------------------------------------------------===// |
| 101 | // State pretty-printing. |
| 102 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 461f977 | 2008-03-11 18:57:24 +0000 | [diff] [blame] | 103 | |
Ted Kremenek | b65be70 | 2009-06-18 01:23:53 +0000 | [diff] [blame] | 104 | void GRState::print(std::ostream& Out, const char* nl, const char* sep) const { |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 105 | // Print the store. |
Ted Kremenek | b65be70 | 2009-06-18 01:23:53 +0000 | [diff] [blame] | 106 | Mgr->getStoreManager().print(getStore(), Out, nl, sep); |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 107 | |
| 108 | // Print Subexpression bindings. |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 109 | bool isFirst = true; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 110 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 111 | for (seb_iterator I = seb_begin(), E = seb_end(); I != E; ++I) { |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 112 | |
| 113 | if (isFirst) { |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 114 | Out << nl << nl << "Sub-Expressions:" << nl; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 115 | isFirst = false; |
| 116 | } |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 117 | else { Out << nl; } |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 118 | |
| 119 | Out << " (" << (void*) I.getKey() << ") "; |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 120 | llvm::raw_os_ostream OutS(Out); |
| 121 | I.getKey()->printPretty(OutS); |
| 122 | OutS.flush(); |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 123 | Out << " : "; |
| 124 | I.getData().print(Out); |
| 125 | } |
| 126 | |
| 127 | // Print block-expression bindings. |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 128 | isFirst = true; |
| 129 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 130 | for (beb_iterator I = beb_begin(), E = beb_end(); I != E; ++I) { |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 131 | |
| 132 | if (isFirst) { |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 133 | Out << nl << nl << "Block-level Expressions:" << nl; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 134 | isFirst = false; |
| 135 | } |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 136 | else { Out << nl; } |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 137 | |
| 138 | Out << " (" << (void*) I.getKey() << ") "; |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 139 | llvm::raw_os_ostream OutS(Out); |
| 140 | I.getKey()->printPretty(OutS); |
| 141 | OutS.flush(); |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 142 | Out << " : "; |
| 143 | I.getData().print(Out); |
| 144 | } |
| 145 | |
Ted Kremenek | b65be70 | 2009-06-18 01:23:53 +0000 | [diff] [blame] | 146 | Mgr->getConstraintManager().print(this, Out, nl, sep); |
Ted Kremenek | 461f977 | 2008-03-11 18:57:24 +0000 | [diff] [blame] | 147 | |
Ted Kremenek | b65be70 | 2009-06-18 01:23:53 +0000 | [diff] [blame] | 148 | // Print checker-specific data. |
| 149 | for (std::vector<Printer*>::iterator I = Mgr->Printers.begin(), |
| 150 | E = Mgr->Printers.end(); I != E; ++I) { |
| 151 | (*I)->Print(Out, this, nl, sep); |
| 152 | } |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 153 | } |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 154 | |
Ted Kremenek | b65be70 | 2009-06-18 01:23:53 +0000 | [diff] [blame] | 155 | void GRState::printDOT(std::ostream& Out) const { |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 156 | print(Out, "\\l", "\\|"); |
| 157 | } |
| 158 | |
Ted Kremenek | b65be70 | 2009-06-18 01:23:53 +0000 | [diff] [blame] | 159 | void GRState::printStdErr() const { |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 160 | print(*llvm::cerr); |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Ted Kremenek | 72cd17f | 2008-08-14 21:16:54 +0000 | [diff] [blame] | 163 | //===----------------------------------------------------------------------===// |
| 164 | // Generic Data Map. |
| 165 | //===----------------------------------------------------------------------===// |
| 166 | |
| 167 | void* const* GRState::FindGDM(void* K) const { |
| 168 | return GDM.lookup(K); |
| 169 | } |
| 170 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 171 | void* |
| 172 | GRStateManager::FindGDMContext(void* K, |
| 173 | void* (*CreateContext)(llvm::BumpPtrAllocator&), |
| 174 | void (*DeleteContext)(void*)) { |
| 175 | |
| 176 | std::pair<void*, void (*)(void*)>& p = GDMContexts[K]; |
| 177 | if (!p.first) { |
| 178 | p.first = CreateContext(Alloc); |
| 179 | p.second = DeleteContext; |
| 180 | } |
| 181 | |
| 182 | return p.first; |
| 183 | } |
| 184 | |
Zhongxing Xu | 4230da6 | 2008-11-03 05:18:34 +0000 | [diff] [blame] | 185 | const GRState* GRStateManager::addGDM(const GRState* St, void* Key, void* Data){ |
Ted Kremenek | 72cd17f | 2008-08-14 21:16:54 +0000 | [diff] [blame] | 186 | GRState::GenericDataMap M1 = St->getGDM(); |
| 187 | GRState::GenericDataMap M2 = GDMFactory.Add(M1, Key, Data); |
| 188 | |
| 189 | if (M1 == M2) |
| 190 | return St; |
| 191 | |
| 192 | GRState NewSt = *St; |
| 193 | NewSt.GDM = M2; |
| 194 | return getPersistentState(NewSt); |
| 195 | } |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 196 | |
| 197 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 5216ad7 | 2009-02-14 03:16:10 +0000 | [diff] [blame] | 198 | // Utility. |
| 199 | //===----------------------------------------------------------------------===// |
| 200 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 201 | namespace { |
Zhongxing Xu | 63d1d60 | 2009-03-04 06:33:38 +0000 | [diff] [blame] | 202 | class VISIBILITY_HIDDEN ScanReachableSymbols : public SubRegionMap::Visitor { |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 203 | typedef llvm::DenseSet<const MemRegion*> VisitedRegionsTy; |
| 204 | |
| 205 | VisitedRegionsTy visited; |
Ted Kremenek | 47fed90 | 2009-06-18 01:33:24 +0000 | [diff] [blame] | 206 | const GRState *state; |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 207 | SymbolVisitor &visitor; |
| 208 | llvm::OwningPtr<SubRegionMap> SRM; |
| 209 | public: |
| 210 | |
Ted Kremenek | 47fed90 | 2009-06-18 01:33:24 +0000 | [diff] [blame] | 211 | ScanReachableSymbols(const GRState *st, SymbolVisitor& v) |
| 212 | : state(st), visitor(v) {} |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 213 | |
| 214 | bool scan(nonloc::CompoundVal val); |
| 215 | bool scan(SVal val); |
| 216 | bool scan(const MemRegion *R); |
| 217 | |
| 218 | // From SubRegionMap::Visitor. |
| 219 | bool Visit(const MemRegion* Parent, const MemRegion* SubRegion) { |
| 220 | return scan(SubRegion); |
| 221 | } |
| 222 | }; |
| 223 | } |
| 224 | |
| 225 | bool ScanReachableSymbols::scan(nonloc::CompoundVal val) { |
Ted Kremenek | 5216ad7 | 2009-02-14 03:16:10 +0000 | [diff] [blame] | 226 | for (nonloc::CompoundVal::iterator I=val.begin(), E=val.end(); I!=E; ++I) |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 227 | if (!scan(*I)) |
| 228 | return false; |
Ted Kremenek | 5216ad7 | 2009-02-14 03:16:10 +0000 | [diff] [blame] | 229 | |
| 230 | return true; |
| 231 | } |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 232 | |
| 233 | bool ScanReachableSymbols::scan(SVal val) { |
| 234 | if (loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(&val)) |
| 235 | return scan(X->getRegion()); |
Ted Kremenek | 380022d | 2009-03-30 18:45:36 +0000 | [diff] [blame] | 236 | |
| 237 | if (SymbolRef Sym = val.getAsSymbol()) |
| 238 | return visitor.VisitSymbol(Sym); |
Ted Kremenek | 5216ad7 | 2009-02-14 03:16:10 +0000 | [diff] [blame] | 239 | |
| 240 | if (nonloc::CompoundVal *X = dyn_cast<nonloc::CompoundVal>(&val)) |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 241 | return scan(*X); |
Ted Kremenek | 5216ad7 | 2009-02-14 03:16:10 +0000 | [diff] [blame] | 242 | |
| 243 | return true; |
| 244 | } |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 245 | |
| 246 | bool ScanReachableSymbols::scan(const MemRegion *R) { |
Ted Kremenek | 1cb151e | 2009-03-04 00:13:10 +0000 | [diff] [blame] | 247 | if (isa<MemSpaceRegion>(R) || visited.count(R)) |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 248 | return true; |
| 249 | |
| 250 | visited.insert(R); |
| 251 | |
| 252 | // If this is a symbolic region, visit the symbol for the region. |
| 253 | if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R)) |
| 254 | if (!visitor.VisitSymbol(SR->getSymbol())) |
| 255 | return false; |
| 256 | |
| 257 | // If this is a subregion, also visit the parent regions. |
| 258 | if (const SubRegion *SR = dyn_cast<SubRegion>(R)) |
Ted Kremenek | 6076e0a | 2009-03-03 18:15:30 +0000 | [diff] [blame] | 259 | if (!scan(SR->getSuperRegion())) |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 260 | return false; |
| 261 | |
| 262 | // Now look at the binding to this region (if any). |
Ted Kremenek | 47fed90 | 2009-06-18 01:33:24 +0000 | [diff] [blame] | 263 | if (!scan(state->getSValAsScalarOrLoc(R))) |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 264 | return false; |
| 265 | |
| 266 | // Now look at the subregions. |
| 267 | if (!SRM.get()) |
Ted Kremenek | 47fed90 | 2009-06-18 01:33:24 +0000 | [diff] [blame] | 268 | SRM.reset(state->getStateManager().getStoreManager().getSubRegionMap(state)); |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 269 | |
| 270 | return SRM->iterSubRegions(R, *this); |
| 271 | } |
| 272 | |
Ted Kremenek | 47fed90 | 2009-06-18 01:33:24 +0000 | [diff] [blame] | 273 | bool GRState::scanReachableSymbols(SVal val, SymbolVisitor& visitor) const { |
| 274 | ScanReachableSymbols S(this, visitor); |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 275 | return S.scan(val); |
| 276 | } |
Ted Kremenek | 5216ad7 | 2009-02-14 03:16:10 +0000 | [diff] [blame] | 277 | |
| 278 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 279 | // Queries. |
| 280 | //===----------------------------------------------------------------------===// |
| 281 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 282 | bool GRStateManager::isEqual(const GRState* state, Expr* Ex, |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 283 | const llvm::APSInt& Y) { |
| 284 | |
Ted Kremenek | dbc2afc | 2009-06-23 17:55:07 +0000 | [diff] [blame] | 285 | SVal V = state->getSVal(Ex); |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 286 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 287 | if (loc::ConcreteInt* X = dyn_cast<loc::ConcreteInt>(&V)) |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 288 | return X->getValue() == Y; |
| 289 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 290 | if (nonloc::ConcreteInt* X = dyn_cast<nonloc::ConcreteInt>(&V)) |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 291 | return X->getValue() == Y; |
| 292 | |
Ted Kremenek | 380022d | 2009-03-30 18:45:36 +0000 | [diff] [blame] | 293 | if (SymbolRef Sym = V.getAsSymbol()) |
| 294 | return ConstraintMgr->isEqual(state, Sym, Y); |
| 295 | |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 296 | return false; |
| 297 | } |
| 298 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 299 | bool GRStateManager::isEqual(const GRState* state, Expr* Ex, uint64_t x) { |
Ted Kremenek | 044b6f0 | 2009-04-09 16:13:17 +0000 | [diff] [blame] | 300 | return isEqual(state, Ex, getBasicVals().getValue(x, Ex->getType())); |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 301 | } |
Ted Kremenek | 7360fda | 2008-09-18 23:09:54 +0000 | [diff] [blame] | 302 | |
| 303 | //===----------------------------------------------------------------------===// |
| 304 | // Persistent values for indexing into the Generic Data Map. |
| 305 | |
| 306 | int GRState::NullDerefTag::TagInt = 0; |
| 307 | |