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