Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 1 | //== RegionStore.cpp - Field-sensitive store model --------------*- 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 defines a basic region store model. In this model, we do have field |
| 11 | // sensitivity. But we assume nothing about the heap shape. So recursive data |
| 12 | // structures are largely ignored. Basically we do 1-limiting analysis. |
| 13 | // Parameter pointers are assumed with no aliasing. Pointee objects of |
| 14 | // parameters are created lazily. |
| 15 | // |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | #include "clang/Analysis/PathSensitive/MemRegion.h" |
| 18 | #include "clang/Analysis/PathSensitive/GRState.h" |
Zhongxing Xu | dc0a25d | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 19 | #include "clang/Analysis/PathSensitive/GRStateTrait.h" |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 20 | #include "clang/Analysis/Analyses/LiveVariables.h" |
| 21 | |
| 22 | #include "llvm/ADT/ImmutableMap.h" |
Zhongxing Xu | dc0a25d | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/ImmutableList.h" |
Zhongxing Xu | a071eb0 | 2008-10-24 06:01:33 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Compiler.h" |
| 26 | |
| 27 | using namespace clang; |
| 28 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 29 | typedef llvm::ImmutableMap<const MemRegion*, SVal> RegionBindingsTy; |
Zhongxing Xu | dc0a25d | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 30 | typedef llvm::ImmutableList<const MemRegion*> RegionViewTy; |
| 31 | typedef llvm::ImmutableMap<const MemRegion*, RegionViewTy> RegionViewMapTy; |
| 32 | |
| 33 | static int RegionViewMapTyIndex = 0; |
| 34 | |
| 35 | namespace clang { |
| 36 | template<> struct GRStateTrait<RegionViewMapTy> |
| 37 | : public GRStatePartialTrait<RegionViewMapTy> { |
| 38 | static void* GDMIndex() { return &RegionViewMapTyIndex; } |
| 39 | }; |
| 40 | } |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 41 | |
| 42 | namespace { |
| 43 | |
| 44 | class VISIBILITY_HIDDEN RegionStoreManager : public StoreManager { |
| 45 | RegionBindingsTy::Factory RBFactory; |
Zhongxing Xu | dc0a25d | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 46 | RegionViewTy::Factory RVFactory; |
| 47 | RegionViewMapTy::Factory RVMFactory; |
| 48 | |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 49 | GRStateManager& StateMgr; |
| 50 | MemRegionManager MRMgr; |
| 51 | |
| 52 | public: |
| 53 | RegionStoreManager(GRStateManager& mgr) |
Zhongxing Xu | dc0a25d | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 54 | : RBFactory(mgr.getAllocator()), |
| 55 | RVFactory(mgr.getAllocator()), |
| 56 | RVMFactory(mgr.getAllocator()), |
| 57 | StateMgr(mgr), |
| 58 | MRMgr(StateMgr.getAllocator()) {} |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 59 | |
| 60 | virtual ~RegionStoreManager() {} |
| 61 | |
Zhongxing Xu | 24194ef | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 62 | MemRegionManager& getRegionManager() { return MRMgr; } |
| 63 | |
| 64 | // FIXME: Is this function necessary? |
| 65 | SVal GetRegionSVal(Store St, const MemRegion* R) { |
| 66 | return Retrieve(St, loc::MemRegionVal(R)); |
| 67 | } |
Ted Kremenek | 4f09027 | 2008-10-27 21:54:31 +0000 | [diff] [blame] | 68 | |
Zhongxing Xu | f22679e | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 69 | Store BindCompoundLiteral(Store store, const CompoundLiteralExpr* CL, SVal V); |
Zhongxing Xu | 24194ef | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 70 | |
Zhongxing Xu | 143bf82 | 2008-10-25 14:18:57 +0000 | [diff] [blame] | 71 | SVal getLValueString(const GRState* St, const StringLiteral* S); |
| 72 | |
Zhongxing Xu | f22679e | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 73 | SVal getLValueCompoundLiteral(const GRState* St, const CompoundLiteralExpr*); |
| 74 | |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 75 | SVal getLValueVar(const GRState* St, const VarDecl* VD); |
| 76 | |
| 77 | SVal getLValueIvar(const GRState* St, const ObjCIvarDecl* D, SVal Base); |
| 78 | |
| 79 | SVal getLValueField(const GRState* St, SVal Base, const FieldDecl* D); |
| 80 | |
Zhongxing Xu | b1d542a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 81 | SVal getLValueElement(const GRState* St, SVal Base, SVal Offset); |
| 82 | |
| 83 | SVal ArrayToPointer(SVal Array); |
| 84 | |
Zhongxing Xu | dc0a25d | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 85 | const GRState* CastRegion(const GRState* St, SVal VoidPtr, |
| 86 | QualType CastToTy, Stmt* CastE); |
| 87 | |
Zhongxing Xu | 24194ef | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 88 | SVal Retrieve(Store S, Loc L, QualType T = QualType()); |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 89 | |
Zhongxing Xu | 8485ec6 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 90 | Store Bind(Store St, Loc LV, SVal V); |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 91 | |
Zhongxing Xu | 24194ef | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 92 | Store Remove(Store store, Loc LV) { |
| 93 | // FIXME: Implement. |
| 94 | return store; |
| 95 | } |
| 96 | |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 97 | Store getInitialStore(); |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 98 | |
| 99 | /// getSelfRegion - Returns the region for the 'self' (Objective-C) or |
| 100 | /// 'this' object (C++). When used when analyzing a normal function this |
| 101 | /// method returns NULL. |
| 102 | const MemRegion* getSelfRegion(Store) { |
| 103 | assert (false && "Not implemented."); |
| 104 | return 0; |
| 105 | } |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 106 | |
Zhongxing Xu | 24194ef | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 107 | Store RemoveDeadBindings(Store store, Stmt* Loc, const LiveVariables& Live, |
| 108 | llvm::SmallVectorImpl<const MemRegion*>& RegionRoots, |
Zhongxing Xu | 8916d5b | 2008-11-10 09:39:04 +0000 | [diff] [blame] | 109 | LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols); |
Zhongxing Xu | 24194ef | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 110 | |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 111 | Store BindDecl(Store store, const VarDecl* VD, SVal* InitVal, unsigned Count); |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 112 | |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 113 | static inline RegionBindingsTy GetRegionBindings(Store store) { |
| 114 | return RegionBindingsTy(static_cast<const RegionBindingsTy::TreeTy*>(store)); |
| 115 | } |
Zhongxing Xu | 24194ef | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 116 | |
Zhongxing Xu | 5b8b6f2 | 2008-10-24 04:33:15 +0000 | [diff] [blame] | 117 | void print(Store store, std::ostream& Out, const char* nl, const char *sep); |
Zhongxing Xu | 24194ef | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 118 | |
| 119 | void iterBindings(Store store, BindingsHandler& f) { |
| 120 | // FIXME: Implement. |
| 121 | } |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 122 | |
| 123 | private: |
| 124 | Loc getVarLoc(const VarDecl* VD) { |
| 125 | return loc::MemRegionVal(MRMgr.getVarRegion(VD)); |
| 126 | } |
| 127 | |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 128 | Store InitializeArray(Store store, const TypedRegion* R, SVal Init); |
| 129 | Store BindArrayToVal(Store store, const TypedRegion* BaseR, SVal V); |
| 130 | Store InitializeStruct(Store store, const TypedRegion* R, SVal Init); |
| 131 | Store BindStructToVal(Store store, const TypedRegion* BaseR, SVal V); |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 132 | |
| 133 | SVal RetrieveStruct(Store store, const TypedRegion* R); |
Zhongxing Xu | f0dfa8d | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 134 | Store BindStruct(Store store, const TypedRegion* R, SVal V); |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 135 | // Utility methods. |
| 136 | BasicValueFactory& getBasicVals() { return StateMgr.getBasicVals(); } |
| 137 | ASTContext& getContext() { return StateMgr.getContext(); } |
Zhongxing Xu | dc0a25d | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 138 | |
| 139 | const GRState* AddRegionView(const GRState* St, |
| 140 | const MemRegion* View, const MemRegion* Base); |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | } // end anonymous namespace |
| 144 | |
Ted Kremenek | 95c7b00 | 2008-10-24 01:04:59 +0000 | [diff] [blame] | 145 | StoreManager* clang::CreateRegionStoreManager(GRStateManager& StMgr) { |
Zhongxing Xu | 24194ef | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 146 | return new RegionStoreManager(StMgr); |
Ted Kremenek | 95c7b00 | 2008-10-24 01:04:59 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Zhongxing Xu | 143bf82 | 2008-10-25 14:18:57 +0000 | [diff] [blame] | 149 | SVal RegionStoreManager::getLValueString(const GRState* St, |
| 150 | const StringLiteral* S) { |
| 151 | return loc::MemRegionVal(MRMgr.getStringRegion(S)); |
| 152 | } |
| 153 | |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 154 | SVal RegionStoreManager::getLValueVar(const GRState* St, const VarDecl* VD) { |
| 155 | return loc::MemRegionVal(MRMgr.getVarRegion(VD)); |
| 156 | } |
Zhongxing Xu | f22679e | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 157 | |
| 158 | SVal RegionStoreManager::getLValueCompoundLiteral(const GRState* St, |
| 159 | const CompoundLiteralExpr* CL) { |
| 160 | return loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL)); |
| 161 | } |
| 162 | |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 163 | SVal RegionStoreManager::getLValueIvar(const GRState* St, const ObjCIvarDecl* D, |
| 164 | SVal Base) { |
| 165 | return UnknownVal(); |
| 166 | } |
| 167 | |
| 168 | SVal RegionStoreManager::getLValueField(const GRState* St, SVal Base, |
| 169 | const FieldDecl* D) { |
| 170 | if (Base.isUnknownOrUndef()) |
| 171 | return Base; |
| 172 | |
| 173 | Loc BaseL = cast<Loc>(Base); |
| 174 | const MemRegion* BaseR = 0; |
| 175 | |
| 176 | switch (BaseL.getSubKind()) { |
| 177 | case loc::MemRegionKind: |
| 178 | BaseR = cast<loc::MemRegionVal>(BaseL).getRegion(); |
| 179 | break; |
| 180 | |
| 181 | case loc::SymbolValKind: |
| 182 | BaseR = MRMgr.getSymbolicRegion(cast<loc::SymbolVal>(&BaseL)->getSymbol()); |
| 183 | break; |
| 184 | |
| 185 | case loc::GotoLabelKind: |
| 186 | case loc::FuncValKind: |
| 187 | // These are anormal cases. Flag an undefined value. |
| 188 | return UndefinedVal(); |
| 189 | |
| 190 | case loc::ConcreteIntKind: |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 191 | // While these seem funny, this can happen through casts. |
| 192 | // FIXME: What we should return is the field offset. For example, |
| 193 | // add the field offset to the integer value. That way funny things |
| 194 | // like this work properly: &(((struct foo *) 0xa)->f) |
| 195 | return Base; |
| 196 | |
| 197 | default: |
Zhongxing Xu | 13d1ee2 | 2008-11-07 08:57:30 +0000 | [diff] [blame] | 198 | assert(0 && "Unhandled Base."); |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 199 | return Base; |
| 200 | } |
| 201 | |
| 202 | return loc::MemRegionVal(MRMgr.getFieldRegion(D, BaseR)); |
| 203 | } |
| 204 | |
Zhongxing Xu | b1d542a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 205 | SVal RegionStoreManager::getLValueElement(const GRState* St, |
| 206 | SVal Base, SVal Offset) { |
| 207 | if (Base.isUnknownOrUndef()) |
| 208 | return Base; |
| 209 | |
Zhongxing Xu | 4a1513e | 2008-10-27 12:23:17 +0000 | [diff] [blame] | 210 | if (isa<loc::SymbolVal>(Base)) |
| 211 | return Base; |
| 212 | |
Zhongxing Xu | b1d542a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 213 | loc::MemRegionVal& BaseL = cast<loc::MemRegionVal>(Base); |
| 214 | |
Zhongxing Xu | e4d1393 | 2008-11-13 09:48:44 +0000 | [diff] [blame] | 215 | // Pointer of any type can be cast and used as array base. We do not support |
| 216 | // that case yet. |
| 217 | if (!isa<ElementRegion>(BaseL.getRegion())) { |
| 218 | // Record what we have seen in real code. |
| 219 | assert(isa<FieldRegion>(BaseL.getRegion())); |
| 220 | return UnknownVal(); |
| 221 | } |
| 222 | |
Zhongxing Xu | b1d542a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 223 | // We expect BaseR is an ElementRegion, not a base VarRegion. |
| 224 | |
| 225 | const ElementRegion* ElemR = cast<ElementRegion>(BaseL.getRegion()); |
| 226 | |
| 227 | SVal Idx = ElemR->getIndex(); |
| 228 | |
| 229 | nonloc::ConcreteInt *CI1, *CI2; |
| 230 | |
| 231 | // Only handle integer indices for now. |
| 232 | if ((CI1 = dyn_cast<nonloc::ConcreteInt>(&Idx)) && |
| 233 | (CI2 = dyn_cast<nonloc::ConcreteInt>(&Offset))) { |
Zhongxing Xu | cc0d0ec | 2008-11-13 09:15:14 +0000 | [diff] [blame] | 234 | |
| 235 | // Temporary SVal to hold a potential signed APSInt. |
| 236 | SVal SignedInt; |
| 237 | |
| 238 | // Index might be unsigned. We have to convert it to signed. |
| 239 | if (CI2->getValue().isUnsigned()) { |
| 240 | llvm::APSInt SI = CI2->getValue(); |
| 241 | SI.setIsSigned(true); |
| 242 | SignedInt = nonloc::ConcreteInt(getBasicVals().getValue(SI)); |
| 243 | CI2 = cast<nonloc::ConcreteInt>(&SignedInt); |
| 244 | } |
| 245 | |
Zhongxing Xu | b1d542a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 246 | SVal NewIdx = CI1->EvalBinOp(StateMgr.getBasicVals(), BinaryOperator::Add, |
| 247 | *CI2); |
| 248 | return loc::MemRegionVal(MRMgr.getElementRegion(NewIdx, |
| 249 | ElemR->getSuperRegion())); |
| 250 | } |
| 251 | |
| 252 | return UnknownVal(); |
| 253 | } |
| 254 | |
| 255 | // Cast 'pointer to array' to 'pointer to the first element of array'. |
| 256 | |
| 257 | SVal RegionStoreManager::ArrayToPointer(SVal Array) { |
| 258 | const MemRegion* ArrayR = cast<loc::MemRegionVal>(&Array)->getRegion(); |
Zhongxing Xu | 143bf82 | 2008-10-25 14:18:57 +0000 | [diff] [blame] | 259 | BasicValueFactory& BasicVals = StateMgr.getBasicVals(); |
| 260 | |
Zhongxing Xu | a09300a | 2008-11-15 05:18:50 +0000 | [diff] [blame] | 261 | nonloc::ConcreteInt Idx(BasicVals.getZeroWithPtrWidth(false)); |
Zhongxing Xu | 0b7e642 | 2008-10-26 02:23:57 +0000 | [diff] [blame] | 262 | ElementRegion* ER = MRMgr.getElementRegion(Idx, ArrayR); |
| 263 | |
| 264 | return loc::MemRegionVal(ER); |
Zhongxing Xu | b1d542a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Zhongxing Xu | dc0a25d | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 267 | const GRState* RegionStoreManager::CastRegion(const GRState* St, |
| 268 | SVal VoidPtr, |
| 269 | QualType CastToTy, |
| 270 | Stmt* CastE) { |
| 271 | if (const AllocaRegion* AR = |
| 272 | dyn_cast<AllocaRegion>(cast<loc::MemRegionVal>(VoidPtr).getRegion())) { |
| 273 | |
| 274 | // Create a new region to attach type information to it. |
| 275 | const AnonTypedRegion* TR = MRMgr.getAnonTypedRegion(CastToTy, AR); |
| 276 | |
| 277 | // Get the pointer to the first element. |
| 278 | nonloc::ConcreteInt Idx(getBasicVals().getZeroWithPtrWidth(false)); |
| 279 | const ElementRegion* ER = MRMgr.getElementRegion(Idx, TR); |
| 280 | |
| 281 | St = StateMgr.BindExpr(St, CastE, loc::MemRegionVal(ER)); |
| 282 | |
| 283 | // Add a RegionView to base region. |
| 284 | return AddRegionView(St, TR, AR); |
| 285 | } |
| 286 | |
| 287 | // Default case. |
| 288 | return St; |
| 289 | } |
| 290 | |
Zhongxing Xu | 8485ec6 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 291 | SVal RegionStoreManager::Retrieve(Store S, Loc L, QualType T) { |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 292 | assert(!isa<UnknownVal>(L) && "location unknown"); |
| 293 | assert(!isa<UndefinedVal>(L) && "location undefined"); |
| 294 | |
| 295 | switch (L.getSubKind()) { |
| 296 | case loc::MemRegionKind: { |
| 297 | const MemRegion* R = cast<loc::MemRegionVal>(L).getRegion(); |
| 298 | assert(R && "bad region"); |
| 299 | |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 300 | if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) |
| 301 | if (TR->getType(getContext())->isStructureType()) |
| 302 | return RetrieveStruct(S, TR); |
| 303 | |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 304 | RegionBindingsTy B(static_cast<const RegionBindingsTy::TreeTy*>(S)); |
| 305 | RegionBindingsTy::data_type* V = B.lookup(R); |
| 306 | return V ? *V : UnknownVal(); |
| 307 | } |
| 308 | |
| 309 | case loc::SymbolValKind: |
| 310 | return UnknownVal(); |
| 311 | |
| 312 | case loc::ConcreteIntKind: |
| 313 | return UndefinedVal(); // As in BasicStoreManager. |
| 314 | |
| 315 | case loc::FuncValKind: |
| 316 | return L; |
| 317 | |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 318 | default: |
| 319 | assert(false && "Invalid Location"); |
| 320 | break; |
| 321 | } |
| 322 | } |
| 323 | |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 324 | SVal RegionStoreManager::RetrieveStruct(Store store, const TypedRegion* R) { |
| 325 | QualType T = R->getType(getContext()); |
| 326 | assert(T->isStructureType()); |
| 327 | |
| 328 | const RecordType* RT = cast<RecordType>(T.getTypePtr()); |
| 329 | RecordDecl* RD = RT->getDecl(); |
| 330 | assert(RD->isDefinition()); |
| 331 | |
| 332 | llvm::ImmutableList<SVal> StructVal = getBasicVals().getEmptySValList(); |
| 333 | |
| 334 | for (int i = RD->getNumMembers() - 1; i >= 0; --i) { |
| 335 | FieldRegion* FR = MRMgr.getFieldRegion(RD->getMember(i), R); |
| 336 | RegionBindingsTy B(static_cast<const RegionBindingsTy::TreeTy*>(store)); |
Zhongxing Xu | f0dfa8d | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 337 | RegionBindingsTy::data_type* data = B.lookup(FR); |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 338 | |
| 339 | SVal FieldValue = data ? *data : UnknownVal(); |
| 340 | |
| 341 | StructVal = getBasicVals().consVals(FieldValue, StructVal); |
| 342 | } |
| 343 | |
| 344 | return NonLoc::MakeCompoundVal(T, StructVal, getBasicVals()); |
| 345 | } |
| 346 | |
Zhongxing Xu | 8485ec6 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 347 | Store RegionStoreManager::Bind(Store store, Loc LV, SVal V) { |
Zhongxing Xu | 8fe63af | 2008-10-27 09:24:07 +0000 | [diff] [blame] | 348 | if (LV.getSubKind() == loc::SymbolValKind) |
| 349 | return store; |
| 350 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 351 | assert(LV.getSubKind() == loc::MemRegionKind); |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 352 | |
Ted Kremenek | 993f1c7 | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 353 | const MemRegion* R = cast<loc::MemRegionVal>(LV).getRegion(); |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 354 | |
Zhongxing Xu | f0dfa8d | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 355 | assert(R); |
| 356 | |
| 357 | if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) |
| 358 | if (TR->getType(getContext())->isStructureType()) |
| 359 | return BindStruct(store, TR, V); |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 360 | |
| 361 | RegionBindingsTy B = GetRegionBindings(store); |
| 362 | return V.isUnknown() |
| 363 | ? RBFactory.Remove(B, R).getRoot() |
| 364 | : RBFactory.Add(B, R, V).getRoot(); |
| 365 | } |
| 366 | |
Zhongxing Xu | f0dfa8d | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 367 | Store RegionStoreManager::BindStruct(Store store, const TypedRegion* R, SVal V){ |
| 368 | QualType T = R->getType(getContext()); |
| 369 | assert(T->isStructureType()); |
| 370 | |
| 371 | const RecordType* RT = cast<RecordType>(T.getTypePtr()); |
| 372 | RecordDecl* RD = RT->getDecl(); |
Zhongxing Xu | a4f28ff | 2008-11-13 08:41:36 +0000 | [diff] [blame] | 373 | |
| 374 | if (!RD->isDefinition()) { |
| 375 | // This can only occur when a pointer of imcomplete struct type is used as a |
| 376 | // function argument. |
| 377 | assert(V.isUnknown()); |
| 378 | return store; |
| 379 | } |
Zhongxing Xu | f0dfa8d | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 380 | |
| 381 | RegionBindingsTy B = GetRegionBindings(store); |
| 382 | |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 383 | if (isa<UnknownVal>(V)) |
| 384 | return BindStructToVal(store, R, UnknownVal()); |
| 385 | |
Zhongxing Xu | f0dfa8d | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 386 | nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(V); |
| 387 | |
| 388 | nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); |
| 389 | RecordDecl::field_iterator FI = RD->field_begin(), FE = RD->field_end(); |
| 390 | |
| 391 | for (; FI != FE; ++FI, ++VI) { |
| 392 | assert(VI != VE); |
| 393 | |
| 394 | FieldRegion* FR = MRMgr.getFieldRegion(*FI, R); |
| 395 | |
| 396 | B = RBFactory.Add(B, FR, *VI); |
| 397 | } |
| 398 | |
| 399 | return B.getRoot(); |
| 400 | } |
| 401 | |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 402 | Store RegionStoreManager::getInitialStore() { |
| 403 | typedef LiveVariables::AnalysisDataTy LVDataTy; |
| 404 | LVDataTy& D = StateMgr.getLiveVariables().getAnalysisData(); |
| 405 | |
| 406 | Store St = RBFactory.GetEmptyMap().getRoot(); |
| 407 | |
| 408 | 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] | 409 | NamedDecl* ND = const_cast<NamedDecl*>(I->first); |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 410 | |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 411 | if (VarDecl* VD = dyn_cast<VarDecl>(ND)) { |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 412 | // Punt on static variables for now. |
| 413 | if (VD->getStorageClass() == VarDecl::Static) |
| 414 | continue; |
| 415 | |
| 416 | QualType T = VD->getType(); |
| 417 | // Only handle pointers and integers for now. |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 418 | if (Loc::IsLocType(T) || T->isIntegerType()) { |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 419 | // Initialize globals and parameters to symbolic values. |
| 420 | // Initialize local variables to undefined. |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 421 | SVal X = (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) || |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 422 | isa<ImplicitParamDecl>(VD)) |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 423 | ? SVal::GetSymbolValue(StateMgr.getSymbolManager(), VD) |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 424 | : UndefinedVal(); |
| 425 | |
Zhongxing Xu | 8485ec6 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 426 | St = Bind(St, getVarLoc(VD), X); |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | } |
| 430 | return St; |
| 431 | } |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 432 | |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 433 | Store RegionStoreManager::BindDecl(Store store, const VarDecl* VD, |
| 434 | SVal* InitVal, unsigned Count) { |
| 435 | |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 436 | BasicValueFactory& BasicVals = StateMgr.getBasicVals(); |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 437 | |
| 438 | if (VD->hasGlobalStorage()) { |
| 439 | // Static global variables should not be visited here. |
| 440 | assert(!(VD->getStorageClass() == VarDecl::Static && |
| 441 | VD->isFileVarDecl())); |
| 442 | // Process static variables. |
| 443 | if (VD->getStorageClass() == VarDecl::Static) { |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 444 | if (!InitVal) { |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 445 | // Only handle pointer and integer static variables. |
| 446 | |
| 447 | QualType T = VD->getType(); |
| 448 | |
| 449 | if (Loc::IsLocType(T)) |
Zhongxing Xu | 8485ec6 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 450 | store = Bind(store, getVarLoc(VD), |
| 451 | loc::ConcreteInt(BasicVals.getValue(0, T))); |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 452 | |
| 453 | else if (T->isIntegerType()) |
Zhongxing Xu | 8485ec6 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 454 | store = Bind(store, getVarLoc(VD), |
| 455 | loc::ConcreteInt(BasicVals.getValue(0, T))); |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 456 | |
| 457 | // Other types of static local variables are not handled yet. |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 458 | } else { |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 459 | store = Bind(store, getVarLoc(VD), *InitVal); |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | } else { |
| 463 | // Process local variables. |
| 464 | |
| 465 | QualType T = VD->getType(); |
| 466 | |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 467 | VarRegion* VR = MRMgr.getVarRegion(VD); |
| 468 | |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 469 | if (Loc::IsLocType(T) || T->isIntegerType()) { |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 470 | SVal V = InitVal ? *InitVal : UndefinedVal(); |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 471 | store = Bind(store, loc::MemRegionVal(VR), V); |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 472 | } |
| 473 | else if (T->isArrayType()) { |
| 474 | if (!InitVal) |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 475 | store = BindArrayToVal(store, VR, UndefinedVal()); |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 476 | else |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 477 | store = InitializeArray(store, VR, *InitVal); |
| 478 | } |
| 479 | else if (T->isStructureType()) { |
| 480 | if (!InitVal) |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 481 | store = BindStructToVal(store, VR, UndefinedVal()); |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 482 | else |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 483 | store = InitializeStruct(store, VR, *InitVal); |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 484 | } |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 485 | |
| 486 | // Other types of local variables are not handled yet. |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 487 | } |
| 488 | return store; |
| 489 | } |
| 490 | |
Zhongxing Xu | f22679e | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 491 | Store RegionStoreManager::BindCompoundLiteral(Store store, |
| 492 | const CompoundLiteralExpr* CL, |
| 493 | SVal V) { |
| 494 | CompoundLiteralRegion* R = MRMgr.getCompoundLiteralRegion(CL); |
| 495 | store = Bind(store, loc::MemRegionVal(R), V); |
| 496 | return store; |
| 497 | } |
| 498 | |
Zhongxing Xu | 8916d5b | 2008-11-10 09:39:04 +0000 | [diff] [blame] | 499 | Store RegionStoreManager::RemoveDeadBindings(Store store, Stmt* Loc, |
| 500 | const LiveVariables& Live, |
| 501 | llvm::SmallVectorImpl<const MemRegion*>& RegionRoots, |
| 502 | LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols) { |
| 503 | |
| 504 | RegionBindingsTy B = GetRegionBindings(store); |
| 505 | typedef SVal::symbol_iterator symbol_iterator; |
| 506 | |
| 507 | // FIXME: Mark all region binding value's symbol as live. We also omit symbols |
| 508 | // in SymbolicRegions. |
| 509 | for (RegionBindingsTy::iterator I = B.begin(), E = B.end(); I != E; ++I) { |
| 510 | SVal X = I.getData(); |
| 511 | for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI) |
| 512 | LSymbols.insert(*SI); |
| 513 | } |
| 514 | |
| 515 | return store; |
| 516 | } |
| 517 | |
Zhongxing Xu | a071eb0 | 2008-10-24 06:01:33 +0000 | [diff] [blame] | 518 | void RegionStoreManager::print(Store store, std::ostream& Out, |
| 519 | const char* nl, const char *sep) { |
| 520 | llvm::raw_os_ostream OS(Out); |
| 521 | RegionBindingsTy B = GetRegionBindings(store); |
| 522 | OS << "Store:" << nl; |
| 523 | |
| 524 | for (RegionBindingsTy::iterator I = B.begin(), E = B.end(); I != E; ++I) { |
| 525 | OS << ' '; I.getKey()->print(OS); OS << " : "; |
| 526 | I.getData().print(OS); OS << nl; |
| 527 | } |
Zhongxing Xu | 5b8b6f2 | 2008-10-24 04:33:15 +0000 | [diff] [blame] | 528 | } |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 529 | |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 530 | Store RegionStoreManager::InitializeArray(Store store, const TypedRegion* R, |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 531 | SVal Init) { |
| 532 | QualType T = R->getType(getContext()); |
| 533 | assert(T->isArrayType()); |
| 534 | |
| 535 | ConstantArrayType* CAT = cast<ConstantArrayType>(T.getTypePtr()); |
| 536 | |
| 537 | llvm::APInt Size = CAT->getSize(); |
| 538 | |
| 539 | llvm::APInt i = llvm::APInt::getNullValue(Size.getBitWidth()); |
| 540 | |
| 541 | nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(Init); |
| 542 | |
| 543 | nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); |
| 544 | |
| 545 | for (; i != Size; ++i) { |
| 546 | nonloc::ConcreteInt Idx(getBasicVals().getValue(llvm::APSInt(i))); |
| 547 | |
| 548 | ElementRegion* ER = MRMgr.getElementRegion(Idx, R); |
| 549 | |
| 550 | store = Bind(store, loc::MemRegionVal(ER), (VI!=VE) ? *VI : UndefinedVal()); |
| 551 | // The init list might be shorter than the array decl. |
| 552 | if (VI != VE) ++VI; |
| 553 | } |
| 554 | |
| 555 | return store; |
| 556 | } |
| 557 | |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 558 | // Bind all elements of the array to some value. |
| 559 | Store RegionStoreManager::BindArrayToVal(Store store, const TypedRegion* BaseR, |
| 560 | SVal V){ |
Zhongxing Xu | ea8a185 | 2008-10-31 11:02:48 +0000 | [diff] [blame] | 561 | QualType T = BaseR->getType(getContext()); |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 562 | assert(T->isArrayType()); |
| 563 | |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 564 | // Only handle constant size array for now. |
| 565 | if (ConstantArrayType* CAT=dyn_cast<ConstantArrayType>(T.getTypePtr())) { |
| 566 | |
| 567 | llvm::APInt Size = CAT->getSize(); |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 568 | llvm::APInt i = llvm::APInt::getNullValue(Size.getBitWidth()); |
| 569 | for (; i != Size; ++i) { |
Zhongxing Xu | ea8a185 | 2008-10-31 11:02:48 +0000 | [diff] [blame] | 570 | nonloc::ConcreteInt Idx(getBasicVals().getValue(llvm::APSInt(i))); |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 571 | |
| 572 | ElementRegion* ER = MRMgr.getElementRegion(Idx, BaseR); |
| 573 | |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 574 | store = Bind(store, loc::MemRegionVal(ER), V); |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 575 | } |
| 576 | } |
| 577 | |
| 578 | return store; |
| 579 | } |
| 580 | |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 581 | Store RegionStoreManager::InitializeStruct(Store store, const TypedRegion* R, |
Zhongxing Xu | ea8a185 | 2008-10-31 11:02:48 +0000 | [diff] [blame] | 582 | SVal Init) { |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 583 | QualType T = R->getType(getContext()); |
| 584 | assert(T->isStructureType()); |
| 585 | |
| 586 | RecordType* RT = cast<RecordType>(T.getTypePtr()); |
| 587 | RecordDecl* RD = RT->getDecl(); |
| 588 | assert(RD->isDefinition()); |
| 589 | |
| 590 | nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(Init); |
| 591 | nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); |
| 592 | RecordDecl::field_iterator FI = RD->field_begin(), FE = RD->field_end(); |
| 593 | |
| 594 | for (; FI != FE; ++FI) { |
| 595 | QualType FTy = (*FI)->getType(); |
| 596 | FieldRegion* FR = MRMgr.getFieldRegion(*FI, R); |
| 597 | |
| 598 | if (Loc::IsLocType(FTy) || FTy->isIntegerType()) { |
| 599 | if (VI != VE) { |
| 600 | store = Bind(store, loc::MemRegionVal(FR), *VI); |
| 601 | ++VI; |
| 602 | } else |
| 603 | store = Bind(store, loc::MemRegionVal(FR), UndefinedVal()); |
| 604 | } |
| 605 | else if (FTy->isArrayType()) { |
| 606 | if (VI != VE) { |
| 607 | store = InitializeArray(store, FR, *VI); |
| 608 | ++VI; |
| 609 | } else |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 610 | store = BindArrayToVal(store, FR, UndefinedVal()); |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 611 | } |
| 612 | else if (FTy->isStructureType()) { |
| 613 | if (VI != VE) { |
| 614 | store = InitializeStruct(store, FR, *VI); |
| 615 | ++VI; |
| 616 | } else |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 617 | store = BindStructToVal(store, FR, UndefinedVal()); |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | return store; |
| 621 | } |
| 622 | |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 623 | // Bind all fields of the struct to some value. |
| 624 | Store RegionStoreManager::BindStructToVal(Store store, const TypedRegion* BaseR, |
| 625 | SVal V) { |
Zhongxing Xu | ea8a185 | 2008-10-31 11:02:48 +0000 | [diff] [blame] | 626 | QualType T = BaseR->getType(getContext()); |
| 627 | assert(T->isStructureType()); |
| 628 | |
| 629 | const RecordType* RT = cast<RecordType>(T.getTypePtr()); |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 630 | RecordDecl* RD = RT->getDecl(); |
| 631 | assert(RD->isDefinition()); |
Zhongxing Xu | ea8a185 | 2008-10-31 11:02:48 +0000 | [diff] [blame] | 632 | |
| 633 | RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end(); |
| 634 | |
| 635 | for (; I != E; ++I) { |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 636 | |
| 637 | QualType FTy = (*I)->getType(); |
| 638 | FieldRegion* FR = MRMgr.getFieldRegion(*I, BaseR); |
| 639 | |
| 640 | if (Loc::IsLocType(FTy) || FTy->isIntegerType()) { |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 641 | store = Bind(store, loc::MemRegionVal(FR), V); |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 642 | |
| 643 | } else if (FTy->isArrayType()) { |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 644 | store = BindArrayToVal(store, FR, V); |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 645 | |
| 646 | } else if (FTy->isStructureType()) { |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 647 | store = BindStructToVal(store, FR, V); |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
| 651 | return store; |
| 652 | } |
Zhongxing Xu | dc0a25d | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 653 | |
| 654 | const GRState* RegionStoreManager::AddRegionView(const GRState* St, |
| 655 | const MemRegion* View, |
| 656 | const MemRegion* Base) { |
| 657 | GRStateRef state(St, StateMgr); |
| 658 | |
| 659 | // First, retrieve the region view of the base region. |
| 660 | RegionViewMapTy::data_type* d = state.get<RegionViewMapTy>(Base); |
| 661 | RegionViewTy L = d ? *d : RVFactory.GetEmptyList(); |
| 662 | |
| 663 | // Now add View to the region view. |
| 664 | L = RVFactory.Add(View, L); |
| 665 | |
| 666 | // Create a new state with the new region view. |
| 667 | return state.set<RegionViewMapTy>(Base, L); |
| 668 | } |