blob: 06292d20d8ca93edce4e5b4d26003d1795dec8cd [file] [log] [blame]
Zhongxing Xu17892752008-10-08 02:50:44 +00001//== 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 Xudc0a25d2008-11-16 04:07:26 +000019#include "clang/Analysis/PathSensitive/GRStateTrait.h"
Zhongxing Xu17892752008-10-08 02:50:44 +000020#include "clang/Analysis/Analyses/LiveVariables.h"
21
22#include "llvm/ADT/ImmutableMap.h"
Zhongxing Xudc0a25d2008-11-16 04:07:26 +000023#include "llvm/ADT/ImmutableList.h"
Zhongxing Xua071eb02008-10-24 06:01:33 +000024#include "llvm/Support/raw_ostream.h"
Zhongxing Xu17892752008-10-08 02:50:44 +000025#include "llvm/Support/Compiler.h"
26
27using namespace clang;
28
Zhongxing Xubaf03a72008-11-24 09:44:56 +000029// Actual Store type.
Zhongxing Xu1c96b242008-10-17 05:57:07 +000030typedef llvm::ImmutableMap<const MemRegion*, SVal> RegionBindingsTy;
Zhongxing Xubaf03a72008-11-24 09:44:56 +000031
32// RegionView GDM stuff.
Zhongxing Xudc0a25d2008-11-16 04:07:26 +000033typedef llvm::ImmutableList<const MemRegion*> RegionViewTy;
34typedef llvm::ImmutableMap<const MemRegion*, RegionViewTy> RegionViewMapTy;
Zhongxing Xudc0a25d2008-11-16 04:07:26 +000035static int RegionViewMapTyIndex = 0;
Zhongxing Xudc0a25d2008-11-16 04:07:26 +000036namespace clang {
37template<> struct GRStateTrait<RegionViewMapTy>
38 : public GRStatePartialTrait<RegionViewMapTy> {
39 static void* GDMIndex() { return &RegionViewMapTyIndex; }
40};
41}
Zhongxing Xu17892752008-10-08 02:50:44 +000042
Zhongxing Xubaf03a72008-11-24 09:44:56 +000043// RegionExtents GDM stuff.
44// Currently RegionExtents are in bytes. We can change this representation when
45// there are real requirements.
46typedef llvm::ImmutableMap<const MemRegion*, SVal> RegionExtentsTy;
47static int RegionExtentsTyIndex = 0;
48namespace clang {
49template<> struct GRStateTrait<RegionExtentsTy>
50 : public GRStatePartialTrait<RegionExtentsTy> {
51 static void* GDMIndex() { return &RegionExtentsTyIndex; }
52};
53}
54
Ted Kremenekc48ea6e2008-12-04 02:08:27 +000055// KillSet GDM stuff.
Ted Kremenek2ed14be2008-12-05 00:47:52 +000056typedef llvm::ImmutableSet<const MemRegion*> RegionKills;
57static int RegionKillsIndex = 0;
Ted Kremenekc48ea6e2008-12-04 02:08:27 +000058namespace clang {
Ted Kremenek2ed14be2008-12-05 00:47:52 +000059 template<> struct GRStateTrait<RegionKills>
60 : public GRStatePartialTrait<RegionKills> {
61 static void* GDMIndex() { return &RegionKillsIndex; }
Ted Kremenekc48ea6e2008-12-04 02:08:27 +000062 };
63}
64
Zhongxing Xu4193eca2008-12-20 06:32:12 +000065// Regions that have default value zero.
66// FIXME: redefinition!
67// typedef llvm::ImmutableMap<const MemRegion*, SVal> RegionDefaultValue;
68// static int RegionDefaultValueIndex = 0;
69// namespace clang {
70// template<> struct GRStateTrait<RegionDefaultValue>
71// : public GRStatePartialTrait<RegionDefaultValue> {
72// static void* GDMIndex() { return &RegionDefaultValueIndex; }
73// };
74// }
Ted Kremenekc48ea6e2008-12-04 02:08:27 +000075
Zhongxing Xu17892752008-10-08 02:50:44 +000076namespace {
77
78class VISIBILITY_HIDDEN RegionStoreManager : public StoreManager {
79 RegionBindingsTy::Factory RBFactory;
Zhongxing Xudc0a25d2008-11-16 04:07:26 +000080 RegionViewTy::Factory RVFactory;
Zhongxing Xudc0a25d2008-11-16 04:07:26 +000081
Zhongxing Xu17892752008-10-08 02:50:44 +000082 GRStateManager& StateMgr;
83 MemRegionManager MRMgr;
84
85public:
86 RegionStoreManager(GRStateManager& mgr)
Zhongxing Xudc0a25d2008-11-16 04:07:26 +000087 : RBFactory(mgr.getAllocator()),
88 RVFactory(mgr.getAllocator()),
Zhongxing Xudc0a25d2008-11-16 04:07:26 +000089 StateMgr(mgr),
90 MRMgr(StateMgr.getAllocator()) {}
Zhongxing Xu17892752008-10-08 02:50:44 +000091
92 virtual ~RegionStoreManager() {}
93
Zhongxing Xu24194ef2008-10-24 01:38:55 +000094 MemRegionManager& getRegionManager() { return MRMgr; }
Ted Kremenek4f090272008-10-27 21:54:31 +000095
Zhongxing Xu4193eca2008-12-20 06:32:12 +000096 const GRState* BindCompoundLiteral(const GRState* St,
97 const CompoundLiteralExpr* CL, SVal V);
Zhongxing Xu24194ef2008-10-24 01:38:55 +000098
Zhongxing Xu143bf822008-10-25 14:18:57 +000099 SVal getLValueString(const GRState* St, const StringLiteral* S);
100
Zhongxing Xuf22679e2008-11-07 10:38:33 +0000101 SVal getLValueCompoundLiteral(const GRState* St, const CompoundLiteralExpr*);
102
Zhongxing Xuc4bf72c2008-10-22 13:44:38 +0000103 SVal getLValueVar(const GRState* St, const VarDecl* VD);
104
105 SVal getLValueIvar(const GRState* St, const ObjCIvarDecl* D, SVal Base);
106
107 SVal getLValueField(const GRState* St, SVal Base, const FieldDecl* D);
108
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000109 SVal getLValueElement(const GRState* St, SVal Base, SVal Offset);
110
Zhongxing Xue8a964b2008-11-22 13:21:46 +0000111 SVal getSizeInElements(const GRState* St, const MemRegion* R);
112
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000113 SVal ArrayToPointer(SVal Array);
114
Ted Kremenek6eddeb12008-12-13 21:49:13 +0000115 /// CastRegion - Used by GRExprEngine::VisitCast to handle casts from
116 /// a MemRegion* to a specific location type. 'R' is the region being
117 /// casted and 'CastToTy' the result type of the cast.
118 CastResult CastRegion(const GRState* state, const MemRegion* R,
119 QualType CastToTy);
Zhongxing Xudc0a25d2008-11-16 04:07:26 +0000120
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000121 /// The high level logic for this method is this:
122 /// Retrieve (L)
123 /// if L has binding
124 /// return L's binding
125 /// else if L is in killset
126 /// return unknown
127 /// else
128 /// if L is on stack or heap
129 /// return undefined
130 /// else
131 /// return symbolic
Ted Kremenek2ed14be2008-12-05 00:47:52 +0000132 SVal Retrieve(const GRState* state, Loc L, QualType T = QualType());
Zhongxing Xuc4bf72c2008-10-22 13:44:38 +0000133
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000134 const GRState* Bind(const GRState* St, Loc LV, SVal V);
Zhongxing Xu17892752008-10-08 02:50:44 +0000135
Zhongxing Xu9c9ca082008-12-16 02:36:30 +0000136 Store Remove(Store store, Loc LV);
Zhongxing Xu24194ef2008-10-24 01:38:55 +0000137
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000138 Store getInitialStore() { return RBFactory.GetEmptyMap().getRoot(); }
Ted Kremenek9deb0e32008-10-24 20:32:16 +0000139
140 /// getSelfRegion - Returns the region for the 'self' (Objective-C) or
141 /// 'this' object (C++). When used when analyzing a normal function this
142 /// method returns NULL.
143 const MemRegion* getSelfRegion(Store) {
144 assert (false && "Not implemented.");
145 return 0;
146 }
Ted Kremenekc48ea6e2008-12-04 02:08:27 +0000147
Ted Kremenek2ed14be2008-12-05 00:47:52 +0000148 /// RemoveDeadBindings - Scans the RegionStore of 'state' for dead values.
149 /// It returns a new Store with these values removed, and populates LSymbols
150 // and DSymbols with the known set of live and dead symbols respectively.
151 Store RemoveDeadBindings(const GRState* state, Stmt* Loc,
152 const LiveVariables& Live,
Zhongxing Xu24194ef2008-10-24 01:38:55 +0000153 llvm::SmallVectorImpl<const MemRegion*>& RegionRoots,
Zhongxing Xu8916d5b2008-11-10 09:39:04 +0000154 LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols);
Ted Kremenek2ed14be2008-12-05 00:47:52 +0000155
Ted Kremenekc48ea6e2008-12-04 02:08:27 +0000156 void UpdateLiveSymbols(SVal X, LiveSymbolsTy& LSymbols);
Zhongxing Xu24194ef2008-10-24 01:38:55 +0000157
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000158 const GRState* BindDecl(const GRState* St, const VarDecl* VD, SVal InitVal);
159
160 const GRState* BindDeclWithNoInit(const GRState* St, const VarDecl* VD) {
161 return St;
162 }
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000163
Zhongxing Xubaf03a72008-11-24 09:44:56 +0000164 const GRState* setExtent(const GRState* St, const MemRegion* R, SVal Extent);
165
Zhongxing Xu17892752008-10-08 02:50:44 +0000166 static inline RegionBindingsTy GetRegionBindings(Store store) {
Zhongxing Xu9c9ca082008-12-16 02:36:30 +0000167 return RegionBindingsTy(static_cast<const RegionBindingsTy::TreeTy*>(store));
Zhongxing Xu17892752008-10-08 02:50:44 +0000168 }
Zhongxing Xu24194ef2008-10-24 01:38:55 +0000169
Zhongxing Xu5b8b6f22008-10-24 04:33:15 +0000170 void print(Store store, std::ostream& Out, const char* nl, const char *sep);
Zhongxing Xu24194ef2008-10-24 01:38:55 +0000171
172 void iterBindings(Store store, BindingsHandler& f) {
173 // FIXME: Implement.
174 }
Zhongxing Xua82512a2008-10-24 08:42:28 +0000175
176private:
177 Loc getVarLoc(const VarDecl* VD) {
178 return loc::MemRegionVal(MRMgr.getVarRegion(VD));
179 }
180
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000181 const GRState* BindArray(const GRState* St, const TypedRegion* R, SVal V);
Zhongxing Xu6e3f01c2008-10-31 07:16:08 +0000182
Zhongxing Xu0b242ec2008-12-04 01:12:41 +0000183 /// Retrieve the values in a struct and return a CompoundVal, used when doing
184 /// struct copy:
185 /// struct s x, y;
186 /// x = y;
187 /// y's value is retrieved by this method.
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000188 SVal RetrieveStruct(const GRState* St, const TypedRegion* R);
Zhongxing Xu0b242ec2008-12-04 01:12:41 +0000189
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000190 const GRState* BindStruct(const GRState* St, const TypedRegion* R, SVal V);
Zhongxing Xu63123d82008-11-23 04:30:35 +0000191
Zhongxing Xu6e3f01c2008-10-31 07:16:08 +0000192 // Utility methods.
193 BasicValueFactory& getBasicVals() { return StateMgr.getBasicVals(); }
194 ASTContext& getContext() { return StateMgr.getContext(); }
Zhongxing Xu63123d82008-11-23 04:30:35 +0000195 SymbolManager& getSymbolManager() { return StateMgr.getSymbolManager(); }
Zhongxing Xudc0a25d2008-11-16 04:07:26 +0000196
197 const GRState* AddRegionView(const GRState* St,
198 const MemRegion* View, const MemRegion* Base);
Zhongxing Xu17892752008-10-08 02:50:44 +0000199};
200
201} // end anonymous namespace
202
Ted Kremenek95c7b002008-10-24 01:04:59 +0000203StoreManager* clang::CreateRegionStoreManager(GRStateManager& StMgr) {
Zhongxing Xu24194ef2008-10-24 01:38:55 +0000204 return new RegionStoreManager(StMgr);
Ted Kremenek95c7b002008-10-24 01:04:59 +0000205}
206
Zhongxing Xu143bf822008-10-25 14:18:57 +0000207SVal RegionStoreManager::getLValueString(const GRState* St,
208 const StringLiteral* S) {
209 return loc::MemRegionVal(MRMgr.getStringRegion(S));
210}
211
Zhongxing Xuc4bf72c2008-10-22 13:44:38 +0000212SVal RegionStoreManager::getLValueVar(const GRState* St, const VarDecl* VD) {
213 return loc::MemRegionVal(MRMgr.getVarRegion(VD));
214}
Zhongxing Xuf22679e2008-11-07 10:38:33 +0000215
216SVal RegionStoreManager::getLValueCompoundLiteral(const GRState* St,
217 const CompoundLiteralExpr* CL) {
218 return loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL));
219}
220
Zhongxing Xuc4bf72c2008-10-22 13:44:38 +0000221SVal RegionStoreManager::getLValueIvar(const GRState* St, const ObjCIvarDecl* D,
222 SVal Base) {
223 return UnknownVal();
224}
225
226SVal RegionStoreManager::getLValueField(const GRState* St, SVal Base,
227 const FieldDecl* D) {
228 if (Base.isUnknownOrUndef())
229 return Base;
230
231 Loc BaseL = cast<Loc>(Base);
232 const MemRegion* BaseR = 0;
233
234 switch (BaseL.getSubKind()) {
235 case loc::MemRegionKind:
236 BaseR = cast<loc::MemRegionVal>(BaseL).getRegion();
237 break;
238
239 case loc::SymbolValKind:
240 BaseR = MRMgr.getSymbolicRegion(cast<loc::SymbolVal>(&BaseL)->getSymbol());
241 break;
242
243 case loc::GotoLabelKind:
244 case loc::FuncValKind:
245 // These are anormal cases. Flag an undefined value.
246 return UndefinedVal();
247
248 case loc::ConcreteIntKind:
Zhongxing Xuc4bf72c2008-10-22 13:44:38 +0000249 // 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:
Zhongxing Xu13d1ee22008-11-07 08:57:30 +0000256 assert(0 && "Unhandled Base.");
Zhongxing Xuc4bf72c2008-10-22 13:44:38 +0000257 return Base;
258 }
259
260 return loc::MemRegionVal(MRMgr.getFieldRegion(D, BaseR));
261}
262
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000263SVal RegionStoreManager::getLValueElement(const GRState* St,
264 SVal Base, SVal Offset) {
265 if (Base.isUnknownOrUndef())
266 return Base;
267
Zhongxing Xu4a1513e2008-10-27 12:23:17 +0000268 if (isa<loc::SymbolVal>(Base))
269 return Base;
270
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000271 loc::MemRegionVal& BaseL = cast<loc::MemRegionVal>(Base);
272
Zhongxing Xue4d13932008-11-13 09:48:44 +0000273 // Pointer of any type can be cast and used as array base. We do not support
274 // that case yet.
275 if (!isa<ElementRegion>(BaseL.getRegion())) {
276 // Record what we have seen in real code.
277 assert(isa<FieldRegion>(BaseL.getRegion()));
278 return UnknownVal();
279 }
280
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000281 // We expect BaseR is an ElementRegion, not a base VarRegion.
282
283 const ElementRegion* ElemR = cast<ElementRegion>(BaseL.getRegion());
284
285 SVal Idx = ElemR->getIndex();
286
287 nonloc::ConcreteInt *CI1, *CI2;
288
289 // Only handle integer indices for now.
290 if ((CI1 = dyn_cast<nonloc::ConcreteInt>(&Idx)) &&
291 (CI2 = dyn_cast<nonloc::ConcreteInt>(&Offset))) {
Zhongxing Xucc0d0ec2008-11-13 09:15:14 +0000292
Sebastian Redle95db4f2008-11-24 19:35:33 +0000293 // Temporary SVal to hold a potential signed and extended APSInt.
Zhongxing Xucc0d0ec2008-11-13 09:15:14 +0000294 SVal SignedInt;
295
Sebastian Redle95db4f2008-11-24 19:35:33 +0000296 // Index might be unsigned. We have to convert it to signed. It might also
297 // be less wide than the size. We have to extend it.
298 if (CI2->getValue().isUnsigned() ||
299 CI2->getValue().getBitWidth() < CI1->getValue().getBitWidth()) {
Zhongxing Xucc0d0ec2008-11-13 09:15:14 +0000300 llvm::APSInt SI = CI2->getValue();
Sebastian Redlddee68b2008-11-24 19:39:40 +0000301 if (CI2->getValue().getBitWidth() < CI1->getValue().getBitWidth())
302 SI.extend(CI1->getValue().getBitWidth());
Zhongxing Xucc0d0ec2008-11-13 09:15:14 +0000303 SI.setIsSigned(true);
304 SignedInt = nonloc::ConcreteInt(getBasicVals().getValue(SI));
305 CI2 = cast<nonloc::ConcreteInt>(&SignedInt);
306 }
307
Zhongxing Xu63123d82008-11-23 04:30:35 +0000308 SVal NewIdx = CI1->EvalBinOp(getBasicVals(), BinaryOperator::Add, *CI2);
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000309 return loc::MemRegionVal(MRMgr.getElementRegion(NewIdx,
Ted Kremenekabb042f2008-12-13 19:24:37 +0000310 ElemR->getArrayRegion()));
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000311 }
312
313 return UnknownVal();
314}
315
Zhongxing Xue8a964b2008-11-22 13:21:46 +0000316SVal RegionStoreManager::getSizeInElements(const GRState* St,
317 const MemRegion* R) {
318 if (const VarRegion* VR = dyn_cast<VarRegion>(R)) {
319 // Get the type of the variable.
Ted Kremenek6eddeb12008-12-13 21:49:13 +0000320 QualType T = VR->getRValueType(getContext());
Zhongxing Xue8a964b2008-11-22 13:21:46 +0000321
322 // It must be of array type.
323 const ConstantArrayType* CAT = cast<ConstantArrayType>(T.getTypePtr());
324
325 // return the size as signed integer.
326 return NonLoc::MakeVal(getBasicVals(), CAT->getSize(), false);
327 }
328
329 if (const StringRegion* SR = dyn_cast<StringRegion>(R)) {
Zhongxing Xu6613d082008-11-24 02:18:56 +0000330 const StringLiteral* Str = SR->getStringLiteral();
Zhongxing Xud0fd3b72008-11-24 02:30:48 +0000331 // We intentionally made the size value signed because it participates in
332 // operations with signed indices.
Zhongxing Xu4b89e032008-11-24 05:16:01 +0000333 return NonLoc::MakeVal(getBasicVals(), Str->getByteLength() + 1, false);
Zhongxing Xue8a964b2008-11-22 13:21:46 +0000334 }
335
336 if (const AnonTypedRegion* ATR = dyn_cast<AnonTypedRegion>(R)) {
Zhongxing Xubaf03a72008-11-24 09:44:56 +0000337 GRStateRef state(St, StateMgr);
338
339 // Get the size of the super region in bytes.
340 RegionExtentsTy::data_type* T
341 = state.get<RegionExtentsTy>(ATR->getSuperRegion());
342
343 assert(T && "region extent not exist");
344
345 // Assume it's ConcreteInt for now.
346 llvm::APSInt SSize = cast<nonloc::ConcreteInt>(*T).getValue();
347
348 // Get the size of the element in bits.
Ted Kremenek6eddeb12008-12-13 21:49:13 +0000349 QualType LvT = ATR->getLValueType(getContext());
350 QualType ElemTy = cast<PointerType>(LvT.getTypePtr())->getPointeeType();
Zhongxing Xubaf03a72008-11-24 09:44:56 +0000351
352 uint64_t X = getContext().getTypeSize(ElemTy);
353
354 const llvm::APSInt& ESize = getBasicVals().getValue(X, SSize.getBitWidth(),
355 false);
356
357 // Calculate the number of elements.
358
359 // FIXME: What do we do with signed-ness problem? Shall we make all APSInts
360 // signed?
361 if (SSize.isUnsigned())
362 SSize.setIsSigned(true);
363
364 // FIXME: move this operation into BasicVals.
365 const llvm::APSInt S =
366 (SSize * getBasicVals().getValue(8, SSize.getBitWidth(), false)) / ESize;
367
368 return NonLoc::MakeVal(getBasicVals(), S);
Zhongxing Xue8a964b2008-11-22 13:21:46 +0000369 }
370
371 if (const FieldRegion* FR = dyn_cast<FieldRegion>(R)) {
372 // FIXME: Unsupported yet.
373 FR = 0;
374 return UnknownVal();
375 }
Zhongxing Xu369f4292008-11-22 13:23:00 +0000376
Zhongxing Xue8a964b2008-11-22 13:21:46 +0000377 assert(0 && "Other regions are not supported yet.");
378}
379
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000380// Cast 'pointer to array' to 'pointer to the first element of array'.
381
382SVal RegionStoreManager::ArrayToPointer(SVal Array) {
Ted Kremenekabb042f2008-12-13 19:24:37 +0000383 if (Array.isUnknownOrUndef())
384 return Array;
385
386 if (!isa<loc::MemRegionVal>(Array))
387 return UnknownVal();
388
389 const MemRegion* R = cast<loc::MemRegionVal>(&Array)->getRegion();
390 const TypedRegion* ArrayR = dyn_cast<TypedRegion>(R);
391
392 if (ArrayR)
393 return UnknownVal();
394
Zhongxing Xu63123d82008-11-23 04:30:35 +0000395 nonloc::ConcreteInt Idx(getBasicVals().getZeroWithPtrWidth(false));
Zhongxing Xu0b7e6422008-10-26 02:23:57 +0000396 ElementRegion* ER = MRMgr.getElementRegion(Idx, ArrayR);
397
398 return loc::MemRegionVal(ER);
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000399}
400
Ted Kremenek6eddeb12008-12-13 21:49:13 +0000401StoreManager::CastResult
402RegionStoreManager::CastRegion(const GRState* state, const MemRegion* R,
403 QualType CastToTy) {
404
405 // Return the same region if the region types are compatible.
406 if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) {
407 ASTContext& Ctx = StateMgr.getContext();
408 QualType Ta = Ctx.getCanonicalType(TR->getLValueType(Ctx));
409 QualType Tb = Ctx.getCanonicalType(CastToTy);
410
411 if (Ta == Tb)
412 return CastResult(state, R);
Zhongxing Xudc0a25d2008-11-16 04:07:26 +0000413 }
Ted Kremenek6eddeb12008-12-13 21:49:13 +0000414
415 const MemRegion* ViewR = MRMgr.getAnonTypedRegion(CastToTy, R);
416 return CastResult(AddRegionView(state, ViewR, R), ViewR);
Zhongxing Xudc0a25d2008-11-16 04:07:26 +0000417}
418
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000419SVal RegionStoreManager::Retrieve(const GRState* St, Loc L, QualType T) {
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000420 assert(!isa<UnknownVal>(L) && "location unknown");
421 assert(!isa<UndefinedVal>(L) && "location undefined");
422
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000423 if (isa<loc::SymbolVal>(L))
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000424 return UnknownVal();
425
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000426 if (isa<loc::ConcreteInt>(L))
427 return UndefinedVal();
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000428
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000429 if (isa<loc::FuncVal>(L))
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000430 return L;
431
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000432 const MemRegion* R = cast<loc::MemRegionVal>(L).getRegion();
433 assert(R && "bad region");
434
435 if (const TypedRegion* TR = dyn_cast<TypedRegion>(R))
436 if (TR->getRValueType(getContext())->isStructureType())
437 return RetrieveStruct(St, TR);
438
439 RegionBindingsTy B = GetRegionBindings(St->getStore());
440 RegionBindingsTy::data_type* V = B.lookup(R);
441
442 // Check if the region has a binding.
443 if (V)
444 return *V;
445
446 // Check if the region is in killset.
447 GRStateRef state(St, StateMgr);
448 if (state.contains<RegionKills>(R))
449 return UnknownVal();
450
451 // The location is not initialized.
452
453 // We treat parameters as symbolic values.
454 if (const VarRegion* VR = dyn_cast<VarRegion>(R))
455 if (isa<ParmVarDecl>(VR->getDecl()))
456 return SVal::MakeSymbolValue(getSymbolManager(), VR,
457 VR->getRValueType(getContext()));
458
459 if (MRMgr.onStack(R) || MRMgr.onHeap(R))
460 return UndefinedVal();
461 else
462 return SVal::MakeSymbolValue(getSymbolManager(), R,
463 cast<TypedRegion>(R)->getRValueType(getContext()));
464
465 // FIXME: consider default values for elements and fields.
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000466}
467
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000468SVal RegionStoreManager::RetrieveStruct(const GRState* St,const TypedRegion* R){
469
470 Store store = St->getStore();
471 GRStateRef state(St, StateMgr);
472
Ted Kremenek6eddeb12008-12-13 21:49:13 +0000473 // FIXME: Verify we want getRValueType instead of getLValueType.
474 QualType T = R->getRValueType(getContext());
Zhongxing Xu6e3f01c2008-10-31 07:16:08 +0000475 assert(T->isStructureType());
476
477 const RecordType* RT = cast<RecordType>(T.getTypePtr());
478 RecordDecl* RD = RT->getDecl();
479 assert(RD->isDefinition());
480
481 llvm::ImmutableList<SVal> StructVal = getBasicVals().getEmptySValList();
482
Douglas Gregore267ff32008-12-11 20:41:00 +0000483 std::vector<FieldDecl *> Fields(RD->field_begin(), RD->field_end());
Douglas Gregor44b43212008-12-11 16:49:14 +0000484
Douglas Gregore267ff32008-12-11 20:41:00 +0000485 for (std::vector<FieldDecl *>::reverse_iterator Field = Fields.rbegin(),
486 FieldEnd = Fields.rend();
487 Field != FieldEnd; ++Field) {
488 FieldRegion* FR = MRMgr.getFieldRegion(*Field, R);
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000489 RegionBindingsTy B = GetRegionBindings(store);
Zhongxing Xuf0dfa8d2008-10-31 08:10:01 +0000490 RegionBindingsTy::data_type* data = B.lookup(FR);
Zhongxing Xu6e3f01c2008-10-31 07:16:08 +0000491
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000492 SVal FieldValue;
493 if (data)
494 FieldValue = *data;
495 else if (state.contains<RegionKills>(FR))
496 FieldValue = UnknownVal();
497 else {
498 if (MRMgr.onStack(FR) || MRMgr.onHeap(FR))
499 FieldValue = UndefinedVal();
500 else
501 FieldValue = SVal::MakeSymbolValue(getSymbolManager(), FR,
502 FR->getRValueType(getContext()));
503 }
Zhongxing Xu6e3f01c2008-10-31 07:16:08 +0000504
505 StructVal = getBasicVals().consVals(FieldValue, StructVal);
506 }
507
508 return NonLoc::MakeCompoundVal(T, StructVal, getBasicVals());
509}
510
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000511const GRState* RegionStoreManager::Bind(const GRState* St, Loc L, SVal V) {
512 // Currently we don't bind value to symbolic location. But if the logic is
513 // made clear, we might change this decision.
514 if (isa<loc::SymbolVal>(L))
515 return St;
Zhongxing Xu8fe63af2008-10-27 09:24:07 +0000516
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000517 // If we get here, the location should be a region.
518 const MemRegion* R = cast<loc::MemRegionVal>(L).getRegion();
Zhongxing Xuf0dfa8d2008-10-31 08:10:01 +0000519 assert(R);
520
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000521 // Check if the region is a struct region.
Zhongxing Xuf0dfa8d2008-10-31 08:10:01 +0000522 if (const TypedRegion* TR = dyn_cast<TypedRegion>(R))
Ted Kremenek6eddeb12008-12-13 21:49:13 +0000523 // FIXME: Verify we want getRValueType().
524 if (TR->getRValueType(getContext())->isStructureType())
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000525 return BindStruct(St, TR, V);
Zhongxing Xu17892752008-10-08 02:50:44 +0000526
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000527 Store store = St->getStore();
Zhongxing Xu17892752008-10-08 02:50:44 +0000528 RegionBindingsTy B = GetRegionBindings(store);
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000529
530 if (V.isUnknown()) {
531 // Remove the binding.
532 store = RBFactory.Remove(B, R).getRoot();
533
534 // Add the region to the killset.
535 GRStateRef state(St, StateMgr);
536 St = state.add<RegionKills>(R);
537 }
538 else
539 store = RBFactory.Add(B, R, V).getRoot();
540
541 return StateMgr.MakeStateWithStore(St, store);
Zhongxing Xu17892752008-10-08 02:50:44 +0000542}
543
Zhongxing Xu9c9ca082008-12-16 02:36:30 +0000544Store RegionStoreManager::Remove(Store store, Loc L) {
545 RegionBindingsTy B = GetRegionBindings(store);
546
547 const MemRegion* R = cast<loc::MemRegionVal>(L).getRegion();
548 assert(R);
549
550 return RBFactory.Remove(B, R).getRoot();
551}
552
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000553const GRState* RegionStoreManager::BindDecl(const GRState* St,
554 const VarDecl* VD, SVal InitVal) {
555 // All static variables are treated as symbolic values.
556 if (VD->hasGlobalStorage())
557 return St;
Zhongxing Xuf0dfa8d2008-10-31 08:10:01 +0000558
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000559 // Process local variables.
Zhongxing Xua4f28ff2008-11-13 08:41:36 +0000560
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000561 QualType T = VD->getType();
562
563 VarRegion* VR = MRMgr.getVarRegion(VD);
564
565 if (Loc::IsLocType(T) || T->isIntegerType())
566 return Bind(St, Loc::MakeVal(VR), InitVal);
Zhongxing Xuf0dfa8d2008-10-31 08:10:01 +0000567
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000568 else if (T->isArrayType())
569 return BindArray(St, VR, InitVal);
Zhongxing Xuf0dfa8d2008-10-31 08:10:01 +0000570
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000571 else if (T->isStructureType())
572 return BindStruct(St, VR, InitVal);
Zhongxing Xud463d442008-11-02 12:13:30 +0000573
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000574 // Other types of variable are not supported yet.
Zhongxing Xu17892752008-10-08 02:50:44 +0000575 return St;
576}
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000577
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000578// FIXME: this method should be merged into Bind().
579const GRState*
580RegionStoreManager::BindCompoundLiteral(const GRState* St,
581 const CompoundLiteralExpr* CL, SVal V) {
Zhongxing Xuf22679e2008-11-07 10:38:33 +0000582 CompoundLiteralRegion* R = MRMgr.getCompoundLiteralRegion(CL);
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000583 return Bind(St, loc::MemRegionVal(R), V);
Zhongxing Xuf22679e2008-11-07 10:38:33 +0000584}
585
Zhongxing Xubaf03a72008-11-24 09:44:56 +0000586const GRState* RegionStoreManager::setExtent(const GRState* St,
587 const MemRegion* R, SVal Extent) {
588 GRStateRef state(St, StateMgr);
589 return state.set<RegionExtentsTy>(R, Extent);
590}
591
592
Ted Kremenekc48ea6e2008-12-04 02:08:27 +0000593void RegionStoreManager::UpdateLiveSymbols(SVal X, LiveSymbolsTy& LSymbols) {
594 for (SVal::symbol_iterator SI=X.symbol_begin(),SE=X.symbol_end();SI!=SE;++SI)
595 LSymbols.insert(*SI);
596}
597
Ted Kremenek2ed14be2008-12-05 00:47:52 +0000598Store RegionStoreManager::RemoveDeadBindings(const GRState* state, Stmt* Loc,
Zhongxing Xu8916d5b2008-11-10 09:39:04 +0000599 const LiveVariables& Live,
600 llvm::SmallVectorImpl<const MemRegion*>& RegionRoots,
601 LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols) {
602
Ted Kremenek2ed14be2008-12-05 00:47:52 +0000603 Store store = state->getStore();
Zhongxing Xu8916d5b2008-11-10 09:39:04 +0000604 RegionBindingsTy B = GetRegionBindings(store);
Ted Kremenekc48ea6e2008-12-04 02:08:27 +0000605
606 // Lazily constructed backmap from MemRegions to SubRegions.
607 typedef llvm::ImmutableSet<const MemRegion*> SubRegionsTy;
608 typedef llvm::ImmutableMap<const MemRegion*, SubRegionsTy> SubRegionsMapTy;
609
610 // FIXME: As a future optimization we can modifiy BumpPtrAllocator to have
611 // the ability to reuse memory. This way we can keep TmpAlloc around as
612 // an instance variable of RegionStoreManager (avoiding repeated malloc
613 // overhead).
614 llvm::BumpPtrAllocator TmpAlloc;
615
616 // Factory objects.
617 SubRegionsMapTy::Factory SubRegMapF(TmpAlloc);
618 SubRegionsTy::Factory SubRegF(TmpAlloc);
619
620 // The backmap from regions to subregions.
621 SubRegionsMapTy SubRegMap = SubRegMapF.GetEmptyMap();
622
623 // Do a pass over the regions in the store. For VarRegions we check if
624 // the variable is still live and if so add it to the list of live roots.
625 // For other regions we populate our region backmap.
Zhongxing Xu8916d5b2008-11-10 09:39:04 +0000626 for (RegionBindingsTy::iterator I = B.begin(), E = B.end(); I != E; ++I) {
Ted Kremenekc48ea6e2008-12-04 02:08:27 +0000627 const MemRegion* R = I.getKey();
628 if (const VarRegion* VR = dyn_cast<VarRegion>(R)) {
629 if (Live.isLive(Loc, VR->getDecl()))
630 RegionRoots.push_back(VR); // This is a live "root".
631 }
632 else {
633 // Get the super region for R.
634 const MemRegion* SuperR = cast<SubRegion>(R)->getSuperRegion();
635 // Get the current set of subregions for SuperR.
636 const SubRegionsTy* SRptr = SubRegMap.lookup(SuperR);
637 SubRegionsTy SR = SRptr ? *SRptr : SubRegF.GetEmptySet();
638 // Add R to the subregions of SuperR.
639 SubRegMap = SubRegMapF.Add(SubRegMap, SuperR, SubRegF.Add(SR, R));
640
641 // Finally, check if SuperR is a VarRegion. We need to do this
642 // to also mark SuperR as a root (as it may not have a value directly
643 // bound to it in the store).
644 if (const VarRegion* VR = dyn_cast<VarRegion>(SuperR)) {
645 if (Live.isLive(Loc, VR->getDecl()))
646 RegionRoots.push_back(VR); // This is a live "root".
647 }
648 }
Zhongxing Xu8916d5b2008-11-10 09:39:04 +0000649 }
Ted Kremenekc48ea6e2008-12-04 02:08:27 +0000650
651 // Process the worklist of RegionRoots. This performs a "mark-and-sweep"
652 // of the store. We want to find all live symbols and dead regions.
653 llvm::SmallPtrSet<const MemRegion*, 10> Marked;
654
655 while (!RegionRoots.empty()) {
656 // Dequeue the next region on the worklist.
657 const MemRegion* R = RegionRoots.back();
658 RegionRoots.pop_back();
Zhongxing Xu8916d5b2008-11-10 09:39:04 +0000659
Ted Kremenekc48ea6e2008-12-04 02:08:27 +0000660 // Check if we have already processed this region.
661 if (Marked.count(R)) continue;
662
663 // Mark this region as processed. This is needed for termination in case
664 // a region is referenced more than once.
665 Marked.insert(R);
666
667 // Mark the symbol for any live SymbolicRegion as "live". This means we
668 // should continue to track that symbol.
669 if (const SymbolicRegion* SymR = dyn_cast<SymbolicRegion>(R))
670 LSymbols.insert(SymR->getSymbol());
671
672 // Get the data binding for R (if any).
673 RegionBindingsTy::data_type* Xptr = B.lookup(R);
674 if (Xptr) {
675 SVal X = *Xptr;
676 UpdateLiveSymbols(X, LSymbols); // Update the set of live symbols.
677
678 // If X is a region, then add it the RegionRoots.
679 if (loc::MemRegionVal* RegionX = dyn_cast<loc::MemRegionVal>(&X))
680 RegionRoots.push_back(RegionX->getRegion());
681 }
682
683 // Get the subregions of R. These are RegionRoots as well since they
684 // represent values that are also bound to R.
685 const SubRegionsTy* SRptr = SubRegMap.lookup(R);
686 if (!SRptr) continue;
687 SubRegionsTy SR = *SRptr;
688
689 for (SubRegionsTy::iterator I=SR.begin(), E=SR.end(); I!=E; ++I)
690 RegionRoots.push_back(*I);
691 }
692
693 // We have now scanned the store, marking reachable regions and symbols
694 // as live. We now remove all the regions that are dead from the store
695 // as well as update DSymbols with the set symbols that are now dead.
696
697 for (RegionBindingsTy::iterator I = B.begin(), E = B.end(); I != E; ++I) {
698 const MemRegion* R = I.getKey();
699
700 // If this region live? Is so, none of its symbols are dead.
701 if (Marked.count(R))
702 continue;
703
704 // Remove this dead region from the store.
Zhongxing Xu9c9ca082008-12-16 02:36:30 +0000705 store = Remove(store, Loc::MakeVal(R));
Ted Kremenekc48ea6e2008-12-04 02:08:27 +0000706
707 // Mark all non-live symbols that this region references as dead.
708 if (const SymbolicRegion* SymR = dyn_cast<SymbolicRegion>(R)) {
Ted Kremenek2dabd432008-12-05 02:27:51 +0000709 SymbolRef Sym = SymR->getSymbol();
Ted Kremenekc48ea6e2008-12-04 02:08:27 +0000710 if (!LSymbols.count(Sym)) DSymbols.insert(Sym);
711 }
712
713 SVal X = I.getData();
714 SVal::symbol_iterator SI = X.symbol_begin(), SE = X.symbol_end();
715 for (; SI != SE; ++SI) { if (!LSymbols.count(*SI)) DSymbols.insert(*SI); }
716 }
717
Zhongxing Xu8916d5b2008-11-10 09:39:04 +0000718 return store;
719}
720
Zhongxing Xua071eb02008-10-24 06:01:33 +0000721void RegionStoreManager::print(Store store, std::ostream& Out,
722 const char* nl, const char *sep) {
723 llvm::raw_os_ostream OS(Out);
724 RegionBindingsTy B = GetRegionBindings(store);
725 OS << "Store:" << nl;
726
727 for (RegionBindingsTy::iterator I = B.begin(), E = B.end(); I != E; ++I) {
728 OS << ' '; I.getKey()->print(OS); OS << " : ";
729 I.getData().print(OS); OS << nl;
730 }
Zhongxing Xu5b8b6f22008-10-24 04:33:15 +0000731}
Zhongxing Xua82512a2008-10-24 08:42:28 +0000732
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000733const GRState* RegionStoreManager::BindArray(const GRState* St,
734 const TypedRegion* R, SVal Init) {
Ted Kremenek6eddeb12008-12-13 21:49:13 +0000735
736 // FIXME: Verify we should use getLValueType or getRValueType.
Zhongxing Xu2ef93722008-12-14 03:14:52 +0000737 QualType T = R->getRValueType(getContext());
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000738 assert(T->isArrayType());
739
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000740 // When we are binding the whole array, it always has default value 0.
741 GRStateRef state(St, StateMgr);
742 // St = state.set<RegionDefaultValue>(R, NonLoc::MakeVal(getBasicVals(), 0,
743 // false));
744
745 Store store = St->getStore();
746
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000747 ConstantArrayType* CAT = cast<ConstantArrayType>(T.getTypePtr());
748
Zhongxing Xu6987c7b2008-11-30 05:49:49 +0000749 llvm::APSInt Size(CAT->getSize(), false);
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000750 llvm::APSInt i = getBasicVals().getZeroWithPtrWidth(false);
Zhongxing Xu6987c7b2008-11-30 05:49:49 +0000751
752 // Check if the init expr is a StringLiteral.
753 if (isa<loc::MemRegionVal>(Init)) {
754 const MemRegion* InitR = cast<loc::MemRegionVal>(Init).getRegion();
755 const StringLiteral* S = cast<StringRegion>(InitR)->getStringLiteral();
756 const char* str = S->getStrData();
757 unsigned len = S->getByteLength();
758 unsigned j = 0;
759
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000760 // Copy bytes from the string literal into the target array. Trailing bytes
761 // in the array that are not covered by the string literal are initialized
762 // to zero.
Zhongxing Xu6987c7b2008-11-30 05:49:49 +0000763 for (; i < Size; ++i, ++j) {
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000764 if (j >= len)
765 break;
766
Zhongxing Xu6987c7b2008-11-30 05:49:49 +0000767 SVal Idx = NonLoc::MakeVal(getBasicVals(), i);
768 ElementRegion* ER = MRMgr.getElementRegion(Idx, R);
769
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000770 SVal V = NonLoc::MakeVal(getBasicVals(), str[j], sizeof(char)*8, true);
771 St = Bind(St, loc::MemRegionVal(ER), V);
Zhongxing Xu6987c7b2008-11-30 05:49:49 +0000772 }
773
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000774 return StateMgr.MakeStateWithStore(St, store);
Zhongxing Xu6987c7b2008-11-30 05:49:49 +0000775 }
776
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000777
778 nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(Init);
779
780 nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end();
781
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000782 for (; i < Size; ++i, ++VI) {
783 // The init list might be shorter than the array decl.
784 if (VI == VE)
785 break;
786
Zhongxing Xu6987c7b2008-11-30 05:49:49 +0000787 SVal Idx = NonLoc::MakeVal(getBasicVals(), i);
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000788 ElementRegion* ER = MRMgr.getElementRegion(Idx, R);
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000789
790 if (CAT->getElementType()->isStructureType())
791 St = BindStruct(St, ER, *VI);
792 else
793 St = Bind(St, Loc::MakeVal(ER), *VI);
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000794 }
795
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000796 return StateMgr.MakeStateWithStore(St, store);
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000797}
798
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000799const GRState*
800RegionStoreManager::BindStruct(const GRState* St, const TypedRegion* R, SVal V){
Ted Kremenek6eddeb12008-12-13 21:49:13 +0000801 // FIXME: Verify that we should use getRValueType or getLValueType.
802 QualType T = R->getRValueType(getContext());
Zhongxing Xuaf0a8442008-10-31 10:53:01 +0000803 assert(T->isStructureType());
804
805 RecordType* RT = cast<RecordType>(T.getTypePtr());
806 RecordDecl* RD = RT->getDecl();
807 assert(RD->isDefinition());
808
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000809 nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(V);
Zhongxing Xuaf0a8442008-10-31 10:53:01 +0000810 nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end();
811 RecordDecl::field_iterator FI = RD->field_begin(), FE = RD->field_end();
812
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000813 for (; FI != FE; ++FI, ++VI) {
814
815 // There may be fewer values than fields only when we are initializing a
816 // struct decl. In this case, mark the region as having default value.
817 if (VI == VE) {
818 // GRStateRef state(St, StateMgr);
819 //St = state.set<RegionDefaultValue>(R, NonLoc::MakeVal(getBasicVals(), 0,
820 // false));
821 break;
822 }
823
Zhongxing Xuaf0a8442008-10-31 10:53:01 +0000824 QualType FTy = (*FI)->getType();
825 FieldRegion* FR = MRMgr.getFieldRegion(*FI, R);
826
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000827 if (Loc::IsLocType(FTy) || FTy->isIntegerType())
828 St = Bind(St, Loc::MakeVal(FR), *VI);
Zhongxing Xua82512a2008-10-24 08:42:28 +0000829
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000830 else if (FTy->isArrayType())
831 St = BindArray(St, FR, *VI);
Zhongxing Xua82512a2008-10-24 08:42:28 +0000832
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000833 else if (FTy->isStructureType())
834 St = BindStruct(St, FR, *VI);
Zhongxing Xua82512a2008-10-24 08:42:28 +0000835 }
836
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000837 return St;
Zhongxing Xuc3a05992008-11-19 11:06:24 +0000838}
839
Zhongxing Xudc0a25d2008-11-16 04:07:26 +0000840const GRState* RegionStoreManager::AddRegionView(const GRState* St,
841 const MemRegion* View,
842 const MemRegion* Base) {
843 GRStateRef state(St, StateMgr);
844
845 // First, retrieve the region view of the base region.
846 RegionViewMapTy::data_type* d = state.get<RegionViewMapTy>(Base);
847 RegionViewTy L = d ? *d : RVFactory.GetEmptyList();
848
849 // Now add View to the region view.
850 L = RVFactory.Add(View, L);
851
852 // Create a new state with the new region view.
853 return state.set<RegionViewMapTy>(Base, L);
854}