blob: 006b613528f7c8e80b7d7d2c38e7ce08e68f4dbf [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
Zhongxing Xu17892752008-10-08 02:50:44 +000055namespace {
56
57class VISIBILITY_HIDDEN RegionStoreManager : public StoreManager {
58 RegionBindingsTy::Factory RBFactory;
Zhongxing Xudc0a25d2008-11-16 04:07:26 +000059 RegionViewTy::Factory RVFactory;
Zhongxing Xudc0a25d2008-11-16 04:07:26 +000060
Zhongxing Xu17892752008-10-08 02:50:44 +000061 GRStateManager& StateMgr;
62 MemRegionManager MRMgr;
63
64public:
65 RegionStoreManager(GRStateManager& mgr)
Zhongxing Xudc0a25d2008-11-16 04:07:26 +000066 : RBFactory(mgr.getAllocator()),
67 RVFactory(mgr.getAllocator()),
Zhongxing Xudc0a25d2008-11-16 04:07:26 +000068 StateMgr(mgr),
69 MRMgr(StateMgr.getAllocator()) {}
Zhongxing Xu17892752008-10-08 02:50:44 +000070
71 virtual ~RegionStoreManager() {}
72
Zhongxing Xu24194ef2008-10-24 01:38:55 +000073 MemRegionManager& getRegionManager() { return MRMgr; }
74
75 // FIXME: Is this function necessary?
76 SVal GetRegionSVal(Store St, const MemRegion* R) {
77 return Retrieve(St, loc::MemRegionVal(R));
78 }
Ted Kremenek4f090272008-10-27 21:54:31 +000079
Zhongxing Xuf22679e2008-11-07 10:38:33 +000080 Store BindCompoundLiteral(Store store, const CompoundLiteralExpr* CL, SVal V);
Zhongxing Xu24194ef2008-10-24 01:38:55 +000081
Zhongxing Xu143bf822008-10-25 14:18:57 +000082 SVal getLValueString(const GRState* St, const StringLiteral* S);
83
Zhongxing Xuf22679e2008-11-07 10:38:33 +000084 SVal getLValueCompoundLiteral(const GRState* St, const CompoundLiteralExpr*);
85
Zhongxing Xuc4bf72c2008-10-22 13:44:38 +000086 SVal getLValueVar(const GRState* St, const VarDecl* VD);
87
88 SVal getLValueIvar(const GRState* St, const ObjCIvarDecl* D, SVal Base);
89
90 SVal getLValueField(const GRState* St, SVal Base, const FieldDecl* D);
91
Zhongxing Xub1d542a2008-10-24 01:09:32 +000092 SVal getLValueElement(const GRState* St, SVal Base, SVal Offset);
93
Zhongxing Xue8a964b2008-11-22 13:21:46 +000094 SVal getSizeInElements(const GRState* St, const MemRegion* R);
95
Zhongxing Xub1d542a2008-10-24 01:09:32 +000096 SVal ArrayToPointer(SVal Array);
97
Zhongxing Xucb529b52008-11-16 07:06:26 +000098 std::pair<const GRState*, SVal>
99 CastRegion(const GRState* St, SVal VoidPtr, QualType CastToTy, Stmt* CastE);
Zhongxing Xudc0a25d2008-11-16 04:07:26 +0000100
Zhongxing Xu24194ef2008-10-24 01:38:55 +0000101 SVal Retrieve(Store S, Loc L, QualType T = QualType());
Zhongxing Xuc4bf72c2008-10-22 13:44:38 +0000102
Zhongxing Xu8485ec62008-10-21 06:27:32 +0000103 Store Bind(Store St, Loc LV, SVal V);
Zhongxing Xu17892752008-10-08 02:50:44 +0000104
Zhongxing Xu24194ef2008-10-24 01:38:55 +0000105 Store Remove(Store store, Loc LV) {
106 // FIXME: Implement.
107 return store;
108 }
109
Zhongxing Xu17892752008-10-08 02:50:44 +0000110 Store getInitialStore();
Ted Kremenek9deb0e32008-10-24 20:32:16 +0000111
112 /// getSelfRegion - Returns the region for the 'self' (Objective-C) or
113 /// 'this' object (C++). When used when analyzing a normal function this
114 /// method returns NULL.
115 const MemRegion* getSelfRegion(Store) {
116 assert (false && "Not implemented.");
117 return 0;
118 }
Zhongxing Xu17892752008-10-08 02:50:44 +0000119
Zhongxing Xu24194ef2008-10-24 01:38:55 +0000120 Store RemoveDeadBindings(Store store, Stmt* Loc, const LiveVariables& Live,
121 llvm::SmallVectorImpl<const MemRegion*>& RegionRoots,
Zhongxing Xu8916d5b2008-11-10 09:39:04 +0000122 LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols);
Zhongxing Xu24194ef2008-10-24 01:38:55 +0000123
Ted Kremenek42577d12008-11-12 19:18:35 +0000124 Store BindDecl(Store store, const VarDecl* VD, SVal* InitVal, unsigned Count);
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000125
Zhongxing Xubaf03a72008-11-24 09:44:56 +0000126 const GRState* setExtent(const GRState* St, const MemRegion* R, SVal Extent);
127
Zhongxing Xu17892752008-10-08 02:50:44 +0000128 static inline RegionBindingsTy GetRegionBindings(Store store) {
129 return RegionBindingsTy(static_cast<const RegionBindingsTy::TreeTy*>(store));
130 }
Zhongxing Xu24194ef2008-10-24 01:38:55 +0000131
Zhongxing Xu5b8b6f22008-10-24 04:33:15 +0000132 void print(Store store, std::ostream& Out, const char* nl, const char *sep);
Zhongxing Xu24194ef2008-10-24 01:38:55 +0000133
134 void iterBindings(Store store, BindingsHandler& f) {
135 // FIXME: Implement.
136 }
Zhongxing Xua82512a2008-10-24 08:42:28 +0000137
138private:
139 Loc getVarLoc(const VarDecl* VD) {
140 return loc::MemRegionVal(MRMgr.getVarRegion(VD));
141 }
142
Zhongxing Xud463d442008-11-02 12:13:30 +0000143 Store InitializeArray(Store store, const TypedRegion* R, SVal Init);
144 Store BindArrayToVal(Store store, const TypedRegion* BaseR, SVal V);
Zhongxing Xuc3a05992008-11-19 11:06:24 +0000145 Store BindArrayToSymVal(Store store, const TypedRegion* BaseR);
146
Zhongxing Xud463d442008-11-02 12:13:30 +0000147 Store InitializeStruct(Store store, const TypedRegion* R, SVal Init);
148 Store BindStructToVal(Store store, const TypedRegion* BaseR, SVal V);
Zhongxing Xuc3a05992008-11-19 11:06:24 +0000149 Store BindStructToSymVal(Store store, const TypedRegion* BaseR);
Zhongxing Xu6e3f01c2008-10-31 07:16:08 +0000150
Zhongxing Xu0b242ec2008-12-04 01:12:41 +0000151 /// Retrieve the values in a struct and return a CompoundVal, used when doing
152 /// struct copy:
153 /// struct s x, y;
154 /// x = y;
155 /// y's value is retrieved by this method.
Zhongxing Xu6e3f01c2008-10-31 07:16:08 +0000156 SVal RetrieveStruct(Store store, const TypedRegion* R);
Zhongxing Xu0b242ec2008-12-04 01:12:41 +0000157
Zhongxing Xuf0dfa8d2008-10-31 08:10:01 +0000158 Store BindStruct(Store store, const TypedRegion* R, SVal V);
Zhongxing Xu63123d82008-11-23 04:30:35 +0000159
Zhongxing Xu6e3f01c2008-10-31 07:16:08 +0000160 // Utility methods.
161 BasicValueFactory& getBasicVals() { return StateMgr.getBasicVals(); }
162 ASTContext& getContext() { return StateMgr.getContext(); }
Zhongxing Xu63123d82008-11-23 04:30:35 +0000163 SymbolManager& getSymbolManager() { return StateMgr.getSymbolManager(); }
Zhongxing Xudc0a25d2008-11-16 04:07:26 +0000164
165 const GRState* AddRegionView(const GRState* St,
166 const MemRegion* View, const MemRegion* Base);
Zhongxing Xu17892752008-10-08 02:50:44 +0000167};
168
169} // end anonymous namespace
170
Ted Kremenek95c7b002008-10-24 01:04:59 +0000171StoreManager* clang::CreateRegionStoreManager(GRStateManager& StMgr) {
Zhongxing Xu24194ef2008-10-24 01:38:55 +0000172 return new RegionStoreManager(StMgr);
Ted Kremenek95c7b002008-10-24 01:04:59 +0000173}
174
Zhongxing Xu143bf822008-10-25 14:18:57 +0000175SVal RegionStoreManager::getLValueString(const GRState* St,
176 const StringLiteral* S) {
177 return loc::MemRegionVal(MRMgr.getStringRegion(S));
178}
179
Zhongxing Xuc4bf72c2008-10-22 13:44:38 +0000180SVal RegionStoreManager::getLValueVar(const GRState* St, const VarDecl* VD) {
181 return loc::MemRegionVal(MRMgr.getVarRegion(VD));
182}
Zhongxing Xuf22679e2008-11-07 10:38:33 +0000183
184SVal RegionStoreManager::getLValueCompoundLiteral(const GRState* St,
185 const CompoundLiteralExpr* CL) {
186 return loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL));
187}
188
Zhongxing Xuc4bf72c2008-10-22 13:44:38 +0000189SVal RegionStoreManager::getLValueIvar(const GRState* St, const ObjCIvarDecl* D,
190 SVal Base) {
191 return UnknownVal();
192}
193
194SVal RegionStoreManager::getLValueField(const GRState* St, SVal Base,
195 const FieldDecl* D) {
196 if (Base.isUnknownOrUndef())
197 return Base;
198
199 Loc BaseL = cast<Loc>(Base);
200 const MemRegion* BaseR = 0;
201
202 switch (BaseL.getSubKind()) {
203 case loc::MemRegionKind:
204 BaseR = cast<loc::MemRegionVal>(BaseL).getRegion();
205 break;
206
207 case loc::SymbolValKind:
208 BaseR = MRMgr.getSymbolicRegion(cast<loc::SymbolVal>(&BaseL)->getSymbol());
209 break;
210
211 case loc::GotoLabelKind:
212 case loc::FuncValKind:
213 // These are anormal cases. Flag an undefined value.
214 return UndefinedVal();
215
216 case loc::ConcreteIntKind:
Zhongxing Xuc4bf72c2008-10-22 13:44:38 +0000217 // While these seem funny, this can happen through casts.
218 // FIXME: What we should return is the field offset. For example,
219 // add the field offset to the integer value. That way funny things
220 // like this work properly: &(((struct foo *) 0xa)->f)
221 return Base;
222
223 default:
Zhongxing Xu13d1ee22008-11-07 08:57:30 +0000224 assert(0 && "Unhandled Base.");
Zhongxing Xuc4bf72c2008-10-22 13:44:38 +0000225 return Base;
226 }
227
228 return loc::MemRegionVal(MRMgr.getFieldRegion(D, BaseR));
229}
230
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000231SVal RegionStoreManager::getLValueElement(const GRState* St,
232 SVal Base, SVal Offset) {
233 if (Base.isUnknownOrUndef())
234 return Base;
235
Zhongxing Xu4a1513e2008-10-27 12:23:17 +0000236 if (isa<loc::SymbolVal>(Base))
237 return Base;
238
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000239 loc::MemRegionVal& BaseL = cast<loc::MemRegionVal>(Base);
240
Zhongxing Xue4d13932008-11-13 09:48:44 +0000241 // Pointer of any type can be cast and used as array base. We do not support
242 // that case yet.
243 if (!isa<ElementRegion>(BaseL.getRegion())) {
244 // Record what we have seen in real code.
245 assert(isa<FieldRegion>(BaseL.getRegion()));
246 return UnknownVal();
247 }
248
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000249 // We expect BaseR is an ElementRegion, not a base VarRegion.
250
251 const ElementRegion* ElemR = cast<ElementRegion>(BaseL.getRegion());
252
253 SVal Idx = ElemR->getIndex();
254
255 nonloc::ConcreteInt *CI1, *CI2;
256
257 // Only handle integer indices for now.
258 if ((CI1 = dyn_cast<nonloc::ConcreteInt>(&Idx)) &&
259 (CI2 = dyn_cast<nonloc::ConcreteInt>(&Offset))) {
Zhongxing Xucc0d0ec2008-11-13 09:15:14 +0000260
Sebastian Redle95db4f2008-11-24 19:35:33 +0000261 // Temporary SVal to hold a potential signed and extended APSInt.
Zhongxing Xucc0d0ec2008-11-13 09:15:14 +0000262 SVal SignedInt;
263
Sebastian Redle95db4f2008-11-24 19:35:33 +0000264 // Index might be unsigned. We have to convert it to signed. It might also
265 // be less wide than the size. We have to extend it.
266 if (CI2->getValue().isUnsigned() ||
267 CI2->getValue().getBitWidth() < CI1->getValue().getBitWidth()) {
Zhongxing Xucc0d0ec2008-11-13 09:15:14 +0000268 llvm::APSInt SI = CI2->getValue();
Sebastian Redlddee68b2008-11-24 19:39:40 +0000269 if (CI2->getValue().getBitWidth() < CI1->getValue().getBitWidth())
270 SI.extend(CI1->getValue().getBitWidth());
Zhongxing Xucc0d0ec2008-11-13 09:15:14 +0000271 SI.setIsSigned(true);
272 SignedInt = nonloc::ConcreteInt(getBasicVals().getValue(SI));
273 CI2 = cast<nonloc::ConcreteInt>(&SignedInt);
274 }
275
Zhongxing Xu63123d82008-11-23 04:30:35 +0000276 SVal NewIdx = CI1->EvalBinOp(getBasicVals(), BinaryOperator::Add, *CI2);
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000277 return loc::MemRegionVal(MRMgr.getElementRegion(NewIdx,
278 ElemR->getSuperRegion()));
279 }
280
281 return UnknownVal();
282}
283
Zhongxing Xue8a964b2008-11-22 13:21:46 +0000284SVal RegionStoreManager::getSizeInElements(const GRState* St,
285 const MemRegion* R) {
286 if (const VarRegion* VR = dyn_cast<VarRegion>(R)) {
287 // Get the type of the variable.
288 QualType T = VR->getType(getContext());
289
290 // It must be of array type.
291 const ConstantArrayType* CAT = cast<ConstantArrayType>(T.getTypePtr());
292
293 // return the size as signed integer.
294 return NonLoc::MakeVal(getBasicVals(), CAT->getSize(), false);
295 }
296
297 if (const StringRegion* SR = dyn_cast<StringRegion>(R)) {
Zhongxing Xu6613d082008-11-24 02:18:56 +0000298 const StringLiteral* Str = SR->getStringLiteral();
Zhongxing Xud0fd3b72008-11-24 02:30:48 +0000299 // We intentionally made the size value signed because it participates in
300 // operations with signed indices.
Zhongxing Xu4b89e032008-11-24 05:16:01 +0000301 return NonLoc::MakeVal(getBasicVals(), Str->getByteLength() + 1, false);
Zhongxing Xue8a964b2008-11-22 13:21:46 +0000302 }
303
304 if (const AnonTypedRegion* ATR = dyn_cast<AnonTypedRegion>(R)) {
Zhongxing Xubaf03a72008-11-24 09:44:56 +0000305 GRStateRef state(St, StateMgr);
306
307 // Get the size of the super region in bytes.
308 RegionExtentsTy::data_type* T
309 = state.get<RegionExtentsTy>(ATR->getSuperRegion());
310
311 assert(T && "region extent not exist");
312
313 // Assume it's ConcreteInt for now.
314 llvm::APSInt SSize = cast<nonloc::ConcreteInt>(*T).getValue();
315
316 // Get the size of the element in bits.
317 QualType ElemTy = cast<PointerType>(ATR->getType(getContext()).getTypePtr())
318 ->getPointeeType();
319
320 uint64_t X = getContext().getTypeSize(ElemTy);
321
322 const llvm::APSInt& ESize = getBasicVals().getValue(X, SSize.getBitWidth(),
323 false);
324
325 // Calculate the number of elements.
326
327 // FIXME: What do we do with signed-ness problem? Shall we make all APSInts
328 // signed?
329 if (SSize.isUnsigned())
330 SSize.setIsSigned(true);
331
332 // FIXME: move this operation into BasicVals.
333 const llvm::APSInt S =
334 (SSize * getBasicVals().getValue(8, SSize.getBitWidth(), false)) / ESize;
335
336 return NonLoc::MakeVal(getBasicVals(), S);
Zhongxing Xue8a964b2008-11-22 13:21:46 +0000337 }
338
339 if (const FieldRegion* FR = dyn_cast<FieldRegion>(R)) {
340 // FIXME: Unsupported yet.
341 FR = 0;
342 return UnknownVal();
343 }
Zhongxing Xu369f4292008-11-22 13:23:00 +0000344
Zhongxing Xue8a964b2008-11-22 13:21:46 +0000345 assert(0 && "Other regions are not supported yet.");
346}
347
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000348// Cast 'pointer to array' to 'pointer to the first element of array'.
349
350SVal RegionStoreManager::ArrayToPointer(SVal Array) {
351 const MemRegion* ArrayR = cast<loc::MemRegionVal>(&Array)->getRegion();
Zhongxing Xu143bf822008-10-25 14:18:57 +0000352
Zhongxing Xu63123d82008-11-23 04:30:35 +0000353 nonloc::ConcreteInt Idx(getBasicVals().getZeroWithPtrWidth(false));
Zhongxing Xu0b7e6422008-10-26 02:23:57 +0000354 ElementRegion* ER = MRMgr.getElementRegion(Idx, ArrayR);
355
356 return loc::MemRegionVal(ER);
Zhongxing Xub1d542a2008-10-24 01:09:32 +0000357}
358
Zhongxing Xucb529b52008-11-16 07:06:26 +0000359std::pair<const GRState*, SVal>
360RegionStoreManager::CastRegion(const GRState* St, SVal VoidPtr,
361 QualType CastToTy, Stmt* CastE) {
Zhongxing Xudc0a25d2008-11-16 04:07:26 +0000362 if (const AllocaRegion* AR =
363 dyn_cast<AllocaRegion>(cast<loc::MemRegionVal>(VoidPtr).getRegion())) {
364
365 // Create a new region to attach type information to it.
366 const AnonTypedRegion* TR = MRMgr.getAnonTypedRegion(CastToTy, AR);
367
368 // Get the pointer to the first element.
369 nonloc::ConcreteInt Idx(getBasicVals().getZeroWithPtrWidth(false));
370 const ElementRegion* ER = MRMgr.getElementRegion(Idx, TR);
371
Zhongxing Xudc0a25d2008-11-16 04:07:26 +0000372 // Add a RegionView to base region.
Zhongxing Xu353cbe12008-11-28 03:55:52 +0000373 return std::make_pair(AddRegionView(St, TR, AR), loc::MemRegionVal(ER));
Zhongxing Xudc0a25d2008-11-16 04:07:26 +0000374 }
375
376 // Default case.
Zhongxing Xu353cbe12008-11-28 03:55:52 +0000377 return std::make_pair(St, UnknownVal());
Zhongxing Xudc0a25d2008-11-16 04:07:26 +0000378}
379
Zhongxing Xu8485ec62008-10-21 06:27:32 +0000380SVal RegionStoreManager::Retrieve(Store S, Loc L, QualType T) {
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000381 assert(!isa<UnknownVal>(L) && "location unknown");
382 assert(!isa<UndefinedVal>(L) && "location undefined");
383
384 switch (L.getSubKind()) {
385 case loc::MemRegionKind: {
386 const MemRegion* R = cast<loc::MemRegionVal>(L).getRegion();
387 assert(R && "bad region");
388
Zhongxing Xu6e3f01c2008-10-31 07:16:08 +0000389 if (const TypedRegion* TR = dyn_cast<TypedRegion>(R))
390 if (TR->getType(getContext())->isStructureType())
391 return RetrieveStruct(S, TR);
392
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000393 RegionBindingsTy B(static_cast<const RegionBindingsTy::TreeTy*>(S));
394 RegionBindingsTy::data_type* V = B.lookup(R);
395 return V ? *V : UnknownVal();
396 }
397
398 case loc::SymbolValKind:
399 return UnknownVal();
400
401 case loc::ConcreteIntKind:
402 return UndefinedVal(); // As in BasicStoreManager.
403
404 case loc::FuncValKind:
405 return L;
406
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000407 default:
408 assert(false && "Invalid Location");
Ted Kremenekab7b32b2008-11-19 00:27:37 +0000409 return L;
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000410 }
411}
412
Zhongxing Xu6e3f01c2008-10-31 07:16:08 +0000413SVal RegionStoreManager::RetrieveStruct(Store store, const TypedRegion* R) {
414 QualType T = R->getType(getContext());
415 assert(T->isStructureType());
416
417 const RecordType* RT = cast<RecordType>(T.getTypePtr());
418 RecordDecl* RD = RT->getDecl();
419 assert(RD->isDefinition());
420
421 llvm::ImmutableList<SVal> StructVal = getBasicVals().getEmptySValList();
422
423 for (int i = RD->getNumMembers() - 1; i >= 0; --i) {
424 FieldRegion* FR = MRMgr.getFieldRegion(RD->getMember(i), R);
425 RegionBindingsTy B(static_cast<const RegionBindingsTy::TreeTy*>(store));
Zhongxing Xuf0dfa8d2008-10-31 08:10:01 +0000426 RegionBindingsTy::data_type* data = B.lookup(FR);
Zhongxing Xu6e3f01c2008-10-31 07:16:08 +0000427
428 SVal FieldValue = data ? *data : UnknownVal();
429
430 StructVal = getBasicVals().consVals(FieldValue, StructVal);
431 }
432
433 return NonLoc::MakeCompoundVal(T, StructVal, getBasicVals());
434}
435
Zhongxing Xu8485ec62008-10-21 06:27:32 +0000436Store RegionStoreManager::Bind(Store store, Loc LV, SVal V) {
Zhongxing Xu8fe63af2008-10-27 09:24:07 +0000437 if (LV.getSubKind() == loc::SymbolValKind)
438 return store;
439
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000440 assert(LV.getSubKind() == loc::MemRegionKind);
Zhongxing Xu17892752008-10-08 02:50:44 +0000441
Ted Kremenek993f1c72008-10-17 20:28:54 +0000442 const MemRegion* R = cast<loc::MemRegionVal>(LV).getRegion();
Zhongxing Xu17892752008-10-08 02:50:44 +0000443
Zhongxing Xuf0dfa8d2008-10-31 08:10:01 +0000444 assert(R);
445
446 if (const TypedRegion* TR = dyn_cast<TypedRegion>(R))
447 if (TR->getType(getContext())->isStructureType())
448 return BindStruct(store, TR, V);
Zhongxing Xu17892752008-10-08 02:50:44 +0000449
450 RegionBindingsTy B = GetRegionBindings(store);
451 return V.isUnknown()
452 ? RBFactory.Remove(B, R).getRoot()
453 : RBFactory.Add(B, R, V).getRoot();
454}
455
Zhongxing Xuf0dfa8d2008-10-31 08:10:01 +0000456Store RegionStoreManager::BindStruct(Store store, const TypedRegion* R, SVal V){
457 QualType T = R->getType(getContext());
458 assert(T->isStructureType());
459
460 const RecordType* RT = cast<RecordType>(T.getTypePtr());
461 RecordDecl* RD = RT->getDecl();
Zhongxing Xua4f28ff2008-11-13 08:41:36 +0000462
463 if (!RD->isDefinition()) {
Zhongxing Xuc3a05992008-11-19 11:06:24 +0000464 // This can only occur when a pointer of incomplete struct type is used as a
Zhongxing Xua4f28ff2008-11-13 08:41:36 +0000465 // function argument.
466 assert(V.isUnknown());
467 return store;
468 }
Zhongxing Xuf0dfa8d2008-10-31 08:10:01 +0000469
470 RegionBindingsTy B = GetRegionBindings(store);
471
Zhongxing Xud463d442008-11-02 12:13:30 +0000472 if (isa<UnknownVal>(V))
473 return BindStructToVal(store, R, UnknownVal());
474
Zhongxing Xuf0dfa8d2008-10-31 08:10:01 +0000475 nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(V);
476
477 nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end();
478 RecordDecl::field_iterator FI = RD->field_begin(), FE = RD->field_end();
479
480 for (; FI != FE; ++FI, ++VI) {
481 assert(VI != VE);
482
483 FieldRegion* FR = MRMgr.getFieldRegion(*FI, R);
484
485 B = RBFactory.Add(B, FR, *VI);
486 }
487
488 return B.getRoot();
489}
490
Zhongxing Xu17892752008-10-08 02:50:44 +0000491Store RegionStoreManager::getInitialStore() {
492 typedef LiveVariables::AnalysisDataTy LVDataTy;
493 LVDataTy& D = StateMgr.getLiveVariables().getAnalysisData();
494
495 Store St = RBFactory.GetEmptyMap().getRoot();
496
497 for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) {
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000498 NamedDecl* ND = const_cast<NamedDecl*>(I->first);
Zhongxing Xu17892752008-10-08 02:50:44 +0000499
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000500 if (VarDecl* VD = dyn_cast<VarDecl>(ND)) {
Zhongxing Xu17892752008-10-08 02:50:44 +0000501 // Punt on static variables for now.
502 if (VD->getStorageClass() == VarDecl::Static)
503 continue;
504
Zhongxing Xuc3a05992008-11-19 11:06:24 +0000505 VarRegion* VR = MRMgr.getVarRegion(VD);
506
Zhongxing Xu17892752008-10-08 02:50:44 +0000507 QualType T = VD->getType();
508 // Only handle pointers and integers for now.
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000509 if (Loc::IsLocType(T) || T->isIntegerType()) {
Zhongxing Xu17892752008-10-08 02:50:44 +0000510 // Initialize globals and parameters to symbolic values.
511 // Initialize local variables to undefined.
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000512 SVal X = (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) ||
Zhongxing Xu17892752008-10-08 02:50:44 +0000513 isa<ImplicitParamDecl>(VD))
Zhongxing Xu63123d82008-11-23 04:30:35 +0000514 ? SVal::GetSymbolValue(getSymbolManager(), VD)
Zhongxing Xu17892752008-10-08 02:50:44 +0000515 : UndefinedVal();
516
Zhongxing Xu8485ec62008-10-21 06:27:32 +0000517 St = Bind(St, getVarLoc(VD), X);
Zhongxing Xuc3a05992008-11-19 11:06:24 +0000518 }
519 else if (T->isArrayType()) {
520 if (VD->hasGlobalStorage()) // Params cannot have array type.
521 St = BindArrayToSymVal(St, VR);
522 else
523 St = BindArrayToVal(St, VR, UndefinedVal());
524 }
525 else if (T->isStructureType()) {
526 if (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) ||
527 isa<ImplicitParamDecl>(VD))
528 St = BindStructToSymVal(St, VR);
529 else
530 St = BindStructToVal(St, VR, UndefinedVal());
Zhongxing Xu17892752008-10-08 02:50:44 +0000531 }
532 }
533 }
534 return St;
535}
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000536
Ted Kremenek42577d12008-11-12 19:18:35 +0000537Store RegionStoreManager::BindDecl(Store store, const VarDecl* VD,
538 SVal* InitVal, unsigned Count) {
539
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000540 if (VD->hasGlobalStorage()) {
541 // Static global variables should not be visited here.
542 assert(!(VD->getStorageClass() == VarDecl::Static &&
543 VD->isFileVarDecl()));
544 // Process static variables.
545 if (VD->getStorageClass() == VarDecl::Static) {
Ted Kremenek42577d12008-11-12 19:18:35 +0000546 if (!InitVal) {
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000547 // Only handle pointer and integer static variables.
548
549 QualType T = VD->getType();
550
551 if (Loc::IsLocType(T))
Zhongxing Xu8485ec62008-10-21 06:27:32 +0000552 store = Bind(store, getVarLoc(VD),
Zhongxing Xu63123d82008-11-23 04:30:35 +0000553 loc::ConcreteInt(getBasicVals().getValue(0, T)));
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000554
555 else if (T->isIntegerType())
Zhongxing Xu8485ec62008-10-21 06:27:32 +0000556 store = Bind(store, getVarLoc(VD),
Zhongxing Xu63123d82008-11-23 04:30:35 +0000557 loc::ConcreteInt(getBasicVals().getValue(0, T)));
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000558
559 // Other types of static local variables are not handled yet.
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000560 } else {
Ted Kremenek42577d12008-11-12 19:18:35 +0000561 store = Bind(store, getVarLoc(VD), *InitVal);
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000562 }
563 }
564 } else {
565 // Process local variables.
566
567 QualType T = VD->getType();
568
Zhongxing Xua82512a2008-10-24 08:42:28 +0000569 VarRegion* VR = MRMgr.getVarRegion(VD);
570
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000571 if (Loc::IsLocType(T) || T->isIntegerType()) {
Ted Kremenek42577d12008-11-12 19:18:35 +0000572 SVal V = InitVal ? *InitVal : UndefinedVal();
Zhongxing Xua82512a2008-10-24 08:42:28 +0000573 store = Bind(store, loc::MemRegionVal(VR), V);
Ted Kremenek42577d12008-11-12 19:18:35 +0000574 }
575 else if (T->isArrayType()) {
576 if (!InitVal)
Zhongxing Xud463d442008-11-02 12:13:30 +0000577 store = BindArrayToVal(store, VR, UndefinedVal());
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000578 else
Ted Kremenek42577d12008-11-12 19:18:35 +0000579 store = InitializeArray(store, VR, *InitVal);
580 }
581 else if (T->isStructureType()) {
582 if (!InitVal)
Zhongxing Xud463d442008-11-02 12:13:30 +0000583 store = BindStructToVal(store, VR, UndefinedVal());
Zhongxing Xuaf0a8442008-10-31 10:53:01 +0000584 else
Ted Kremenek42577d12008-11-12 19:18:35 +0000585 store = InitializeStruct(store, VR, *InitVal);
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000586 }
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000587
588 // Other types of local variables are not handled yet.
Zhongxing Xu53bcdd42008-10-21 05:29:26 +0000589 }
590 return store;
591}
592
Zhongxing Xuf22679e2008-11-07 10:38:33 +0000593Store RegionStoreManager::BindCompoundLiteral(Store store,
594 const CompoundLiteralExpr* CL,
595 SVal V) {
596 CompoundLiteralRegion* R = MRMgr.getCompoundLiteralRegion(CL);
597 store = Bind(store, loc::MemRegionVal(R), V);
598 return store;
599}
600
Zhongxing Xubaf03a72008-11-24 09:44:56 +0000601const GRState* RegionStoreManager::setExtent(const GRState* St,
602 const MemRegion* R, SVal Extent) {
603 GRStateRef state(St, StateMgr);
604 return state.set<RegionExtentsTy>(R, Extent);
605}
606
607
Zhongxing Xu8916d5b2008-11-10 09:39:04 +0000608Store RegionStoreManager::RemoveDeadBindings(Store store, Stmt* Loc,
609 const LiveVariables& Live,
610 llvm::SmallVectorImpl<const MemRegion*>& RegionRoots,
611 LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols) {
612
613 RegionBindingsTy B = GetRegionBindings(store);
614 typedef SVal::symbol_iterator symbol_iterator;
615
616 // FIXME: Mark all region binding value's symbol as live. We also omit symbols
617 // in SymbolicRegions.
618 for (RegionBindingsTy::iterator I = B.begin(), E = B.end(); I != E; ++I) {
619 SVal X = I.getData();
620 for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI)
621 LSymbols.insert(*SI);
622 }
623
624 return store;
625}
626
Zhongxing Xua071eb02008-10-24 06:01:33 +0000627void RegionStoreManager::print(Store store, std::ostream& Out,
628 const char* nl, const char *sep) {
629 llvm::raw_os_ostream OS(Out);
630 RegionBindingsTy B = GetRegionBindings(store);
631 OS << "Store:" << nl;
632
633 for (RegionBindingsTy::iterator I = B.begin(), E = B.end(); I != E; ++I) {
634 OS << ' '; I.getKey()->print(OS); OS << " : ";
635 I.getData().print(OS); OS << nl;
636 }
Zhongxing Xu5b8b6f22008-10-24 04:33:15 +0000637}
Zhongxing Xua82512a2008-10-24 08:42:28 +0000638
Zhongxing Xud463d442008-11-02 12:13:30 +0000639Store RegionStoreManager::InitializeArray(Store store, const TypedRegion* R,
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000640 SVal Init) {
641 QualType T = R->getType(getContext());
642 assert(T->isArrayType());
643
644 ConstantArrayType* CAT = cast<ConstantArrayType>(T.getTypePtr());
645
Zhongxing Xu6987c7b2008-11-30 05:49:49 +0000646 llvm::APSInt Size(CAT->getSize(), false);
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000647
Sebastian Redl50038612008-12-02 16:47:35 +0000648 llvm::APSInt i = getBasicVals().getValue(0, Size.getBitWidth(),
649 Size.isUnsigned());
Zhongxing Xu6987c7b2008-11-30 05:49:49 +0000650
651 // Check if the init expr is a StringLiteral.
652 if (isa<loc::MemRegionVal>(Init)) {
653 const MemRegion* InitR = cast<loc::MemRegionVal>(Init).getRegion();
654 const StringLiteral* S = cast<StringRegion>(InitR)->getStringLiteral();
655 const char* str = S->getStrData();
656 unsigned len = S->getByteLength();
657 unsigned j = 0;
658
659 for (; i < Size; ++i, ++j) {
660 SVal Idx = NonLoc::MakeVal(getBasicVals(), i);
661 ElementRegion* ER = MRMgr.getElementRegion(Idx, R);
662
663 // Copy bytes from the string literal into the target array. Trailing
664 // bytes in the array that are not covered by the string literal are
665 // initialized to zero.
666 SVal V = (j < len)
667 ? NonLoc::MakeVal(getBasicVals(), str[j], sizeof(char)*8, true)
668 : NonLoc::MakeVal(getBasicVals(), 0, sizeof(char)*8, true);
669
670 store = Bind(store, loc::MemRegionVal(ER), V);
671 }
672
673 return store;
674 }
675
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000676
677 nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(Init);
678
679 nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end();
680
Zhongxing Xu6987c7b2008-11-30 05:49:49 +0000681 for (; i < Size; ++i) {
682 SVal Idx = NonLoc::MakeVal(getBasicVals(), i);
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000683 ElementRegion* ER = MRMgr.getElementRegion(Idx, R);
684
685 store = Bind(store, loc::MemRegionVal(ER), (VI!=VE) ? *VI : UndefinedVal());
686 // The init list might be shorter than the array decl.
687 if (VI != VE) ++VI;
688 }
689
690 return store;
691}
692
Zhongxing Xud463d442008-11-02 12:13:30 +0000693// Bind all elements of the array to some value.
694Store RegionStoreManager::BindArrayToVal(Store store, const TypedRegion* BaseR,
695 SVal V){
Zhongxing Xuea8a1852008-10-31 11:02:48 +0000696 QualType T = BaseR->getType(getContext());
Zhongxing Xua82512a2008-10-24 08:42:28 +0000697 assert(T->isArrayType());
698
Zhongxing Xua82512a2008-10-24 08:42:28 +0000699 // Only handle constant size array for now.
700 if (ConstantArrayType* CAT=dyn_cast<ConstantArrayType>(T.getTypePtr())) {
701
702 llvm::APInt Size = CAT->getSize();
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000703 llvm::APInt i = llvm::APInt::getNullValue(Size.getBitWidth());
Zhongxing Xu96cb9fb2008-11-28 08:41:39 +0000704
Zhongxing Xu1a12a0e2008-10-31 10:24:47 +0000705 for (; i != Size; ++i) {
Zhongxing Xu96cb9fb2008-11-28 08:41:39 +0000706 nonloc::ConcreteInt Idx(getBasicVals().getValue(llvm::APSInt(i, false)));
Zhongxing Xua82512a2008-10-24 08:42:28 +0000707
708 ElementRegion* ER = MRMgr.getElementRegion(Idx, BaseR);
709
Zhongxing Xu9b6ceb12008-11-18 13:11:04 +0000710 if (CAT->getElementType()->isStructureType())
711 store = BindStructToVal(store, ER, V);
712 else
713 store = Bind(store, loc::MemRegionVal(ER), V);
Zhongxing Xua82512a2008-10-24 08:42:28 +0000714 }
715 }
716
717 return store;
718}
719
Zhongxing Xuc3a05992008-11-19 11:06:24 +0000720Store RegionStoreManager::BindArrayToSymVal(Store store,
721 const TypedRegion* BaseR) {
722 QualType T = BaseR->getType(getContext());
723 assert(T->isArrayType());
724
725 if (ConstantArrayType* CAT = dyn_cast<ConstantArrayType>(T.getTypePtr())) {
726 llvm::APInt Size = CAT->getSize();
727 llvm::APInt i = llvm::APInt::getNullValue(Size.getBitWidth());
728 for (; i != Size; ++i) {
Zhongxing Xu96cb9fb2008-11-28 08:41:39 +0000729 nonloc::ConcreteInt Idx(getBasicVals().getValue(llvm::APSInt(i, false)));
Zhongxing Xuc3a05992008-11-19 11:06:24 +0000730
731 ElementRegion* ER = MRMgr.getElementRegion(Idx, BaseR);
732
733 if (CAT->getElementType()->isStructureType()) {
734 store = BindStructToSymVal(store, ER);
735 }
736 else {
737 SVal V = SVal::getSymbolValue(getSymbolManager(), BaseR,
738 &Idx.getValue(), CAT->getElementType());
739 store = Bind(store, loc::MemRegionVal(ER), V);
740 }
741 }
742 }
743
744 return store;
745}
746
Zhongxing Xud463d442008-11-02 12:13:30 +0000747Store RegionStoreManager::InitializeStruct(Store store, const TypedRegion* R,
Zhongxing Xuea8a1852008-10-31 11:02:48 +0000748 SVal Init) {
Zhongxing Xuaf0a8442008-10-31 10:53:01 +0000749 QualType T = R->getType(getContext());
750 assert(T->isStructureType());
751
752 RecordType* RT = cast<RecordType>(T.getTypePtr());
753 RecordDecl* RD = RT->getDecl();
754 assert(RD->isDefinition());
755
756 nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(Init);
757 nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end();
758 RecordDecl::field_iterator FI = RD->field_begin(), FE = RD->field_end();
759
760 for (; FI != FE; ++FI) {
761 QualType FTy = (*FI)->getType();
762 FieldRegion* FR = MRMgr.getFieldRegion(*FI, R);
763
764 if (Loc::IsLocType(FTy) || FTy->isIntegerType()) {
765 if (VI != VE) {
766 store = Bind(store, loc::MemRegionVal(FR), *VI);
767 ++VI;
768 } else
769 store = Bind(store, loc::MemRegionVal(FR), UndefinedVal());
770 }
771 else if (FTy->isArrayType()) {
772 if (VI != VE) {
773 store = InitializeArray(store, FR, *VI);
774 ++VI;
775 } else
Zhongxing Xud463d442008-11-02 12:13:30 +0000776 store = BindArrayToVal(store, FR, UndefinedVal());
Zhongxing Xuaf0a8442008-10-31 10:53:01 +0000777 }
778 else if (FTy->isStructureType()) {
779 if (VI != VE) {
780 store = InitializeStruct(store, FR, *VI);
781 ++VI;
782 } else
Zhongxing Xud463d442008-11-02 12:13:30 +0000783 store = BindStructToVal(store, FR, UndefinedVal());
Zhongxing Xuaf0a8442008-10-31 10:53:01 +0000784 }
785 }
786 return store;
787}
788
Zhongxing Xud463d442008-11-02 12:13:30 +0000789// Bind all fields of the struct to some value.
790Store RegionStoreManager::BindStructToVal(Store store, const TypedRegion* BaseR,
791 SVal V) {
Zhongxing Xuea8a1852008-10-31 11:02:48 +0000792 QualType T = BaseR->getType(getContext());
793 assert(T->isStructureType());
794
795 const RecordType* RT = cast<RecordType>(T.getTypePtr());
Zhongxing Xua82512a2008-10-24 08:42:28 +0000796 RecordDecl* RD = RT->getDecl();
797 assert(RD->isDefinition());
Zhongxing Xuea8a1852008-10-31 11:02:48 +0000798
799 RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
800
801 for (; I != E; ++I) {
Zhongxing Xua82512a2008-10-24 08:42:28 +0000802
803 QualType FTy = (*I)->getType();
804 FieldRegion* FR = MRMgr.getFieldRegion(*I, BaseR);
805
806 if (Loc::IsLocType(FTy) || FTy->isIntegerType()) {
Zhongxing Xud463d442008-11-02 12:13:30 +0000807 store = Bind(store, loc::MemRegionVal(FR), V);
Zhongxing Xua82512a2008-10-24 08:42:28 +0000808
809 } else if (FTy->isArrayType()) {
Zhongxing Xud463d442008-11-02 12:13:30 +0000810 store = BindArrayToVal(store, FR, V);
Zhongxing Xua82512a2008-10-24 08:42:28 +0000811
812 } else if (FTy->isStructureType()) {
Zhongxing Xud463d442008-11-02 12:13:30 +0000813 store = BindStructToVal(store, FR, V);
Zhongxing Xua82512a2008-10-24 08:42:28 +0000814 }
815 }
816
817 return store;
818}
Zhongxing Xudc0a25d2008-11-16 04:07:26 +0000819
Zhongxing Xuc3a05992008-11-19 11:06:24 +0000820Store RegionStoreManager::BindStructToSymVal(Store store,
821 const TypedRegion* BaseR) {
822 QualType T = BaseR->getType(getContext());
823 assert(T->isStructureType());
824
825 const RecordType* RT = cast<RecordType>(T.getTypePtr());
826 RecordDecl* RD = RT->getDecl();
827 assert(RD->isDefinition());
828
829 RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
830
831 for (; I != E; ++I) {
832 QualType FTy = (*I)->getType();
833 FieldRegion* FR = MRMgr.getFieldRegion(*I, BaseR);
834
835 if (Loc::IsLocType(FTy) || FTy->isIntegerType()) {
836 store = Bind(store, loc::MemRegionVal(FR),
837 SVal::getSymbolValue(getSymbolManager(), BaseR, *I, FTy));
838 }
839 else if (FTy->isArrayType()) {
840 store = BindArrayToSymVal(store, FR);
841 }
842 else if (FTy->isStructureType()) {
843 store = BindStructToSymVal(store, FR);
844 }
845 }
846
847 return store;
848}
849
Zhongxing Xudc0a25d2008-11-16 04:07:26 +0000850const GRState* RegionStoreManager::AddRegionView(const GRState* St,
851 const MemRegion* View,
852 const MemRegion* Base) {
853 GRStateRef state(St, StateMgr);
854
855 // First, retrieve the region view of the base region.
856 RegionViewMapTy::data_type* d = state.get<RegionViewMapTy>(Base);
857 RegionViewTy L = d ? *d : RVFactory.GetEmptyList();
858
859 // Now add View to the region view.
860 L = RVFactory.Add(View, L);
861
862 // Create a new state with the new region view.
863 return state.set<RegionViewMapTy>(Base, L);
864}