From f7a6de3a12545d51f48aebdad39b03720c43a084 Mon Sep 17 00:00:00 2001 From: Zhongxing Xu Date: Sun, 28 Jun 2009 09:26:15 +0000 Subject: [PATCH] Simplify some code. As in region store, we always expect the location is a memregion. llvm-svn: 74406 --- clang/lib/Analysis/BasicStore.cpp | 77 ++++++++++++++----------------- 1 file changed, 35 insertions(+), 42 deletions(-) diff --git a/clang/lib/Analysis/BasicStore.cpp b/clang/lib/Analysis/BasicStore.cpp index 8fbce528fa9a..44831f68e6a2 100644 --- a/clang/lib/Analysis/BasicStore.cpp +++ b/clang/lib/Analysis/BasicStore.cpp @@ -319,54 +319,47 @@ SVal BasicStoreManager::Retrieve(const GRState *state, Loc loc, QualType T) { } Store BasicStoreManager::BindInternal(Store store, Loc loc, SVal V) { - switch (loc.getSubKind()) { - case loc::MemRegionKind: { - const MemRegion* R = cast(loc).getRegion(); - ASTContext &C = StateMgr.getContext(); + const MemRegion* R = cast(loc).getRegion(); + ASTContext &C = StateMgr.getContext(); - // Special case: handle store of pointer values (Loc) to pointers via - // a cast to intXX_t*, void*, etc. This is needed to handle - // OSCompareAndSwap32Barrier/OSCompareAndSwap64Barrier. - if (isa(V) || isa(V)) - if (const ElementRegion *ER = dyn_cast(R)) { - // FIXME: Should check for index 0. - QualType T = ER->getLocationType(C); + // Special case: handle store of pointer values (Loc) to pointers via + // a cast to intXX_t*, void*, etc. This is needed to handle + // OSCompareAndSwap32Barrier/OSCompareAndSwap64Barrier. + if (isa(V) || isa(V)) + if (const ElementRegion *ER = dyn_cast(R)) { + // FIXME: Should check for index 0. + QualType T = ER->getLocationType(C); - if (isHigherOrderRawPtr(T, C)) - R = ER->getSuperRegion(); - } + if (isHigherOrderRawPtr(T, C)) + R = ER->getSuperRegion(); + } - if (!(isa(R) || isa(R))) - return store; + if (!(isa(R) || isa(R))) + return store; - // We only track bindings to self.ivar. - if (const ObjCIvarRegion *IVR = dyn_cast(R)) - if (IVR->getSuperRegion() != SelfRegion) - return store; - - if (nonloc::LocAsInteger *X = dyn_cast(&V)) { - // Only convert 'V' to a location iff the underlying region type - // is a location as well. - // FIXME: We are allowing a store of an arbitrary location to - // a pointer. We may wish to flag a type error here if the types - // are incompatible. This may also cause lots of breakage - // elsewhere. Food for thought. - if (const TypedRegion *TyR = dyn_cast(R)) { - if (TyR->isBoundable() && - Loc::IsLocType(TyR->getValueType(C))) - V = X->getLoc(); - } - } - - BindingsTy B = GetBindings(store); - return V.isUnknown() - ? VBFactory.Remove(B, R).getRoot() - : VBFactory.Add(B, R, V).getRoot(); - } - default: - assert ("SetSVal for given Loc type not yet implemented."); + // We only track bindings to self.ivar. + if (const ObjCIvarRegion *IVR = dyn_cast(R)) + if (IVR->getSuperRegion() != SelfRegion) return store; + + if (nonloc::LocAsInteger *X = dyn_cast(&V)) { + // Only convert 'V' to a location iff the underlying region type + // is a location as well. + // FIXME: We are allowing a store of an arbitrary location to + // a pointer. We may wish to flag a type error here if the types + // are incompatible. This may also cause lots of breakage + // elsewhere. Food for thought. + if (const TypedRegion *TyR = dyn_cast(R)) { + if (TyR->isBoundable() && + Loc::IsLocType(TyR->getValueType(C))) + V = X->getLoc(); + } } + + BindingsTy B = GetBindings(store); + return V.isUnknown() + ? VBFactory.Remove(B, R).getRoot() + : VBFactory.Add(B, R, V).getRoot(); } Store BasicStoreManager::Remove(Store store, Loc loc) {