aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/Store.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-04-21 21:51:34 +0000
committerTed Kremenek <kremenek@apple.com>2009-04-21 21:51:34 +0000
commitc62abc1012feb0b15eff091b02c176649766a347 (patch)
tree61bd1482a0292fac61add423346827b1efdf564d /lib/Analysis/Store.cpp
parent293b4d6a4394174e46d0b3faf6353ed98203792d (diff)
Refactor 'BasicStoreManager::CastRegion' and 'RegionStoreManager::CastRegion'
into StoreManager::CastRegion. Both methods were practically identical, and this is core logic that is common to all StoreManagers since it defines the basic invariants of the abstract memory model. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69730 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/Store.cpp')
-rw-r--r--lib/Analysis/Store.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/Analysis/Store.cpp b/lib/Analysis/Store.cpp
new file mode 100644
index 0000000000..edd353d0f2
--- /dev/null
+++ b/lib/Analysis/Store.cpp
@@ -0,0 +1,47 @@
+//== Store.cpp - Interface for maps from Locations to Values ----*- C++ -*--==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defined the types Store and StoreManager.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Analysis/PathSensitive/Store.h"
+#include "clang/Analysis/PathSensitive/GRState.h"
+
+using namespace clang;
+
+StoreManager::StoreManager(GRStateManager &stateMgr)
+ : ValMgr(stateMgr.getValueManager()),
+ StateMgr(stateMgr),
+ MRMgr(ValMgr.getRegionManager()) {}
+
+StoreManager::CastResult
+StoreManager::CastRegion(const GRState* state, const MemRegion* R,
+ QualType CastToTy) {
+
+ // Return the same region if the region types are compatible.
+ if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) {
+ ASTContext& Ctx = StateMgr.getContext();
+ QualType Ta = Ctx.getCanonicalType(TR->getLValueType(Ctx));
+ QualType Tb = Ctx.getCanonicalType(CastToTy);
+
+ if (Ta == Tb)
+ return CastResult(state, R);
+ }
+
+ // FIXME: We should handle the case when we are casting *back* to a
+ // previous type. For example:
+ //
+ // void* x = ...;
+ // char* y = (char*) x;
+ // void* z = (void*) y; // <-- we should get the same region that is
+ // bound to 'x'
+ const MemRegion* ViewR = MRMgr.getTypedViewRegion(CastToTy, R);
+ return CastResult(AddRegionView(state, ViewR, R), ViewR);
+}