Zhongxing Xu | 79c57f8 | 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 | 8fbe7ae | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 19 | #include "clang/Analysis/PathSensitive/GRStateTrait.h" |
Zhongxing Xu | 79c57f8 | 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 | 8fbe7ae | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/ImmutableList.h" |
Zhongxing Xu | ca892b8 | 2008-10-24 06:01:33 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
Zhongxing Xu | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Compiler.h" |
| 26 | |
| 27 | using namespace clang; |
| 28 | |
Zhongxing Xu | 097fc98 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 29 | typedef llvm::ImmutableMap<const MemRegion*, SVal> RegionBindingsTy; |
Zhongxing Xu | 8fbe7ae | 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 | 79c57f8 | 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 | 8fbe7ae | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 46 | RegionViewTy::Factory RVFactory; |
| 47 | RegionViewMapTy::Factory RVMFactory; |
| 48 | |
Zhongxing Xu | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 49 | GRStateManager& StateMgr; |
| 50 | MemRegionManager MRMgr; |
| 51 | |
| 52 | public: |
| 53 | RegionStoreManager(GRStateManager& mgr) |
Zhongxing Xu | 8fbe7ae | 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 | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 59 | |
| 60 | virtual ~RegionStoreManager() {} |
| 61 | |
Zhongxing Xu | e4b6fc2 | 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 | d83daa5 | 2008-10-27 21:54:31 +0000 | [diff] [blame] | 68 | |
Zhongxing Xu | c88ca9d | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 69 | Store BindCompoundLiteral(Store store, const CompoundLiteralExpr* CL, SVal V); |
Zhongxing Xu | e4b6fc2 | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 70 | |
Zhongxing Xu | 2abba44 | 2008-10-25 14:18:57 +0000 | [diff] [blame] | 71 | SVal getLValueString(const GRState* St, const StringLiteral* S); |
| 72 | |
Zhongxing Xu | c88ca9d | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 73 | SVal getLValueCompoundLiteral(const GRState* St, const CompoundLiteralExpr*); |
| 74 | |
Zhongxing Xu | 6f1b515 | 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 | 0972d0a | 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 | 0a322a5 | 2008-11-16 07:06:26 +0000 | [diff] [blame] | 85 | std::pair<const GRState*, SVal> |
| 86 | CastRegion(const GRState* St, SVal VoidPtr, QualType CastToTy, Stmt* CastE); |
Zhongxing Xu | 8fbe7ae | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 87 | |
Zhongxing Xu | e4b6fc2 | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 88 | SVal Retrieve(Store S, Loc L, QualType T = QualType()); |
Zhongxing Xu | 6f1b515 | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 89 | |
Zhongxing Xu | 7324932 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 90 | Store Bind(Store St, Loc LV, SVal V); |
Zhongxing Xu | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 91 | |
Zhongxing Xu | e4b6fc2 | 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 | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 97 | Store getInitialStore(); |
Ted Kremenek | 73a36c9 | 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 | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 106 | |
Zhongxing Xu | e4b6fc2 | 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 | ab42da3 | 2008-11-10 09:39:04 +0000 | [diff] [blame] | 109 | LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols); |
Zhongxing Xu | e4b6fc2 | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 110 | |
Ted Kremenek | 37b78a1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 111 | Store BindDecl(Store store, const VarDecl* VD, SVal* InitVal, unsigned Count); |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 112 | |
Zhongxing Xu | 79c57f8 | 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 | e4b6fc2 | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 116 | |
Zhongxing Xu | 6149e88 | 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 | e4b6fc2 | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 118 | |
| 119 | void iterBindings(Store store, BindingsHandler& f) { |
| 120 | // FIXME: Implement. |
| 121 | } |
Zhongxing Xu | 702d470 | 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 | 9ef12d3 | 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 | 6f267e5 | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 132 | |
| 133 | SVal RetrieveStruct(Store store, const TypedRegion* R); |
Zhongxing Xu | 29454f4 | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 134 | Store BindStruct(Store store, const TypedRegion* R, SVal V); |
Zhongxing Xu | 6f267e5 | 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 | 8fbe7ae | 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 | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | } // end anonymous namespace |
| 144 | |
Ted Kremenek | c380399 | 2008-10-24 01:04:59 +0000 | [diff] [blame] | 145 | StoreManager* clang::CreateRegionStoreManager(GRStateManager& StMgr) { |
Zhongxing Xu | e4b6fc2 | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 146 | return new RegionStoreManager(StMgr); |
Ted Kremenek | c380399 | 2008-10-24 01:04:59 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Zhongxing Xu | 2abba44 | 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 | 6f1b515 | 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 | c88ca9d | 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 | 6f1b515 | 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 | 6f1b515 | 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 | edfbcd9 | 2008-11-07 08:57:30 +0000 | [diff] [blame] | 198 | assert(0 && "Unhandled Base."); |
Zhongxing Xu | 6f1b515 | 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 | 0972d0a | 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 | 13a05fa | 2008-10-27 12:23:17 +0000 | [diff] [blame] | 210 | if (isa<loc::SymbolVal>(Base)) |
| 211 | return Base; |
| 212 | |
Zhongxing Xu | 0972d0a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 213 | loc::MemRegionVal& BaseL = cast<loc::MemRegionVal>(Base); |
| 214 | |
Zhongxing Xu | 853c6f6 | 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 | 0972d0a | 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 | ec12b81 | 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 | 0972d0a | 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 | 2abba44 | 2008-10-25 14:18:57 +0000 | [diff] [blame] | 259 | BasicValueFactory& BasicVals = StateMgr.getBasicVals(); |
| 260 | |
Zhongxing Xu | b7d9bb5 | 2008-11-15 05:18:50 +0000 | [diff] [blame] | 261 | nonloc::ConcreteInt Idx(BasicVals.getZeroWithPtrWidth(false)); |
Zhongxing Xu | 5ac8bf1 | 2008-10-26 02:23:57 +0000 | [diff] [blame] | 262 | ElementRegion* ER = MRMgr.getElementRegion(Idx, ArrayR); |
| 263 | |
| 264 | return loc::MemRegionVal(ER); |
Zhongxing Xu | 0972d0a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Zhongxing Xu | 0a322a5 | 2008-11-16 07:06:26 +0000 | [diff] [blame] | 267 | std::pair<const GRState*, SVal> |
| 268 | RegionStoreManager::CastRegion(const GRState* St, SVal VoidPtr, |
| 269 | QualType CastToTy, Stmt* CastE) { |
Zhongxing Xu | 8fbe7ae | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 270 | if (const AllocaRegion* AR = |
| 271 | dyn_cast<AllocaRegion>(cast<loc::MemRegionVal>(VoidPtr).getRegion())) { |
| 272 | |
| 273 | // Create a new region to attach type information to it. |
| 274 | const AnonTypedRegion* TR = MRMgr.getAnonTypedRegion(CastToTy, AR); |
| 275 | |
| 276 | // Get the pointer to the first element. |
| 277 | nonloc::ConcreteInt Idx(getBasicVals().getZeroWithPtrWidth(false)); |
| 278 | const ElementRegion* ER = MRMgr.getElementRegion(Idx, TR); |
| 279 | |
Zhongxing Xu | 8fbe7ae | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 280 | // Add a RegionView to base region. |
Zhongxing Xu | 0a322a5 | 2008-11-16 07:06:26 +0000 | [diff] [blame] | 281 | return std::pair<const GRState*, SVal>(AddRegionView(St, TR, AR), |
| 282 | loc::MemRegionVal(ER)); |
Zhongxing Xu | 8fbe7ae | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | // Default case. |
Zhongxing Xu | 0a322a5 | 2008-11-16 07:06:26 +0000 | [diff] [blame] | 286 | return std::pair<const GRState*, SVal>(St, UnknownVal()); |
Zhongxing Xu | 8fbe7ae | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Zhongxing Xu | 7324932 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 289 | SVal RegionStoreManager::Retrieve(Store S, Loc L, QualType T) { |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 290 | assert(!isa<UnknownVal>(L) && "location unknown"); |
| 291 | assert(!isa<UndefinedVal>(L) && "location undefined"); |
| 292 | |
| 293 | switch (L.getSubKind()) { |
| 294 | case loc::MemRegionKind: { |
| 295 | const MemRegion* R = cast<loc::MemRegionVal>(L).getRegion(); |
| 296 | assert(R && "bad region"); |
| 297 | |
Zhongxing Xu | 6f267e5 | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 298 | if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) |
| 299 | if (TR->getType(getContext())->isStructureType()) |
| 300 | return RetrieveStruct(S, TR); |
| 301 | |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 302 | RegionBindingsTy B(static_cast<const RegionBindingsTy::TreeTy*>(S)); |
| 303 | RegionBindingsTy::data_type* V = B.lookup(R); |
| 304 | return V ? *V : UnknownVal(); |
| 305 | } |
| 306 | |
| 307 | case loc::SymbolValKind: |
| 308 | return UnknownVal(); |
| 309 | |
| 310 | case loc::ConcreteIntKind: |
| 311 | return UndefinedVal(); // As in BasicStoreManager. |
| 312 | |
| 313 | case loc::FuncValKind: |
| 314 | return L; |
| 315 | |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 316 | default: |
| 317 | assert(false && "Invalid Location"); |
Ted Kremenek | 2ced1b3 | 2008-11-19 00:27:37 +0000 | [diff] [blame^] | 318 | return L; |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
Zhongxing Xu | 6f267e5 | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 322 | SVal RegionStoreManager::RetrieveStruct(Store store, const TypedRegion* R) { |
| 323 | QualType T = R->getType(getContext()); |
| 324 | assert(T->isStructureType()); |
| 325 | |
| 326 | const RecordType* RT = cast<RecordType>(T.getTypePtr()); |
| 327 | RecordDecl* RD = RT->getDecl(); |
| 328 | assert(RD->isDefinition()); |
| 329 | |
| 330 | llvm::ImmutableList<SVal> StructVal = getBasicVals().getEmptySValList(); |
| 331 | |
| 332 | for (int i = RD->getNumMembers() - 1; i >= 0; --i) { |
| 333 | FieldRegion* FR = MRMgr.getFieldRegion(RD->getMember(i), R); |
| 334 | RegionBindingsTy B(static_cast<const RegionBindingsTy::TreeTy*>(store)); |
Zhongxing Xu | 29454f4 | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 335 | RegionBindingsTy::data_type* data = B.lookup(FR); |
Zhongxing Xu | 6f267e5 | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 336 | |
| 337 | SVal FieldValue = data ? *data : UnknownVal(); |
| 338 | |
| 339 | StructVal = getBasicVals().consVals(FieldValue, StructVal); |
| 340 | } |
| 341 | |
| 342 | return NonLoc::MakeCompoundVal(T, StructVal, getBasicVals()); |
| 343 | } |
| 344 | |
Zhongxing Xu | 7324932 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 345 | Store RegionStoreManager::Bind(Store store, Loc LV, SVal V) { |
Zhongxing Xu | e7c8a13 | 2008-10-27 09:24:07 +0000 | [diff] [blame] | 346 | if (LV.getSubKind() == loc::SymbolValKind) |
| 347 | return store; |
| 348 | |
Zhongxing Xu | 097fc98 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 349 | assert(LV.getSubKind() == loc::MemRegionKind); |
Zhongxing Xu | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 350 | |
Ted Kremenek | 38a4b4b | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 351 | const MemRegion* R = cast<loc::MemRegionVal>(LV).getRegion(); |
Zhongxing Xu | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 352 | |
Zhongxing Xu | 29454f4 | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 353 | assert(R); |
| 354 | |
| 355 | if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) |
| 356 | if (TR->getType(getContext())->isStructureType()) |
| 357 | return BindStruct(store, TR, V); |
Zhongxing Xu | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 358 | |
| 359 | RegionBindingsTy B = GetRegionBindings(store); |
| 360 | return V.isUnknown() |
| 361 | ? RBFactory.Remove(B, R).getRoot() |
| 362 | : RBFactory.Add(B, R, V).getRoot(); |
| 363 | } |
| 364 | |
Zhongxing Xu | 29454f4 | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 365 | Store RegionStoreManager::BindStruct(Store store, const TypedRegion* R, SVal V){ |
| 366 | QualType T = R->getType(getContext()); |
| 367 | assert(T->isStructureType()); |
| 368 | |
| 369 | const RecordType* RT = cast<RecordType>(T.getTypePtr()); |
| 370 | RecordDecl* RD = RT->getDecl(); |
Zhongxing Xu | ca1c252 | 2008-11-13 08:41:36 +0000 | [diff] [blame] | 371 | |
| 372 | if (!RD->isDefinition()) { |
| 373 | // This can only occur when a pointer of imcomplete struct type is used as a |
| 374 | // function argument. |
| 375 | assert(V.isUnknown()); |
| 376 | return store; |
| 377 | } |
Zhongxing Xu | 29454f4 | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 378 | |
| 379 | RegionBindingsTy B = GetRegionBindings(store); |
| 380 | |
Zhongxing Xu | 9ef12d3 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 381 | if (isa<UnknownVal>(V)) |
| 382 | return BindStructToVal(store, R, UnknownVal()); |
| 383 | |
Zhongxing Xu | 29454f4 | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 384 | nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(V); |
| 385 | |
| 386 | nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); |
| 387 | RecordDecl::field_iterator FI = RD->field_begin(), FE = RD->field_end(); |
| 388 | |
| 389 | for (; FI != FE; ++FI, ++VI) { |
| 390 | assert(VI != VE); |
| 391 | |
| 392 | FieldRegion* FR = MRMgr.getFieldRegion(*FI, R); |
| 393 | |
| 394 | B = RBFactory.Add(B, FR, *VI); |
| 395 | } |
| 396 | |
| 397 | return B.getRoot(); |
| 398 | } |
| 399 | |
Zhongxing Xu | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 400 | Store RegionStoreManager::getInitialStore() { |
| 401 | typedef LiveVariables::AnalysisDataTy LVDataTy; |
| 402 | LVDataTy& D = StateMgr.getLiveVariables().getAnalysisData(); |
| 403 | |
| 404 | Store St = RBFactory.GetEmptyMap().getRoot(); |
| 405 | |
| 406 | for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) { |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 407 | NamedDecl* ND = const_cast<NamedDecl*>(I->first); |
Zhongxing Xu | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 408 | |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 409 | if (VarDecl* VD = dyn_cast<VarDecl>(ND)) { |
Zhongxing Xu | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 410 | // Punt on static variables for now. |
| 411 | if (VD->getStorageClass() == VarDecl::Static) |
| 412 | continue; |
| 413 | |
| 414 | QualType T = VD->getType(); |
| 415 | // Only handle pointers and integers for now. |
Zhongxing Xu | 097fc98 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 416 | if (Loc::IsLocType(T) || T->isIntegerType()) { |
Zhongxing Xu | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 417 | // Initialize globals and parameters to symbolic values. |
| 418 | // Initialize local variables to undefined. |
Zhongxing Xu | 097fc98 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 419 | SVal X = (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) || |
Zhongxing Xu | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 420 | isa<ImplicitParamDecl>(VD)) |
Zhongxing Xu | 097fc98 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 421 | ? SVal::GetSymbolValue(StateMgr.getSymbolManager(), VD) |
Zhongxing Xu | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 422 | : UndefinedVal(); |
| 423 | |
Zhongxing Xu | 7324932 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 424 | St = Bind(St, getVarLoc(VD), X); |
Zhongxing Xu | 79c57f8 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | } |
| 428 | return St; |
| 429 | } |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 430 | |
Ted Kremenek | 37b78a1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 431 | Store RegionStoreManager::BindDecl(Store store, const VarDecl* VD, |
| 432 | SVal* InitVal, unsigned Count) { |
| 433 | |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 434 | BasicValueFactory& BasicVals = StateMgr.getBasicVals(); |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 435 | |
| 436 | if (VD->hasGlobalStorage()) { |
| 437 | // Static global variables should not be visited here. |
| 438 | assert(!(VD->getStorageClass() == VarDecl::Static && |
| 439 | VD->isFileVarDecl())); |
| 440 | // Process static variables. |
| 441 | if (VD->getStorageClass() == VarDecl::Static) { |
Ted Kremenek | 37b78a1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 442 | if (!InitVal) { |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 443 | // Only handle pointer and integer static variables. |
| 444 | |
| 445 | QualType T = VD->getType(); |
| 446 | |
| 447 | if (Loc::IsLocType(T)) |
Zhongxing Xu | 7324932 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 448 | store = Bind(store, getVarLoc(VD), |
| 449 | loc::ConcreteInt(BasicVals.getValue(0, T))); |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 450 | |
| 451 | else if (T->isIntegerType()) |
Zhongxing Xu | 7324932 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 452 | store = Bind(store, getVarLoc(VD), |
| 453 | loc::ConcreteInt(BasicVals.getValue(0, T))); |
Zhongxing Xu | b30a073 | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 454 | |
| 455 | // Other types of static local variables are not handled yet. |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 456 | } else { |
Ted Kremenek | 37b78a1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 457 | store = Bind(store, getVarLoc(VD), *InitVal); |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | } else { |
| 461 | // Process local variables. |
| 462 | |
| 463 | QualType T = VD->getType(); |
| 464 | |
Zhongxing Xu | 702d470 | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 465 | VarRegion* VR = MRMgr.getVarRegion(VD); |
| 466 | |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 467 | if (Loc::IsLocType(T) || T->isIntegerType()) { |
Ted Kremenek | 37b78a1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 468 | SVal V = InitVal ? *InitVal : UndefinedVal(); |
Zhongxing Xu | 702d470 | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 469 | store = Bind(store, loc::MemRegionVal(VR), V); |
Ted Kremenek | 37b78a1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 470 | } |
| 471 | else if (T->isArrayType()) { |
| 472 | if (!InitVal) |
Zhongxing Xu | 9ef12d3 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 473 | store = BindArrayToVal(store, VR, UndefinedVal()); |
Zhongxing Xu | b30a073 | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 474 | else |
Ted Kremenek | 37b78a1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 475 | store = InitializeArray(store, VR, *InitVal); |
| 476 | } |
| 477 | else if (T->isStructureType()) { |
| 478 | if (!InitVal) |
Zhongxing Xu | 9ef12d3 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 479 | store = BindStructToVal(store, VR, UndefinedVal()); |
Zhongxing Xu | c00c55a | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 480 | else |
Ted Kremenek | 37b78a1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 481 | store = InitializeStruct(store, VR, *InitVal); |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 482 | } |
Zhongxing Xu | b30a073 | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 483 | |
| 484 | // Other types of local variables are not handled yet. |
Zhongxing Xu | e3954d1 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 485 | } |
| 486 | return store; |
| 487 | } |
| 488 | |
Zhongxing Xu | c88ca9d | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 489 | Store RegionStoreManager::BindCompoundLiteral(Store store, |
| 490 | const CompoundLiteralExpr* CL, |
| 491 | SVal V) { |
| 492 | CompoundLiteralRegion* R = MRMgr.getCompoundLiteralRegion(CL); |
| 493 | store = Bind(store, loc::MemRegionVal(R), V); |
| 494 | return store; |
| 495 | } |
| 496 | |
Zhongxing Xu | ab42da3 | 2008-11-10 09:39:04 +0000 | [diff] [blame] | 497 | Store RegionStoreManager::RemoveDeadBindings(Store store, Stmt* Loc, |
| 498 | const LiveVariables& Live, |
| 499 | llvm::SmallVectorImpl<const MemRegion*>& RegionRoots, |
| 500 | LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols) { |
| 501 | |
| 502 | RegionBindingsTy B = GetRegionBindings(store); |
| 503 | typedef SVal::symbol_iterator symbol_iterator; |
| 504 | |
| 505 | // FIXME: Mark all region binding value's symbol as live. We also omit symbols |
| 506 | // in SymbolicRegions. |
| 507 | for (RegionBindingsTy::iterator I = B.begin(), E = B.end(); I != E; ++I) { |
| 508 | SVal X = I.getData(); |
| 509 | for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI) |
| 510 | LSymbols.insert(*SI); |
| 511 | } |
| 512 | |
| 513 | return store; |
| 514 | } |
| 515 | |
Zhongxing Xu | ca892b8 | 2008-10-24 06:01:33 +0000 | [diff] [blame] | 516 | void RegionStoreManager::print(Store store, std::ostream& Out, |
| 517 | const char* nl, const char *sep) { |
| 518 | llvm::raw_os_ostream OS(Out); |
| 519 | RegionBindingsTy B = GetRegionBindings(store); |
| 520 | OS << "Store:" << nl; |
| 521 | |
| 522 | for (RegionBindingsTy::iterator I = B.begin(), E = B.end(); I != E; ++I) { |
| 523 | OS << ' '; I.getKey()->print(OS); OS << " : "; |
| 524 | I.getData().print(OS); OS << nl; |
| 525 | } |
Zhongxing Xu | 6149e88 | 2008-10-24 04:33:15 +0000 | [diff] [blame] | 526 | } |
Zhongxing Xu | 702d470 | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 527 | |
Zhongxing Xu | 9ef12d3 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 528 | Store RegionStoreManager::InitializeArray(Store store, const TypedRegion* R, |
Zhongxing Xu | b30a073 | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 529 | SVal Init) { |
| 530 | QualType T = R->getType(getContext()); |
| 531 | assert(T->isArrayType()); |
| 532 | |
| 533 | ConstantArrayType* CAT = cast<ConstantArrayType>(T.getTypePtr()); |
| 534 | |
| 535 | llvm::APInt Size = CAT->getSize(); |
| 536 | |
| 537 | llvm::APInt i = llvm::APInt::getNullValue(Size.getBitWidth()); |
| 538 | |
| 539 | nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(Init); |
| 540 | |
| 541 | nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); |
| 542 | |
| 543 | for (; i != Size; ++i) { |
| 544 | nonloc::ConcreteInt Idx(getBasicVals().getValue(llvm::APSInt(i))); |
| 545 | |
| 546 | ElementRegion* ER = MRMgr.getElementRegion(Idx, R); |
| 547 | |
| 548 | store = Bind(store, loc::MemRegionVal(ER), (VI!=VE) ? *VI : UndefinedVal()); |
| 549 | // The init list might be shorter than the array decl. |
| 550 | if (VI != VE) ++VI; |
| 551 | } |
| 552 | |
| 553 | return store; |
| 554 | } |
| 555 | |
Zhongxing Xu | 9ef12d3 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 556 | // Bind all elements of the array to some value. |
| 557 | Store RegionStoreManager::BindArrayToVal(Store store, const TypedRegion* BaseR, |
| 558 | SVal V){ |
Zhongxing Xu | 3dd9ec8 | 2008-10-31 11:02:48 +0000 | [diff] [blame] | 559 | QualType T = BaseR->getType(getContext()); |
Zhongxing Xu | 702d470 | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 560 | assert(T->isArrayType()); |
| 561 | |
Zhongxing Xu | 702d470 | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 562 | // Only handle constant size array for now. |
| 563 | if (ConstantArrayType* CAT=dyn_cast<ConstantArrayType>(T.getTypePtr())) { |
| 564 | |
| 565 | llvm::APInt Size = CAT->getSize(); |
Zhongxing Xu | b30a073 | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 566 | llvm::APInt i = llvm::APInt::getNullValue(Size.getBitWidth()); |
| 567 | for (; i != Size; ++i) { |
Zhongxing Xu | 3dd9ec8 | 2008-10-31 11:02:48 +0000 | [diff] [blame] | 568 | nonloc::ConcreteInt Idx(getBasicVals().getValue(llvm::APSInt(i))); |
Zhongxing Xu | 702d470 | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 569 | |
| 570 | ElementRegion* ER = MRMgr.getElementRegion(Idx, BaseR); |
| 571 | |
Zhongxing Xu | 42ca6cc | 2008-11-18 13:11:04 +0000 | [diff] [blame] | 572 | if (CAT->getElementType()->isStructureType()) |
| 573 | store = BindStructToVal(store, ER, V); |
| 574 | else |
| 575 | store = Bind(store, loc::MemRegionVal(ER), V); |
Zhongxing Xu | 702d470 | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | |
| 579 | return store; |
| 580 | } |
| 581 | |
Zhongxing Xu | 9ef12d3 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 582 | Store RegionStoreManager::InitializeStruct(Store store, const TypedRegion* R, |
Zhongxing Xu | 3dd9ec8 | 2008-10-31 11:02:48 +0000 | [diff] [blame] | 583 | SVal Init) { |
Zhongxing Xu | c00c55a | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 584 | QualType T = R->getType(getContext()); |
| 585 | assert(T->isStructureType()); |
| 586 | |
| 587 | RecordType* RT = cast<RecordType>(T.getTypePtr()); |
| 588 | RecordDecl* RD = RT->getDecl(); |
| 589 | assert(RD->isDefinition()); |
| 590 | |
| 591 | nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(Init); |
| 592 | nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); |
| 593 | RecordDecl::field_iterator FI = RD->field_begin(), FE = RD->field_end(); |
| 594 | |
| 595 | for (; FI != FE; ++FI) { |
| 596 | QualType FTy = (*FI)->getType(); |
| 597 | FieldRegion* FR = MRMgr.getFieldRegion(*FI, R); |
| 598 | |
| 599 | if (Loc::IsLocType(FTy) || FTy->isIntegerType()) { |
| 600 | if (VI != VE) { |
| 601 | store = Bind(store, loc::MemRegionVal(FR), *VI); |
| 602 | ++VI; |
| 603 | } else |
| 604 | store = Bind(store, loc::MemRegionVal(FR), UndefinedVal()); |
| 605 | } |
| 606 | else if (FTy->isArrayType()) { |
| 607 | if (VI != VE) { |
| 608 | store = InitializeArray(store, FR, *VI); |
| 609 | ++VI; |
| 610 | } else |
Zhongxing Xu | 9ef12d3 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 611 | store = BindArrayToVal(store, FR, UndefinedVal()); |
Zhongxing Xu | c00c55a | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 612 | } |
| 613 | else if (FTy->isStructureType()) { |
| 614 | if (VI != VE) { |
| 615 | store = InitializeStruct(store, FR, *VI); |
| 616 | ++VI; |
| 617 | } else |
Zhongxing Xu | 9ef12d3 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 618 | store = BindStructToVal(store, FR, UndefinedVal()); |
Zhongxing Xu | c00c55a | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | return store; |
| 622 | } |
| 623 | |
Zhongxing Xu | 9ef12d3 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 624 | // Bind all fields of the struct to some value. |
| 625 | Store RegionStoreManager::BindStructToVal(Store store, const TypedRegion* BaseR, |
| 626 | SVal V) { |
Zhongxing Xu | 3dd9ec8 | 2008-10-31 11:02:48 +0000 | [diff] [blame] | 627 | QualType T = BaseR->getType(getContext()); |
| 628 | assert(T->isStructureType()); |
| 629 | |
| 630 | const RecordType* RT = cast<RecordType>(T.getTypePtr()); |
Zhongxing Xu | 702d470 | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 631 | RecordDecl* RD = RT->getDecl(); |
| 632 | assert(RD->isDefinition()); |
Zhongxing Xu | 3dd9ec8 | 2008-10-31 11:02:48 +0000 | [diff] [blame] | 633 | |
| 634 | RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end(); |
| 635 | |
| 636 | for (; I != E; ++I) { |
Zhongxing Xu | 702d470 | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 637 | |
| 638 | QualType FTy = (*I)->getType(); |
| 639 | FieldRegion* FR = MRMgr.getFieldRegion(*I, BaseR); |
| 640 | |
| 641 | if (Loc::IsLocType(FTy) || FTy->isIntegerType()) { |
Zhongxing Xu | 9ef12d3 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 642 | store = Bind(store, loc::MemRegionVal(FR), V); |
Zhongxing Xu | 702d470 | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 643 | |
| 644 | } else if (FTy->isArrayType()) { |
Zhongxing Xu | 9ef12d3 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 645 | store = BindArrayToVal(store, FR, V); |
Zhongxing Xu | 702d470 | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 646 | |
| 647 | } else if (FTy->isStructureType()) { |
Zhongxing Xu | 9ef12d3 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 648 | store = BindStructToVal(store, FR, V); |
Zhongxing Xu | 702d470 | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
| 652 | return store; |
| 653 | } |
Zhongxing Xu | 8fbe7ae | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 654 | |
| 655 | const GRState* RegionStoreManager::AddRegionView(const GRState* St, |
| 656 | const MemRegion* View, |
| 657 | const MemRegion* Base) { |
| 658 | GRStateRef state(St, StateMgr); |
| 659 | |
| 660 | // First, retrieve the region view of the base region. |
| 661 | RegionViewMapTy::data_type* d = state.get<RegionViewMapTy>(Base); |
| 662 | RegionViewTy L = d ? *d : RVFactory.GetEmptyList(); |
| 663 | |
| 664 | // Now add View to the region view. |
| 665 | L = RVFactory.Add(View, L); |
| 666 | |
| 667 | // Create a new state with the new region view. |
| 668 | return state.set<RegionViewMapTy>(Base, L); |
| 669 | } |