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 | |
Benjamin Kramer | 5e2d2c2 | 2010-03-27 21:19:47 +0000 | [diff] [blame] | 14 | #include "clang/Analysis/CFG.h" |
Argyrios Kyrtzidis | 98cabba | 2010-12-22 18:51:49 +0000 | [diff] [blame] | 15 | #include "clang/GR/PathSensitive/GRStateTrait.h" |
| 16 | #include "clang/GR/PathSensitive/GRState.h" |
Argyrios Kyrtzidis | d2592a3 | 2010-12-22 18:53:44 +0000 | [diff] [blame^] | 17 | #include "clang/GR/PathSensitive/SubEngine.h" |
| 18 | #include "clang/GR/PathSensitive/TransferFuncs.h" |
Chris Lattner | 405674c | 2008-08-23 22:23:37 +0000 | [diff] [blame] | 19 | #include "llvm/Support/raw_ostream.h" |
Ted Kremenek | 05125f1 | 2008-08-27 23:13:01 +0000 | [diff] [blame] | 20 | |
Ted Kremenek | f66ea2cd | 2008-02-04 21:59:22 +0000 | [diff] [blame] | 21 | using namespace clang; |
Argyrios Kyrtzidis | 5a4f98f | 2010-12-22 18:53:20 +0000 | [diff] [blame] | 22 | using namespace GR; |
Ted Kremenek | f66ea2cd | 2008-02-04 21:59:22 +0000 | [diff] [blame] | 23 | |
Ted Kremenek | 05125f1 | 2008-08-27 23:13:01 +0000 | [diff] [blame] | 24 | // Give the vtable for ConstraintManager somewhere to live. |
Ted Kremenek | 53ba0b6 | 2009-06-24 23:06:47 +0000 | [diff] [blame] | 25 | // FIXME: Move this elsewhere. |
Ted Kremenek | 05125f1 | 2008-08-27 23:13:01 +0000 | [diff] [blame] | 26 | ConstraintManager::~ConstraintManager() {} |
| 27 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 28 | GRStateManager::~GRStateManager() { |
| 29 | for (std::vector<GRState::Printer*>::iterator I=Printers.begin(), |
| 30 | E=Printers.end(); I!=E; ++I) |
| 31 | delete *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 32 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 33 | for (GDMContextsTy::iterator I=GDMContexts.begin(), E=GDMContexts.end(); |
| 34 | I!=E; ++I) |
| 35 | I->second.second(I->second.first); |
| 36 | } |
| 37 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 38 | const GRState* |
Jordy Rose | 7dadf79 | 2010-07-01 20:09:55 +0000 | [diff] [blame] | 39 | GRStateManager::RemoveDeadBindings(const GRState* state, |
Zhongxing Xu | 17ddf1c | 2010-03-17 03:35:08 +0000 | [diff] [blame] | 40 | const StackFrameContext *LCtx, |
Ted Kremenek | 241677a | 2009-01-21 22:26:05 +0000 | [diff] [blame] | 41 | SymbolReaper& SymReaper) { |
| 42 | |
Ted Kremenek | b87d909 | 2008-02-08 19:17:19 +0000 | [diff] [blame] | 43 | // This code essentially performs a "mark-and-sweep" of the VariableBindings. |
| 44 | // The roots are any Block-level exprs and Decls that our liveness algorithm |
| 45 | // tells us are live. We then see what Decls they may reference, and keep |
| 46 | // those around. This code more than likely can be made faster, and the |
| 47 | // frequency of which this method is called should be experimented with |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 48 | // for optimum performance. |
| 49 | llvm::SmallVector<const MemRegion*, 10> RegionRoots; |
Ted Kremenek | 2ed14be | 2008-12-05 00:47:52 +0000 | [diff] [blame] | 50 | GRState NewState = *state; |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 51 | |
Jordy Rose | 7dadf79 | 2010-07-01 20:09:55 +0000 | [diff] [blame] | 52 | NewState.Env = EnvMgr.RemoveDeadBindings(NewState.Env, SymReaper, |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 53 | state, RegionRoots); |
Ted Kremenek | 016f52f | 2008-02-08 21:10:02 +0000 | [diff] [blame] | 54 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 55 | // Clean up the store. |
Zhongxing Xu | 5e4cb34 | 2010-08-15 12:45:09 +0000 | [diff] [blame] | 56 | NewState.St = StoreMgr->RemoveDeadBindings(NewState.St, LCtx, |
| 57 | SymReaper, RegionRoots); |
| 58 | state = getPersistentState(NewState); |
| 59 | return ConstraintMgr->RemoveDeadBindings(state, SymReaper); |
Ted Kremenek | b87d909 | 2008-02-08 19:17:19 +0000 | [diff] [blame] | 60 | } |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 61 | |
Zhongxing Xu | 2ce43c8 | 2010-07-22 13:52:13 +0000 | [diff] [blame] | 62 | const GRState *GRStateManager::MarshalState(const GRState *state, |
Zhongxing Xu | d5ef7b2 | 2010-07-23 05:55:01 +0000 | [diff] [blame] | 63 | const StackFrameContext *InitLoc) { |
Zhongxing Xu | 2ce43c8 | 2010-07-22 13:52:13 +0000 | [diff] [blame] | 64 | // make up an empty state for now. |
| 65 | GRState State(this, |
| 66 | EnvMgr.getInitialEnvironment(), |
| 67 | StoreMgr->getInitialStore(InitLoc), |
Ted Kremenek | 3baf672 | 2010-11-24 00:54:37 +0000 | [diff] [blame] | 68 | GDMFactory.getEmptyMap()); |
Zhongxing Xu | 2ce43c8 | 2010-07-22 13:52:13 +0000 | [diff] [blame] | 69 | |
| 70 | return getPersistentState(State); |
| 71 | } |
| 72 | |
Jordy Rose | 52082af | 2010-08-15 22:19:33 +0000 | [diff] [blame] | 73 | const GRState *GRState::bindCompoundLiteral(const CompoundLiteralExpr* CL, |
| 74 | const LocationContext *LC, |
| 75 | SVal V) const { |
| 76 | Store new_store = |
| 77 | getStateManager().StoreMgr->BindCompoundLiteral(St, CL, LC, V); |
| 78 | return makeWithStore(new_store); |
| 79 | } |
| 80 | |
| 81 | const GRState *GRState::bindDecl(const VarRegion* VR, SVal IVal) const { |
| 82 | Store new_store = getStateManager().StoreMgr->BindDecl(St, VR, IVal); |
| 83 | return makeWithStore(new_store); |
| 84 | } |
| 85 | |
| 86 | const GRState *GRState::bindDeclWithNoInit(const VarRegion* VR) const { |
| 87 | Store new_store = getStateManager().StoreMgr->BindDeclWithNoInit(St, VR); |
| 88 | return makeWithStore(new_store); |
| 89 | } |
| 90 | |
| 91 | const GRState *GRState::bindLoc(Loc LV, SVal V) const { |
| 92 | GRStateManager &Mgr = getStateManager(); |
| 93 | Store new_store = Mgr.StoreMgr->Bind(St, LV, V); |
| 94 | const GRState *new_state = makeWithStore(new_store); |
| 95 | |
| 96 | const MemRegion *MR = LV.getAsRegion(); |
| 97 | if (MR) |
| 98 | return Mgr.getOwningEngine().ProcessRegionChange(new_state, MR); |
| 99 | |
| 100 | return new_state; |
| 101 | } |
| 102 | |
| 103 | const GRState *GRState::bindDefault(SVal loc, SVal V) const { |
| 104 | GRStateManager &Mgr = getStateManager(); |
| 105 | const MemRegion *R = cast<loc::MemRegionVal>(loc).getRegion(); |
| 106 | Store new_store = Mgr.StoreMgr->BindDefault(St, R, V); |
| 107 | const GRState *new_state = makeWithStore(new_store); |
| 108 | return Mgr.getOwningEngine().ProcessRegionChange(new_state, R); |
| 109 | } |
| 110 | |
| 111 | const GRState *GRState::InvalidateRegions(const MemRegion * const *Begin, |
| 112 | const MemRegion * const *End, |
| 113 | const Expr *E, unsigned Count, |
| 114 | StoreManager::InvalidatedSymbols *IS, |
| 115 | bool invalidateGlobals) const { |
| 116 | GRStateManager &Mgr = getStateManager(); |
Argyrios Kyrtzidis | d2592a3 | 2010-12-22 18:53:44 +0000 | [diff] [blame^] | 117 | SubEngine &Eng = Mgr.getOwningEngine(); |
Jordy Rose | 52082af | 2010-08-15 22:19:33 +0000 | [diff] [blame] | 118 | |
| 119 | if (Eng.WantsRegionChangeUpdate(this)) { |
| 120 | StoreManager::InvalidatedRegions Regions; |
| 121 | |
| 122 | Store new_store = Mgr.StoreMgr->InvalidateRegions(St, Begin, End, |
| 123 | E, Count, IS, |
| 124 | invalidateGlobals, |
| 125 | &Regions); |
| 126 | const GRState *new_state = makeWithStore(new_store); |
| 127 | |
| 128 | return Eng.ProcessRegionChanges(new_state, |
| 129 | &Regions.front(), |
| 130 | &Regions.back()+1); |
| 131 | } |
| 132 | |
| 133 | Store new_store = Mgr.StoreMgr->InvalidateRegions(St, Begin, End, |
| 134 | E, Count, IS, |
| 135 | invalidateGlobals, |
| 136 | NULL); |
| 137 | return makeWithStore(new_store); |
| 138 | } |
| 139 | |
Ted Kremenek | 76500d0 | 2009-06-23 20:38:51 +0000 | [diff] [blame] | 140 | const GRState *GRState::unbindLoc(Loc LV) const { |
Jordy Rose | a9c7621 | 2010-08-05 03:33:56 +0000 | [diff] [blame] | 141 | assert(!isa<loc::MemRegionVal>(LV) && "Use InvalidateRegion instead."); |
| 142 | |
Ted Kremenek | 76500d0 | 2009-06-23 20:38:51 +0000 | [diff] [blame] | 143 | Store OldStore = getStore(); |
Ted Kremenek | 0fb0bc4 | 2009-08-27 01:39:13 +0000 | [diff] [blame] | 144 | Store NewStore = getStateManager().StoreMgr->Remove(OldStore, LV); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 145 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 146 | if (NewStore == OldStore) |
Ted Kremenek | 76500d0 | 2009-06-23 20:38:51 +0000 | [diff] [blame] | 147 | return this; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 148 | |
Jordy Rose | a9c7621 | 2010-08-05 03:33:56 +0000 | [diff] [blame] | 149 | return makeWithStore(NewStore); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Jordy Rose | 52082af | 2010-08-15 22:19:33 +0000 | [diff] [blame] | 152 | const GRState *GRState::EnterStackFrame(const StackFrameContext *frame) const { |
| 153 | Store new_store = getStateManager().StoreMgr->EnterStackFrame(this, frame); |
| 154 | return makeWithStore(new_store); |
| 155 | } |
| 156 | |
Ted Kremenek | 1397663 | 2010-02-08 16:18:51 +0000 | [diff] [blame] | 157 | SVal GRState::getSValAsScalarOrLoc(const MemRegion *R) const { |
Ted Kremenek | 233e913 | 2009-06-24 22:15:30 +0000 | [diff] [blame] | 158 | // We only want to do fetches from regions that we can actually bind |
| 159 | // values. For example, SymbolicRegions of type 'id<...>' cannot |
| 160 | // have direct bindings (but their can be bindings on their subregions). |
| 161 | if (!R->isBoundable()) |
| 162 | return UnknownVal(); |
| 163 | |
| 164 | if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) { |
Zhongxing Xu | 018220c | 2010-08-11 06:10:55 +0000 | [diff] [blame] | 165 | QualType T = TR->getValueType(); |
Ted Kremenek | 233e913 | 2009-06-24 22:15:30 +0000 | [diff] [blame] | 166 | if (Loc::IsLocType(T) || T->isIntegerType()) |
Ted Kremenek | 1397663 | 2010-02-08 16:18:51 +0000 | [diff] [blame] | 167 | return getSVal(R); |
Ted Kremenek | 233e913 | 2009-06-24 22:15:30 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | return UnknownVal(); |
| 171 | } |
| 172 | |
Ted Kremenek | 96ebad6 | 2010-09-09 07:13:00 +0000 | [diff] [blame] | 173 | SVal GRState::getSVal(Loc location, QualType T) const { |
| 174 | SVal V = getRawSVal(cast<Loc>(location), T); |
| 175 | |
Ted Kremenek | 124f5d5 | 2010-09-03 01:06:58 +0000 | [diff] [blame] | 176 | // If 'V' is a symbolic value that is *perfectly* constrained to |
| 177 | // be a constant value, use that value instead to lessen the burden |
| 178 | // on later analysis stages (so we have less symbolic values to reason |
| 179 | // about). |
| 180 | if (!T.isNull()) { |
| 181 | if (SymbolRef sym = V.getAsSymbol()) { |
| 182 | if (const llvm::APSInt *Int = getSymVal(sym)) { |
| 183 | // FIXME: Because we don't correctly model (yet) sign-extension |
| 184 | // and truncation of symbolic values, we need to convert |
| 185 | // the integer value to the correct signedness and bitwidth. |
| 186 | // |
| 187 | // This shows up in the following: |
| 188 | // |
| 189 | // char foo(); |
| 190 | // unsigned x = foo(); |
| 191 | // if (x == 54) |
| 192 | // ... |
| 193 | // |
| 194 | // The symbolic value stored to 'x' is actually the conjured |
| 195 | // symbol for the call to foo(); the type of that symbol is 'char', |
| 196 | // not unsigned. |
| 197 | const llvm::APSInt &NewV = getBasicVals().Convert(T, *Int); |
| 198 | |
| 199 | if (isa<Loc>(V)) |
| 200 | return loc::ConcreteInt(NewV); |
| 201 | else |
| 202 | return nonloc::ConcreteInt(NewV); |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | return V; |
| 208 | } |
Ted Kremenek | 4f596c2 | 2009-06-27 00:24:54 +0000 | [diff] [blame] | 209 | |
Ted Kremenek | 6d4c022 | 2010-09-03 01:07:02 +0000 | [diff] [blame] | 210 | const GRState *GRState::BindExpr(const Stmt* S, SVal V, bool Invalidate) const{ |
| 211 | Environment NewEnv = getStateManager().EnvMgr.bindExpr(Env, S, V, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 212 | Invalidate); |
Ted Kremenek | 4f596c2 | 2009-06-27 00:24:54 +0000 | [diff] [blame] | 213 | if (NewEnv == Env) |
| 214 | return this; |
Ted Kremenek | 6d2c657 | 2009-08-27 22:15:20 +0000 | [diff] [blame] | 215 | |
Ted Kremenek | 4f596c2 | 2009-06-27 00:24:54 +0000 | [diff] [blame] | 216 | GRState NewSt = *this; |
| 217 | NewSt.Env = NewEnv; |
Ted Kremenek | 0fb0bc4 | 2009-08-27 01:39:13 +0000 | [diff] [blame] | 218 | return getStateManager().getPersistentState(NewSt); |
Ted Kremenek | 4f596c2 | 2009-06-27 00:24:54 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Ted Kremenek | 6d4c022 | 2010-09-03 01:07:02 +0000 | [diff] [blame] | 221 | const GRState *GRState::bindExprAndLocation(const Stmt *S, SVal location, |
| 222 | SVal V) const { |
| 223 | Environment NewEnv = |
| 224 | getStateManager().EnvMgr.bindExprAndLocation(Env, S, location, V); |
| 225 | |
| 226 | if (NewEnv == Env) |
| 227 | return this; |
| 228 | |
| 229 | GRState NewSt = *this; |
| 230 | NewSt.Env = NewEnv; |
| 231 | return getStateManager().getPersistentState(NewSt); |
| 232 | } |
| 233 | |
Ted Kremenek | 28f47b9 | 2010-12-01 22:16:56 +0000 | [diff] [blame] | 234 | const GRState *GRState::assumeInBound(DefinedOrUnknownSVal Idx, |
Jordy Rose | 1802eeb | 2010-08-16 20:34:06 +0000 | [diff] [blame] | 235 | DefinedOrUnknownSVal UpperBound, |
| 236 | bool Assumption) const { |
| 237 | if (Idx.isUnknown() || UpperBound.isUnknown()) |
| 238 | return this; |
| 239 | |
| 240 | // Build an expression for 0 <= Idx < UpperBound. |
| 241 | // This is the same as Idx + MIN < UpperBound + MIN, if overflow is allowed. |
Ted Kremenek | 846eabd | 2010-12-01 21:28:31 +0000 | [diff] [blame] | 242 | // FIXME: This should probably be part of SValBuilder. |
Jordy Rose | 1802eeb | 2010-08-16 20:34:06 +0000 | [diff] [blame] | 243 | GRStateManager &SM = getStateManager(); |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 244 | SValBuilder &svalBuilder = SM.getSValBuilder(); |
| 245 | ASTContext &Ctx = svalBuilder.getContext(); |
Jordy Rose | 1802eeb | 2010-08-16 20:34:06 +0000 | [diff] [blame] | 246 | |
| 247 | // Get the offset: the minimum value of the array index type. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 248 | BasicValueFactory &BVF = svalBuilder.getBasicValueFactory(); |
| 249 | // FIXME: This should be using ValueManager::ArrayindexTy...somehow. |
| 250 | QualType indexTy = Ctx.IntTy; |
Ted Kremenek | 0074b48 | 2010-12-05 23:36:20 +0000 | [diff] [blame] | 251 | nonloc::ConcreteInt Min(BVF.getMinValue(indexTy)); |
Jordy Rose | 1802eeb | 2010-08-16 20:34:06 +0000 | [diff] [blame] | 252 | |
| 253 | // Adjust the index. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 254 | SVal newIdx = svalBuilder.evalBinOpNN(this, BO_Add, |
| 255 | cast<NonLoc>(Idx), Min, indexTy); |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 256 | if (newIdx.isUnknownOrUndef()) |
Jordy Rose | 1802eeb | 2010-08-16 20:34:06 +0000 | [diff] [blame] | 257 | return this; |
| 258 | |
| 259 | // Adjust the upper bound. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 260 | SVal newBound = |
| 261 | svalBuilder.evalBinOpNN(this, BO_Add, cast<NonLoc>(UpperBound), |
| 262 | Min, indexTy); |
| 263 | |
| 264 | if (newBound.isUnknownOrUndef()) |
Jordy Rose | 1802eeb | 2010-08-16 20:34:06 +0000 | [diff] [blame] | 265 | return this; |
| 266 | |
| 267 | // Build the actual comparison. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 268 | SVal inBound = svalBuilder.evalBinOpNN(this, BO_LT, |
| 269 | cast<NonLoc>(newIdx), cast<NonLoc>(newBound), |
Jordy Rose | 1802eeb | 2010-08-16 20:34:06 +0000 | [diff] [blame] | 270 | Ctx.IntTy); |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 271 | if (inBound.isUnknownOrUndef()) |
Jordy Rose | 1802eeb | 2010-08-16 20:34:06 +0000 | [diff] [blame] | 272 | return this; |
| 273 | |
| 274 | // Finally, let the constraint manager take care of it. |
| 275 | ConstraintManager &CM = SM.getConstraintManager(); |
Ted Kremenek | 28f47b9 | 2010-12-01 22:16:56 +0000 | [diff] [blame] | 276 | return CM.assume(this, cast<DefinedSVal>(inBound), Assumption); |
Jordy Rose | 1802eeb | 2010-08-16 20:34:06 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Zhongxing Xu | 17fd863 | 2009-08-17 06:19:58 +0000 | [diff] [blame] | 279 | const GRState* GRStateManager::getInitialState(const LocationContext *InitLoc) { |
Ted Kremenek | 6d2c657 | 2009-08-27 22:15:20 +0000 | [diff] [blame] | 280 | GRState State(this, |
Zhongxing Xu | c179a7f | 2010-03-05 04:45:36 +0000 | [diff] [blame] | 281 | EnvMgr.getInitialEnvironment(), |
Zhongxing Xu | 17fd863 | 2009-08-17 06:19:58 +0000 | [diff] [blame] | 282 | StoreMgr->getInitialStore(InitLoc), |
Ted Kremenek | 3baf672 | 2010-11-24 00:54:37 +0000 | [diff] [blame] | 283 | GDMFactory.getEmptyMap()); |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 284 | |
Zhongxing Xu | 17fd863 | 2009-08-17 06:19:58 +0000 | [diff] [blame] | 285 | return getPersistentState(State); |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 288 | const GRState* GRStateManager::getPersistentState(GRState& State) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 290 | llvm::FoldingSetNodeID ID; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 291 | State.Profile(ID); |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 292 | void* InsertPos; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 294 | if (GRState* I = StateSet.FindNodeOrInsertPos(ID, InsertPos)) |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 295 | return I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 296 | |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 297 | GRState* I = (GRState*) Alloc.Allocate<GRState>(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 298 | new (I) GRState(State); |
Ted Kremenek | 9153f73 | 2008-02-05 07:17:49 +0000 | [diff] [blame] | 299 | StateSet.InsertNode(I, InsertPos); |
| 300 | return I; |
| 301 | } |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 302 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 303 | const GRState* GRState::makeWithStore(Store store) const { |
| 304 | GRState NewSt = *this; |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 305 | NewSt.St = store; |
Ted Kremenek | 0fb0bc4 | 2009-08-27 01:39:13 +0000 | [diff] [blame] | 306 | return getStateManager().getPersistentState(NewSt); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 309 | //===----------------------------------------------------------------------===// |
| 310 | // State pretty-printing. |
| 311 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 461f977 | 2008-03-11 18:57:24 +0000 | [diff] [blame] | 312 | |
Ted Kremenek | 6d4c022 | 2010-09-03 01:07:02 +0000 | [diff] [blame] | 313 | static bool IsEnvLoc(const Stmt *S) { |
| 314 | // FIXME: This is a layering violation. Should be in environment. |
| 315 | return (bool) (((uintptr_t) S) & 0x1); |
| 316 | } |
| 317 | |
Zhongxing Xu | c179a7f | 2010-03-05 04:45:36 +0000 | [diff] [blame] | 318 | void GRState::print(llvm::raw_ostream& Out, CFG &C, const char* nl, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 319 | const char* sep) const { |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 320 | // Print the store. |
Ted Kremenek | 0fb0bc4 | 2009-08-27 01:39:13 +0000 | [diff] [blame] | 321 | GRStateManager &Mgr = getStateManager(); |
| 322 | Mgr.getStoreManager().print(getStore(), Out, nl, sep); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 323 | |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 324 | // Print Subexpression bindings. |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 325 | bool isFirst = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 326 | |
Ted Kremenek | 6d4c022 | 2010-09-03 01:07:02 +0000 | [diff] [blame] | 327 | // FIXME: All environment printing should be moved inside Environment. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 328 | for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) { |
Ted Kremenek | 6d4c022 | 2010-09-03 01:07:02 +0000 | [diff] [blame] | 329 | if (C.isBlkExpr(I.getKey()) || IsEnvLoc(I.getKey())) |
Ted Kremenek | 0fb0bc4 | 2009-08-27 01:39:13 +0000 | [diff] [blame] | 330 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 331 | |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 332 | if (isFirst) { |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 333 | Out << nl << nl << "Sub-Expressions:" << nl; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 334 | isFirst = false; |
| 335 | } |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 336 | else { Out << nl; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 337 | |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 338 | Out << " (" << (void*) I.getKey() << ") "; |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 339 | LangOptions LO; // FIXME. |
| 340 | I.getKey()->printPretty(Out, 0, PrintingPolicy(LO)); |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 341 | Out << " : " << I.getData(); |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 342 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 343 | |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 344 | // Print block-expression bindings. |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 345 | isFirst = true; |
Ted Kremenek | 0fb0bc4 | 2009-08-27 01:39:13 +0000 | [diff] [blame] | 346 | |
| 347 | for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) { |
| 348 | if (!C.isBlkExpr(I.getKey())) |
| 349 | continue; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 350 | |
| 351 | if (isFirst) { |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 352 | Out << nl << nl << "Block-level Expressions:" << nl; |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 353 | isFirst = false; |
| 354 | } |
Ted Kremenek | 59894f9 | 2008-03-04 18:30:35 +0000 | [diff] [blame] | 355 | else { Out << nl; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 357 | Out << " (" << (void*) I.getKey() << ") "; |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 358 | LangOptions LO; // FIXME. |
| 359 | I.getKey()->printPretty(Out, 0, PrintingPolicy(LO)); |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 360 | Out << " : " << I.getData(); |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 361 | } |
Ted Kremenek | 6d4c022 | 2010-09-03 01:07:02 +0000 | [diff] [blame] | 362 | |
| 363 | // Print locations. |
| 364 | isFirst = true; |
| 365 | |
| 366 | for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) { |
| 367 | if (!IsEnvLoc(I.getKey())) |
| 368 | continue; |
| 369 | |
| 370 | if (isFirst) { |
| 371 | Out << nl << nl << "Load/store locations:" << nl; |
| 372 | isFirst = false; |
| 373 | } |
| 374 | else { Out << nl; } |
| 375 | |
| 376 | const Stmt *S = (Stmt*) (((uintptr_t) I.getKey()) & ((uintptr_t) ~0x1)); |
| 377 | |
| 378 | Out << " (" << (void*) S << ") "; |
| 379 | LangOptions LO; // FIXME. |
| 380 | S->printPretty(Out, 0, PrintingPolicy(LO)); |
| 381 | Out << " : " << I.getData(); |
| 382 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 383 | |
Ted Kremenek | 0fb0bc4 | 2009-08-27 01:39:13 +0000 | [diff] [blame] | 384 | Mgr.getConstraintManager().print(this, Out, nl, sep); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 385 | |
Ted Kremenek | b65be70 | 2009-06-18 01:23:53 +0000 | [diff] [blame] | 386 | // Print checker-specific data. |
Ted Kremenek | 0fb0bc4 | 2009-08-27 01:39:13 +0000 | [diff] [blame] | 387 | for (std::vector<Printer*>::iterator I = Mgr.Printers.begin(), |
| 388 | E = Mgr.Printers.end(); I != E; ++I) { |
Ted Kremenek | b65be70 | 2009-06-18 01:23:53 +0000 | [diff] [blame] | 389 | (*I)->Print(Out, this, nl, sep); |
| 390 | } |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 391 | } |
Ted Kremenek | 729a9a2 | 2008-07-17 23:15:45 +0000 | [diff] [blame] | 392 | |
Zhongxing Xu | c179a7f | 2010-03-05 04:45:36 +0000 | [diff] [blame] | 393 | void GRState::printDOT(llvm::raw_ostream& Out, CFG &C) const { |
| 394 | print(Out, C, "\\l", "\\|"); |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Zhongxing Xu | c179a7f | 2010-03-05 04:45:36 +0000 | [diff] [blame] | 397 | void GRState::printStdErr(CFG &C) const { |
| 398 | print(llvm::errs(), C); |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Ted Kremenek | 72cd17f | 2008-08-14 21:16:54 +0000 | [diff] [blame] | 401 | //===----------------------------------------------------------------------===// |
| 402 | // Generic Data Map. |
| 403 | //===----------------------------------------------------------------------===// |
| 404 | |
| 405 | void* const* GRState::FindGDM(void* K) const { |
| 406 | return GDM.lookup(K); |
| 407 | } |
| 408 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 409 | void* |
| 410 | GRStateManager::FindGDMContext(void* K, |
| 411 | void* (*CreateContext)(llvm::BumpPtrAllocator&), |
| 412 | void (*DeleteContext)(void*)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 413 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 414 | std::pair<void*, void (*)(void*)>& p = GDMContexts[K]; |
| 415 | if (!p.first) { |
| 416 | p.first = CreateContext(Alloc); |
| 417 | p.second = DeleteContext; |
| 418 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 419 | |
Ted Kremenek | 1c72ef0 | 2008-08-16 00:49:49 +0000 | [diff] [blame] | 420 | return p.first; |
| 421 | } |
| 422 | |
Zhongxing Xu | 4230da6 | 2008-11-03 05:18:34 +0000 | [diff] [blame] | 423 | const GRState* GRStateManager::addGDM(const GRState* St, void* Key, void* Data){ |
Ted Kremenek | 72cd17f | 2008-08-14 21:16:54 +0000 | [diff] [blame] | 424 | GRState::GenericDataMap M1 = St->getGDM(); |
Ted Kremenek | 3baf672 | 2010-11-24 00:54:37 +0000 | [diff] [blame] | 425 | GRState::GenericDataMap M2 = GDMFactory.add(M1, Key, Data); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 426 | |
Ted Kremenek | 72cd17f | 2008-08-14 21:16:54 +0000 | [diff] [blame] | 427 | if (M1 == M2) |
| 428 | return St; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 429 | |
Ted Kremenek | 72cd17f | 2008-08-14 21:16:54 +0000 | [diff] [blame] | 430 | GRState NewSt = *St; |
| 431 | NewSt.GDM = M2; |
| 432 | return getPersistentState(NewSt); |
| 433 | } |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 434 | |
Zhongxing Xu | 0541d10 | 2010-03-25 01:39:39 +0000 | [diff] [blame] | 435 | const GRState *GRStateManager::removeGDM(const GRState *state, void *Key) { |
| 436 | GRState::GenericDataMap OldM = state->getGDM(); |
Ted Kremenek | 3baf672 | 2010-11-24 00:54:37 +0000 | [diff] [blame] | 437 | GRState::GenericDataMap NewM = GDMFactory.remove(OldM, Key); |
Zhongxing Xu | 0541d10 | 2010-03-25 01:39:39 +0000 | [diff] [blame] | 438 | |
| 439 | if (NewM == OldM) |
| 440 | return state; |
| 441 | |
| 442 | GRState NewState = *state; |
| 443 | NewState.GDM = NewM; |
| 444 | return getPersistentState(NewState); |
| 445 | } |
| 446 | |
Ted Kremenek | 584def7 | 2008-07-22 00:46:16 +0000 | [diff] [blame] | 447 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 5216ad7 | 2009-02-14 03:16:10 +0000 | [diff] [blame] | 448 | // Utility. |
| 449 | //===----------------------------------------------------------------------===// |
| 450 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 451 | namespace { |
Kovarththanan Rajaratnam | ba5fb5a | 2009-11-28 06:07:30 +0000 | [diff] [blame] | 452 | class ScanReachableSymbols : public SubRegionMap::Visitor { |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 453 | typedef llvm::DenseSet<const MemRegion*> VisitedRegionsTy; |
| 454 | |
| 455 | VisitedRegionsTy visited; |
Ted Kremenek | 47fed90 | 2009-06-18 01:33:24 +0000 | [diff] [blame] | 456 | const GRState *state; |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 457 | SymbolVisitor &visitor; |
| 458 | llvm::OwningPtr<SubRegionMap> SRM; |
| 459 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | |
Ted Kremenek | 47fed90 | 2009-06-18 01:33:24 +0000 | [diff] [blame] | 461 | ScanReachableSymbols(const GRState *st, SymbolVisitor& v) |
| 462 | : state(st), visitor(v) {} |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 464 | bool scan(nonloc::CompoundVal val); |
| 465 | bool scan(SVal val); |
| 466 | bool scan(const MemRegion *R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 467 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 468 | // From SubRegionMap::Visitor. |
| 469 | bool Visit(const MemRegion* Parent, const MemRegion* SubRegion) { |
| 470 | return scan(SubRegion); |
| 471 | } |
| 472 | }; |
| 473 | } |
| 474 | |
| 475 | bool ScanReachableSymbols::scan(nonloc::CompoundVal val) { |
Ted Kremenek | 5216ad7 | 2009-02-14 03:16:10 +0000 | [diff] [blame] | 476 | 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] | 477 | if (!scan(*I)) |
| 478 | return false; |
Ted Kremenek | 5216ad7 | 2009-02-14 03:16:10 +0000 | [diff] [blame] | 479 | |
| 480 | return true; |
| 481 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 482 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 483 | bool ScanReachableSymbols::scan(SVal val) { |
| 484 | if (loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(&val)) |
| 485 | return scan(X->getRegion()); |
Ted Kremenek | 380022d | 2009-03-30 18:45:36 +0000 | [diff] [blame] | 486 | |
Zhongxing Xu | 951b334 | 2010-01-11 07:40:00 +0000 | [diff] [blame] | 487 | if (nonloc::LocAsInteger *X = dyn_cast<nonloc::LocAsInteger>(&val)) |
| 488 | return scan(X->getLoc()); |
| 489 | |
Ted Kremenek | 380022d | 2009-03-30 18:45:36 +0000 | [diff] [blame] | 490 | if (SymbolRef Sym = val.getAsSymbol()) |
| 491 | return visitor.VisitSymbol(Sym); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 492 | |
Ted Kremenek | 5216ad7 | 2009-02-14 03:16:10 +0000 | [diff] [blame] | 493 | if (nonloc::CompoundVal *X = dyn_cast<nonloc::CompoundVal>(&val)) |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 494 | return scan(*X); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | |
Ted Kremenek | 5216ad7 | 2009-02-14 03:16:10 +0000 | [diff] [blame] | 496 | return true; |
| 497 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 498 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 499 | bool ScanReachableSymbols::scan(const MemRegion *R) { |
Ted Kremenek | 1cb151e | 2009-03-04 00:13:10 +0000 | [diff] [blame] | 500 | if (isa<MemSpaceRegion>(R) || visited.count(R)) |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 501 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 503 | visited.insert(R); |
| 504 | |
| 505 | // If this is a symbolic region, visit the symbol for the region. |
| 506 | if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R)) |
| 507 | if (!visitor.VisitSymbol(SR->getSymbol())) |
| 508 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 509 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 510 | // If this is a subregion, also visit the parent regions. |
| 511 | if (const SubRegion *SR = dyn_cast<SubRegion>(R)) |
Ted Kremenek | 6076e0a | 2009-03-03 18:15:30 +0000 | [diff] [blame] | 512 | if (!scan(SR->getSuperRegion())) |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 513 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 514 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 515 | // Now look at the binding to this region (if any). |
Ted Kremenek | 1397663 | 2010-02-08 16:18:51 +0000 | [diff] [blame] | 516 | if (!scan(state->getSValAsScalarOrLoc(R))) |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 517 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 518 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 519 | // Now look at the subregions. |
| 520 | if (!SRM.get()) |
Zhongxing Xu | f5416bd | 2010-02-05 05:18:47 +0000 | [diff] [blame] | 521 | SRM.reset(state->getStateManager().getStoreManager(). |
| 522 | getSubRegionMap(state->getStore())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 523 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 524 | return SRM->iterSubRegions(R, *this); |
| 525 | } |
| 526 | |
Ted Kremenek | 47fed90 | 2009-06-18 01:33:24 +0000 | [diff] [blame] | 527 | bool GRState::scanReachableSymbols(SVal val, SymbolVisitor& visitor) const { |
| 528 | ScanReachableSymbols S(this, visitor); |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 529 | return S.scan(val); |
| 530 | } |
Ted Kremenek | 5216ad7 | 2009-02-14 03:16:10 +0000 | [diff] [blame] | 531 | |
Ted Kremenek | 9dce71f | 2009-11-26 02:32:19 +0000 | [diff] [blame] | 532 | bool GRState::scanReachableSymbols(const SVal *I, const SVal *E, |
| 533 | SymbolVisitor &visitor) const { |
| 534 | ScanReachableSymbols S(this, visitor); |
| 535 | for ( ; I != E; ++I) { |
Ted Kremenek | 43f19f7 | 2009-12-01 17:50:25 +0000 | [diff] [blame] | 536 | if (!S.scan(*I)) |
| 537 | return false; |
Ted Kremenek | 9dce71f | 2009-11-26 02:32:19 +0000 | [diff] [blame] | 538 | } |
Ted Kremenek | 43f19f7 | 2009-12-01 17:50:25 +0000 | [diff] [blame] | 539 | return true; |
Ted Kremenek | 9dce71f | 2009-11-26 02:32:19 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | bool GRState::scanReachableSymbols(const MemRegion * const *I, |
| 543 | const MemRegion * const *E, |
| 544 | SymbolVisitor &visitor) const { |
| 545 | ScanReachableSymbols S(this, visitor); |
| 546 | for ( ; I != E; ++I) { |
Ted Kremenek | 43f19f7 | 2009-12-01 17:50:25 +0000 | [diff] [blame] | 547 | if (!S.scan(*I)) |
| 548 | return false; |
Ted Kremenek | 9dce71f | 2009-11-26 02:32:19 +0000 | [diff] [blame] | 549 | } |
Ted Kremenek | 43f19f7 | 2009-12-01 17:50:25 +0000 | [diff] [blame] | 550 | return true; |
Ted Kremenek | 9dce71f | 2009-11-26 02:32:19 +0000 | [diff] [blame] | 551 | } |