Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 1 | //== BasicStore.cpp - Basic map from Locations to Values --------*- C++ -*--==// |
| 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 | // |
| 10 | // This file defined the BasicStore and BasicStoreManager classes. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Ted Kremenek | 5f81c44 | 2008-08-28 23:31:31 +0000 | [diff] [blame] | 14 | #include "clang/Analysis/Analyses/LiveVariables.h" |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 15 | #include "clang/Analysis/PathSensitive/GRState.h" |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/ImmutableMap.h" |
| 17 | #include "llvm/Support/Compiler.h" |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Streams.h" |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace clang; |
| 21 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 22 | typedef llvm::ImmutableMap<const VarDecl*,SVal> VarBindingsTy; |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 23 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 24 | namespace { |
| 25 | |
| 26 | class VISIBILITY_HIDDEN BasicStoreManager : public StoreManager { |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 27 | VarBindingsTy::Factory VBFactory; |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame] | 28 | GRStateManager& StateMgr; |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 29 | const MemRegion* SelfRegion; |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 30 | |
| 31 | public: |
Zhongxing Xu | bc678fd | 2008-10-07 01:31:04 +0000 | [diff] [blame] | 32 | BasicStoreManager(GRStateManager& mgr) |
Ted Kremenek | d6cfbe4 | 2009-01-07 22:18:50 +0000 | [diff] [blame] | 33 | : StoreManager(mgr.getAllocator()), |
| 34 | VBFactory(mgr.getAllocator()), |
Zhongxing Xu | 0adfbf6 | 2008-11-15 08:19:58 +0000 | [diff] [blame] | 35 | StateMgr(mgr), |
Zhongxing Xu | 0adfbf6 | 2008-11-15 08:19:58 +0000 | [diff] [blame] | 36 | SelfRegion(0) {} |
Ted Kremenek | d0c4b28 | 2008-08-25 19:33:03 +0000 | [diff] [blame] | 37 | |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 38 | ~BasicStoreManager() {} |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 39 | |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame^] | 40 | SVal Retrieve(const GRState *state, Loc loc, QualType T = QualType()); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 41 | |
| 42 | const GRState* Bind(const GRState* St, Loc L, SVal V) { |
| 43 | Store store = St->getStore(); |
| 44 | store = BindInternal(store, L, V); |
| 45 | return StateMgr.MakeStateWithStore(St, store); |
| 46 | } |
| 47 | |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame^] | 48 | Store BindInternal(Store St, Loc loc, SVal V); |
| 49 | Store Remove(Store St, Loc loc); |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 50 | Store getInitialStore(); |
Zhongxing Xu | bc678fd | 2008-10-07 01:31:04 +0000 | [diff] [blame] | 51 | |
Zhongxing Xu | 6d69b5d | 2008-10-16 06:09:51 +0000 | [diff] [blame] | 52 | // FIXME: Investigate what is using this. This method should be removed. |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 53 | virtual Loc getLoc(const VarDecl* VD) { |
Zhongxing Xu | 56a3460 | 2008-12-21 03:31:01 +0000 | [diff] [blame] | 54 | return Loc::MakeVal(MRMgr.getVarRegion(VD)); |
Zhongxing Xu | bc678fd | 2008-10-07 01:31:04 +0000 | [diff] [blame] | 55 | } |
Ted Kremenek | d9bc33e | 2008-10-17 00:51:01 +0000 | [diff] [blame] | 56 | |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 57 | const GRState* BindCompoundLiteral(const GRState* St, |
| 58 | const CompoundLiteralExpr* CL, |
| 59 | SVal V) { |
| 60 | return St; |
Ted Kremenek | 4f09027 | 2008-10-27 21:54:31 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 63 | SVal getLValueVar(const GRState* St, const VarDecl* VD); |
Zhongxing Xu | 143bf82 | 2008-10-25 14:18:57 +0000 | [diff] [blame] | 64 | SVal getLValueString(const GRState* St, const StringLiteral* S); |
Zhongxing Xu | f22679e | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 65 | SVal getLValueCompoundLiteral(const GRState* St, |
| 66 | const CompoundLiteralExpr* CL); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 67 | SVal getLValueIvar(const GRState* St, const ObjCIvarDecl* D, SVal Base); |
Zhongxing Xu | c92e5fe | 2008-10-22 09:00:19 +0000 | [diff] [blame] | 68 | SVal getLValueField(const GRState* St, SVal Base, const FieldDecl* D); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 69 | SVal getLValueElement(const GRState* St, SVal Base, SVal Offset); |
Zhongxing Xu | e1911af | 2008-10-23 03:10:39 +0000 | [diff] [blame] | 70 | |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 71 | /// ArrayToPointer - Used by GRExprEngine::VistCast to handle implicit |
| 72 | /// conversions between arrays and pointers. |
Zhongxing Xu | e1911af | 2008-10-23 03:10:39 +0000 | [diff] [blame] | 73 | SVal ArrayToPointer(SVal Array) { return Array; } |
Zhongxing Xu | dc0a25d | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 74 | |
Ted Kremenek | 6eddeb1 | 2008-12-13 21:49:13 +0000 | [diff] [blame] | 75 | /// CastRegion - Used by GRExprEngine::VisitCast to handle casts from |
| 76 | /// a MemRegion* to a specific location type. 'R' is the region being |
| 77 | /// casted and 'CastToTy' the result type of the cast. |
| 78 | CastResult CastRegion(const GRState* state, const MemRegion* R, |
| 79 | QualType CastToTy); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 80 | |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 81 | /// getSelfRegion - Returns the region for the 'self' (Objective-C) or |
| 82 | /// 'this' object (C++). When used when analyzing a normal function this |
| 83 | /// method returns NULL. |
| 84 | const MemRegion* getSelfRegion(Store) { |
| 85 | return SelfRegion; |
| 86 | } |
| 87 | |
Ted Kremenek | 2ed14be | 2008-12-05 00:47:52 +0000 | [diff] [blame] | 88 | /// RemoveDeadBindings - Scans a BasicStore of 'state' for dead values. |
| 89 | /// It returns a new Store with these values removed, and populates LSymbols |
| 90 | /// and DSymbols with the known set of live and dead symbols respectively. |
| 91 | Store RemoveDeadBindings(const GRState* state, Stmt* Loc, |
| 92 | const LiveVariables& Live, |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 93 | llvm::SmallVectorImpl<const MemRegion*>& RegionRoots, |
| 94 | LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 95 | |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 96 | void iterBindings(Store store, BindingsHandler& f); |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 97 | |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 98 | const GRState* BindDecl(const GRState* St, const VarDecl* VD, SVal InitVal) { |
| 99 | Store store = St->getStore(); |
| 100 | store = BindDeclInternal(store, VD, &InitVal); |
| 101 | return StateMgr.MakeStateWithStore(St, store); |
| 102 | } |
| 103 | |
| 104 | const GRState* BindDeclWithNoInit(const GRState* St, const VarDecl* VD) { |
| 105 | Store store = St->getStore(); |
| 106 | store = BindDeclInternal(store, VD, 0); |
| 107 | return StateMgr.MakeStateWithStore(St, store); |
| 108 | } |
| 109 | |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 110 | Store BindDeclInternal(Store store, const VarDecl* VD, SVal* InitVal); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 111 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 112 | static inline VarBindingsTy GetVarBindings(Store store) { |
| 113 | return VarBindingsTy(static_cast<const VarBindingsTy::TreeTy*>(store)); |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 116 | void print(Store store, std::ostream& Out, const char* nl, const char *sep); |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 117 | }; |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 118 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 119 | } // end anonymous namespace |
| 120 | |
| 121 | |
Ted Kremenek | 5f81c44 | 2008-08-28 23:31:31 +0000 | [diff] [blame] | 122 | StoreManager* clang::CreateBasicStoreManager(GRStateManager& StMgr) { |
| 123 | return new BasicStoreManager(StMgr); |
Ted Kremenek | d0c4b28 | 2008-08-25 19:33:03 +0000 | [diff] [blame] | 124 | } |
Zhongxing Xu | 933c3e1 | 2008-10-21 06:54:23 +0000 | [diff] [blame] | 125 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 126 | SVal BasicStoreManager::getLValueVar(const GRState* St, const VarDecl* VD) { |
Zhongxing Xu | 56a3460 | 2008-12-21 03:31:01 +0000 | [diff] [blame] | 127 | return Loc::MakeVal(MRMgr.getVarRegion(VD)); |
Ted Kremenek | d9bc33e | 2008-10-17 00:51:01 +0000 | [diff] [blame] | 128 | } |
Zhongxing Xu | 143bf82 | 2008-10-25 14:18:57 +0000 | [diff] [blame] | 129 | |
| 130 | SVal BasicStoreManager::getLValueString(const GRState* St, |
| 131 | const StringLiteral* S) { |
Zhongxing Xu | 56a3460 | 2008-12-21 03:31:01 +0000 | [diff] [blame] | 132 | return Loc::MakeVal(MRMgr.getStringRegion(S)); |
Zhongxing Xu | 143bf82 | 2008-10-25 14:18:57 +0000 | [diff] [blame] | 133 | } |
Zhongxing Xu | f22679e | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 134 | |
| 135 | SVal BasicStoreManager::getLValueCompoundLiteral(const GRState* St, |
| 136 | const CompoundLiteralExpr* CL){ |
Zhongxing Xu | 56a3460 | 2008-12-21 03:31:01 +0000 | [diff] [blame] | 137 | return Loc::MakeVal(MRMgr.getCompoundLiteralRegion(CL)); |
Zhongxing Xu | f22679e | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 140 | SVal BasicStoreManager::getLValueIvar(const GRState* St, const ObjCIvarDecl* D, |
| 141 | SVal Base) { |
Ted Kremenek | d9bc33e | 2008-10-17 00:51:01 +0000 | [diff] [blame] | 142 | return UnknownVal(); |
| 143 | } |
| 144 | |
Ted Kremenek | 6eddeb1 | 2008-12-13 21:49:13 +0000 | [diff] [blame] | 145 | /// CastRegion - Used by GRExprEngine::VisitCast to handle casts from |
| 146 | /// a MemRegion* to a specific location type. 'R' is the region being |
| 147 | /// casted and 'CastToTy' the result type of the cast. |
| 148 | StoreManager::CastResult |
| 149 | BasicStoreManager::CastRegion(const GRState* state, const MemRegion* R, |
| 150 | QualType CastToTy) { |
| 151 | |
| 152 | // Return the same region if the region types are compatible. |
| 153 | if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) { |
| 154 | ASTContext& Ctx = StateMgr.getContext(); |
| 155 | QualType Ta = Ctx.getCanonicalType(TR->getLValueType(Ctx)); |
| 156 | QualType Tb = Ctx.getCanonicalType(CastToTy); |
| 157 | |
| 158 | if (Ta == Tb) |
| 159 | return CastResult(state, R); |
| 160 | } |
| 161 | |
| 162 | return CastResult(state, MRMgr.getAnonTypedRegion(CastToTy, R)); |
| 163 | } |
Ted Kremenek | d9bc33e | 2008-10-17 00:51:01 +0000 | [diff] [blame] | 164 | |
Zhongxing Xu | c92e5fe | 2008-10-22 09:00:19 +0000 | [diff] [blame] | 165 | SVal BasicStoreManager::getLValueField(const GRState* St, SVal Base, |
| 166 | const FieldDecl* D) { |
Ted Kremenek | 993f1c7 | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 167 | |
| 168 | if (Base.isUnknownOrUndef()) |
| 169 | return Base; |
| 170 | |
| 171 | Loc BaseL = cast<Loc>(Base); |
| 172 | const MemRegion* BaseR = 0; |
| 173 | |
| 174 | switch(BaseL.getSubKind()) { |
| 175 | case loc::SymbolValKind: |
| 176 | BaseR = MRMgr.getSymbolicRegion(cast<loc::SymbolVal>(&BaseL)->getSymbol()); |
| 177 | break; |
| 178 | |
| 179 | case loc::GotoLabelKind: |
| 180 | case loc::FuncValKind: |
| 181 | // Technically we can get here if people do funny things with casts. |
| 182 | return UndefinedVal(); |
| 183 | |
| 184 | case loc::MemRegionKind: |
| 185 | BaseR = cast<loc::MemRegionVal>(BaseL).getRegion(); |
| 186 | break; |
| 187 | |
| 188 | case loc::ConcreteIntKind: |
Ted Kremenek | 993f1c7 | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 189 | // While these seem funny, this can happen through casts. |
| 190 | // FIXME: What we should return is the field offset. For example, |
| 191 | // add the field offset to the integer value. That way funny things |
| 192 | // like this work properly: &(((struct foo *) 0xa)->f) |
| 193 | return Base; |
| 194 | |
| 195 | default: |
| 196 | assert ("Unhandled Base."); |
| 197 | return Base; |
| 198 | } |
| 199 | |
Zhongxing Xu | 56a3460 | 2008-12-21 03:31:01 +0000 | [diff] [blame] | 200 | return Loc::MakeVal(MRMgr.getFieldRegion(D, BaseR)); |
Ted Kremenek | d9bc33e | 2008-10-17 00:51:01 +0000 | [diff] [blame] | 201 | } |
Ted Kremenek | d0c4b28 | 2008-08-25 19:33:03 +0000 | [diff] [blame] | 202 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 203 | SVal BasicStoreManager::getLValueElement(const GRState* St, SVal Base, |
| 204 | SVal Offset) { |
Ted Kremenek | 7d71b29 | 2008-12-09 21:20:27 +0000 | [diff] [blame] | 205 | |
| 206 | |
| 207 | if (Base.isUnknownOrUndef()) |
| 208 | return Base; |
| 209 | |
| 210 | Loc BaseL = cast<Loc>(Base); |
Ted Kremenek | abb042f | 2008-12-13 19:24:37 +0000 | [diff] [blame] | 211 | const TypedRegion* BaseR = 0; |
Ted Kremenek | 7d71b29 | 2008-12-09 21:20:27 +0000 | [diff] [blame] | 212 | |
| 213 | switch(BaseL.getSubKind()) { |
Ted Kremenek | 1d6c14b | 2008-12-09 23:50:57 +0000 | [diff] [blame] | 214 | case loc::SymbolValKind: { |
| 215 | // FIXME: Should we have symbolic regions be typed or typeless? |
| 216 | // Here we assume that these regions are typeless, even though the |
| 217 | // symbol is typed. |
| 218 | SymbolRef Sym = cast<loc::SymbolVal>(&BaseL)->getSymbol(); |
| 219 | // Create a region to represent this symbol. |
| 220 | // FIXME: In the future we may just use symbolic regions instead of |
| 221 | // SymbolVals to reason about symbolic memory chunks. |
| 222 | const MemRegion* SymR = MRMgr.getSymbolicRegion(Sym); |
| 223 | // Layered a typed region on top of this. |
| 224 | QualType T = StateMgr.getSymbolManager().getType(Sym); |
| 225 | BaseR = MRMgr.getAnonTypedRegion(T, SymR); |
Ted Kremenek | 7d71b29 | 2008-12-09 21:20:27 +0000 | [diff] [blame] | 226 | break; |
Ted Kremenek | 1d6c14b | 2008-12-09 23:50:57 +0000 | [diff] [blame] | 227 | } |
Ted Kremenek | 7d71b29 | 2008-12-09 21:20:27 +0000 | [diff] [blame] | 228 | |
| 229 | case loc::GotoLabelKind: |
| 230 | case loc::FuncValKind: |
| 231 | // Technically we can get here if people do funny things with casts. |
| 232 | return UndefinedVal(); |
| 233 | |
Ted Kremenek | abb042f | 2008-12-13 19:24:37 +0000 | [diff] [blame] | 234 | case loc::MemRegionKind: { |
| 235 | const MemRegion *R = cast<loc::MemRegionVal>(BaseL).getRegion(); |
| 236 | if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) { |
| 237 | BaseR = TR; |
| 238 | break; |
| 239 | } |
| 240 | |
| 241 | // FIXME: Handle SymbolRegions? Shouldn't be possible in |
| 242 | // BasicStoreManager. |
| 243 | assert(!isa<SymbolicRegion>(R)); |
| 244 | |
Ted Kremenek | 7d71b29 | 2008-12-09 21:20:27 +0000 | [diff] [blame] | 245 | break; |
Ted Kremenek | abb042f | 2008-12-13 19:24:37 +0000 | [diff] [blame] | 246 | } |
Ted Kremenek | 7d71b29 | 2008-12-09 21:20:27 +0000 | [diff] [blame] | 247 | |
| 248 | case loc::ConcreteIntKind: |
| 249 | // While these seem funny, this can happen through casts. |
| 250 | // FIXME: What we should return is the field offset. For example, |
| 251 | // add the field offset to the integer value. That way funny things |
| 252 | // like this work properly: &(((struct foo *) 0xa)->f) |
| 253 | return Base; |
| 254 | |
| 255 | default: |
| 256 | assert ("Unhandled Base."); |
| 257 | return Base; |
| 258 | } |
| 259 | |
Ted Kremenek | abb042f | 2008-12-13 19:24:37 +0000 | [diff] [blame] | 260 | if (BaseR) |
Zhongxing Xu | 56a3460 | 2008-12-21 03:31:01 +0000 | [diff] [blame] | 261 | return Loc::MakeVal(MRMgr.getElementRegion(UnknownVal(), BaseR)); |
Ted Kremenek | abb042f | 2008-12-13 19:24:37 +0000 | [diff] [blame] | 262 | else |
| 263 | return UnknownVal(); |
Zhongxing Xu | 6d69b5d | 2008-10-16 06:09:51 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame^] | 266 | SVal BasicStoreManager::Retrieve(const GRState* state, Loc loc, QualType T) { |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 267 | |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame^] | 268 | if (isa<UnknownVal>(loc)) |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 269 | return UnknownVal(); |
| 270 | |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame^] | 271 | assert (!isa<UndefinedVal>(loc)); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 272 | |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame^] | 273 | switch (loc.getSubKind()) { |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 274 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 275 | case loc::MemRegionKind: { |
Ted Kremenek | 993f1c7 | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 276 | const VarRegion* R = |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame^] | 277 | dyn_cast<VarRegion>(cast<loc::MemRegionVal>(loc).getRegion()); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 278 | |
| 279 | if (!R) |
| 280 | return UnknownVal(); |
Ted Kremenek | 2ed14be | 2008-12-05 00:47:52 +0000 | [diff] [blame] | 281 | |
| 282 | Store store = state->getStore(); |
Zhongxing Xu | 47b3240 | 2008-12-21 03:46:11 +0000 | [diff] [blame] | 283 | VarBindingsTy B = GetVarBindings(store); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 284 | VarBindingsTy::data_type* T = B.lookup(R->getDecl()); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 285 | return T ? *T : UnknownVal(); |
| 286 | } |
| 287 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 288 | case loc::SymbolValKind: |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 289 | return UnknownVal(); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 290 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 291 | case loc::ConcreteIntKind: |
| 292 | // Some clients may call GetSVal with such an option simply because |
| 293 | // they are doing a quick scan through their Locs (potentially to |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 294 | // invalidate their bindings). Just return Undefined. |
Ted Kremenek | d9bc33e | 2008-10-17 00:51:01 +0000 | [diff] [blame] | 295 | return UndefinedVal(); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 296 | case loc::FuncValKind: |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame^] | 297 | return loc; |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 298 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 299 | default: |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 300 | assert (false && "Invalid Loc."); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 301 | break; |
| 302 | } |
| 303 | |
| 304 | return UnknownVal(); |
| 305 | } |
Ted Kremenek | 97ed4f6 | 2008-10-17 00:03:18 +0000 | [diff] [blame] | 306 | |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame^] | 307 | Store BasicStoreManager::BindInternal(Store store, Loc loc, SVal V) { |
| 308 | switch (loc.getSubKind()) { |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 309 | case loc::MemRegionKind: { |
Ted Kremenek | 993f1c7 | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 310 | const VarRegion* R = |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame^] | 311 | dyn_cast<VarRegion>(cast<loc::MemRegionVal>(loc).getRegion()); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 312 | |
| 313 | if (!R) |
| 314 | return store; |
| 315 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 316 | VarBindingsTy B = GetVarBindings(store); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 317 | return V.isUnknown() |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 318 | ? VBFactory.Remove(B, R->getDecl()).getRoot() |
| 319 | : VBFactory.Add(B, R->getDecl(), V).getRoot(); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 320 | } |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 321 | default: |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 322 | assert ("SetSVal for given Loc type not yet implemented."); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 323 | return store; |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame^] | 327 | Store BasicStoreManager::Remove(Store store, Loc loc) { |
| 328 | switch (loc.getSubKind()) { |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 329 | case loc::MemRegionKind: { |
Ted Kremenek | 993f1c7 | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 330 | const VarRegion* R = |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame^] | 331 | dyn_cast<VarRegion>(cast<loc::MemRegionVal>(loc).getRegion()); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 332 | |
| 333 | if (!R) |
| 334 | return store; |
| 335 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 336 | VarBindingsTy B = GetVarBindings(store); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 337 | return VBFactory.Remove(B,R->getDecl()).getRoot(); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 338 | } |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 339 | default: |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 340 | assert ("Remove for given Loc type not yet implemented."); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 341 | return store; |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 342 | } |
| 343 | } |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 344 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 345 | Store |
Ted Kremenek | 2ed14be | 2008-12-05 00:47:52 +0000 | [diff] [blame] | 346 | BasicStoreManager::RemoveDeadBindings(const GRState* state, Stmt* Loc, |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 347 | const LiveVariables& Liveness, |
| 348 | llvm::SmallVectorImpl<const MemRegion*>& RegionRoots, |
| 349 | LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols) { |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 350 | |
Ted Kremenek | 2ed14be | 2008-12-05 00:47:52 +0000 | [diff] [blame] | 351 | Store store = state->getStore(); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 352 | VarBindingsTy B = GetVarBindings(store); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 353 | typedef SVal::symbol_iterator symbol_iterator; |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 354 | |
| 355 | // Iterate over the variable bindings. |
| 356 | for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I) |
| 357 | if (Liveness.isLive(Loc, I.getKey())) { |
Zhongxing Xu | bc678fd | 2008-10-07 01:31:04 +0000 | [diff] [blame] | 358 | RegionRoots.push_back(MRMgr.getVarRegion(I.getKey())); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 359 | SVal X = I.getData(); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 360 | |
| 361 | for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI) |
| 362 | LSymbols.insert(*SI); |
| 363 | } |
| 364 | |
| 365 | // Scan for live variables and live symbols. |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 366 | llvm::SmallPtrSet<const VarRegion*, 10> Marked; |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 367 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 368 | while (!RegionRoots.empty()) { |
Ted Kremenek | 134e749 | 2008-10-17 22:52:40 +0000 | [diff] [blame] | 369 | const MemRegion* MR = RegionRoots.back(); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 370 | RegionRoots.pop_back(); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 371 | |
Ted Kremenek | 134e749 | 2008-10-17 22:52:40 +0000 | [diff] [blame] | 372 | while (MR) { |
| 373 | if (const SymbolicRegion* SymR = dyn_cast<SymbolicRegion>(MR)) { |
| 374 | LSymbols.insert(SymR->getSymbol()); |
| 375 | break; |
| 376 | } |
| 377 | else if (const VarRegion* R = dyn_cast<VarRegion>(MR)) { |
| 378 | if (Marked.count(R)) |
| 379 | break; |
| 380 | |
| 381 | Marked.insert(R); |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame^] | 382 | SVal X = Retrieve(state, loc::MemRegionVal(R)); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 383 | |
Ted Kremenek | 134e749 | 2008-10-17 22:52:40 +0000 | [diff] [blame] | 384 | // FIXME: We need to handle symbols nested in region definitions. |
| 385 | for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI) |
| 386 | LSymbols.insert(*SI); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 387 | |
Ted Kremenek | 134e749 | 2008-10-17 22:52:40 +0000 | [diff] [blame] | 388 | if (!isa<loc::MemRegionVal>(X)) |
| 389 | break; |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 390 | |
Ted Kremenek | 134e749 | 2008-10-17 22:52:40 +0000 | [diff] [blame] | 391 | const loc::MemRegionVal& LVD = cast<loc::MemRegionVal>(X); |
| 392 | RegionRoots.push_back(LVD.getRegion()); |
| 393 | break; |
| 394 | } |
| 395 | else if (const SubRegion* R = dyn_cast<SubRegion>(MR)) |
| 396 | MR = R->getSuperRegion(); |
| 397 | else |
| 398 | break; |
| 399 | } |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | // Remove dead variable bindings. |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 403 | for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I) { |
Zhongxing Xu | bc678fd | 2008-10-07 01:31:04 +0000 | [diff] [blame] | 404 | const VarRegion* R = cast<VarRegion>(MRMgr.getVarRegion(I.getKey())); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 405 | |
| 406 | if (!Marked.count(R)) { |
Zhongxing Xu | 56a3460 | 2008-12-21 03:31:01 +0000 | [diff] [blame] | 407 | store = Remove(store, Loc::MakeVal(R)); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 408 | SVal X = I.getData(); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 409 | |
| 410 | for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI) |
| 411 | if (!LSymbols.count(*SI)) DSymbols.insert(*SI); |
| 412 | } |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 415 | return store; |
| 416 | } |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 417 | |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame] | 418 | Store BasicStoreManager::getInitialStore() { |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 419 | |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 420 | // The LiveVariables information already has a compilation of all VarDecls |
| 421 | // used in the function. Iterate through this set, and "symbolicate" |
| 422 | // any VarDecl whose value originally comes from outside the function. |
| 423 | |
| 424 | typedef LiveVariables::AnalysisDataTy LVDataTy; |
| 425 | LVDataTy& D = StateMgr.getLiveVariables().getAnalysisData(); |
| 426 | |
| 427 | Store St = VBFactory.GetEmptyMap().getRoot(); |
| 428 | |
| 429 | for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) { |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 430 | NamedDecl* ND = const_cast<NamedDecl*>(I->first); |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 431 | |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 432 | // Handle implicit parameters. |
| 433 | if (ImplicitParamDecl* PD = dyn_cast<ImplicitParamDecl>(ND)) { |
| 434 | const Decl& CD = StateMgr.getCodeDecl(); |
| 435 | if (const ObjCMethodDecl* MD = dyn_cast<ObjCMethodDecl>(&CD)) { |
| 436 | if (MD->getSelfDecl() == PD) { |
| 437 | // Create a region for "self". |
| 438 | assert (SelfRegion == 0); |
| 439 | SelfRegion = MRMgr.getObjCObjectRegion(MD->getClassInterface(), |
| 440 | MRMgr.getHeapRegion()); |
| 441 | |
Zhongxing Xu | 56a3460 | 2008-12-21 03:31:01 +0000 | [diff] [blame] | 442 | St = BindInternal(St, Loc::MakeVal(MRMgr.getVarRegion(PD)), |
| 443 | Loc::MakeVal(SelfRegion)); |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | } |
| 447 | else if (VarDecl* VD = dyn_cast<VarDecl>(ND)) { |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 448 | // Punt on static variables for now. |
| 449 | if (VD->getStorageClass() == VarDecl::Static) |
| 450 | continue; |
| 451 | |
| 452 | // Only handle pointers and integers for now. |
| 453 | QualType T = VD->getType(); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 454 | if (Loc::IsLocType(T) || T->isIntegerType()) { |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 455 | // Initialize globals and parameters to symbolic values. |
| 456 | // Initialize local variables to undefined. |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 457 | SVal X = (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) || |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 458 | isa<ImplicitParamDecl>(VD)) |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 459 | ? SVal::GetSymbolValue(StateMgr.getSymbolManager(), VD) |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 460 | : UndefinedVal(); |
| 461 | |
Zhongxing Xu | 56a3460 | 2008-12-21 03:31:01 +0000 | [diff] [blame] | 462 | St = BindInternal(St, Loc::MakeVal(MRMgr.getVarRegion(VD)), X); |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | } |
| 466 | return St; |
| 467 | } |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 468 | |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 469 | Store BasicStoreManager::BindDeclInternal(Store store, const VarDecl* VD, |
| 470 | SVal* InitVal) { |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 471 | |
Ted Kremenek | e53c069 | 2008-08-23 00:50:55 +0000 | [diff] [blame] | 472 | BasicValueFactory& BasicVals = StateMgr.getBasicVals(); |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 473 | |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 474 | // BasicStore does not model arrays and structs. |
| 475 | if (VD->getType()->isArrayType() || VD->getType()->isStructureType()) |
| 476 | return store; |
| 477 | |
| 478 | if (VD->hasGlobalStorage()) { |
| 479 | // Handle variables with global storage: extern, static, PrivateExtern. |
| 480 | |
| 481 | // FIXME:: static variables may have an initializer, but the second time a |
| 482 | // function is called those values may not be current. Currently, a function |
| 483 | // will not be called more than once. |
| 484 | |
| 485 | // Static global variables should not be visited here. |
| 486 | assert(!(VD->getStorageClass() == VarDecl::Static && |
| 487 | VD->isFileVarDecl())); |
| 488 | |
| 489 | // Process static variables. |
| 490 | if (VD->getStorageClass() == VarDecl::Static) { |
| 491 | // C99: 6.7.8 Initialization |
| 492 | // If an object that has static storage duration is not initialized |
| 493 | // explicitly, then: |
| 494 | // —if it has pointer type, it is initialized to a null pointer; |
| 495 | // —if it has arithmetic type, it is initialized to (positive or |
| 496 | // unsigned) zero; |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 497 | if (!InitVal) { |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 498 | QualType T = VD->getType(); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 499 | if (Loc::IsLocType(T)) |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 500 | store = BindInternal(store, getLoc(VD), |
Zhongxing Xu | 8485ec6 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 501 | loc::ConcreteInt(BasicVals.getValue(0, T))); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 502 | else if (T->isIntegerType()) |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 503 | store = BindInternal(store, getLoc(VD), |
Zhongxing Xu | 8485ec6 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 504 | nonloc::ConcreteInt(BasicVals.getValue(0, T))); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 505 | else { |
| 506 | // assert(0 && "ignore other types of variables"); |
| 507 | } |
| 508 | } else { |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 509 | store = BindInternal(store, getLoc(VD), *InitVal); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | } else { |
| 513 | // Process local scalar variables. |
| 514 | QualType T = VD->getType(); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 515 | if (Loc::IsLocType(T) || T->isIntegerType()) { |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 516 | SVal V = InitVal ? *InitVal : UndefinedVal(); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 517 | store = BindInternal(store, getLoc(VD), V); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | |
| 521 | return store; |
| 522 | } |
| 523 | |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 524 | void BasicStoreManager::print(Store store, std::ostream& Out, |
| 525 | const char* nl, const char *sep) { |
| 526 | |
| 527 | VarBindingsTy B = GetVarBindings(store); |
| 528 | Out << "Variables:" << nl; |
| 529 | |
| 530 | bool isFirst = true; |
| 531 | |
| 532 | for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I != E; ++I) { |
| 533 | if (isFirst) isFirst = false; |
| 534 | else Out << nl; |
| 535 | |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 536 | Out << ' ' << I.getKey()->getNameAsString() << " : "; |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 537 | I.getData().print(Out); |
| 538 | } |
| 539 | } |
Ted Kremenek | 2bc39c6 | 2008-08-29 00:47:32 +0000 | [diff] [blame] | 540 | |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 541 | |
| 542 | void BasicStoreManager::iterBindings(Store store, BindingsHandler& f) { |
| 543 | VarBindingsTy B = GetVarBindings(store); |
Ted Kremenek | 2bc39c6 | 2008-08-29 00:47:32 +0000 | [diff] [blame] | 544 | |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 545 | for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I != E; ++I) { |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 546 | |
Zhongxing Xu | bc678fd | 2008-10-07 01:31:04 +0000 | [diff] [blame] | 547 | f.HandleBinding(*this, store, MRMgr.getVarRegion(I.getKey()),I.getData()); |
Ted Kremenek | 2bc39c6 | 2008-08-29 00:47:32 +0000 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 551 | StoreManager::BindingsHandler::~BindingsHandler() {} |