blob: edd353d0f21a3b9ccc02d548816f98b626e233d4 [file] [log] [blame]
Ted Kremenekc62abc12009-04-21 21:51:34 +00001//== Store.cpp - Interface for maps from Locations to Values ----*- 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 defined the types Store and StoreManager.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Analysis/PathSensitive/Store.h"
15#include "clang/Analysis/PathSensitive/GRState.h"
16
17using namespace clang;
18
19StoreManager::StoreManager(GRStateManager &stateMgr)
20 : ValMgr(stateMgr.getValueManager()),
21 StateMgr(stateMgr),
22 MRMgr(ValMgr.getRegionManager()) {}
23
24StoreManager::CastResult
25StoreManager::CastRegion(const GRState* state, const MemRegion* R,
26 QualType CastToTy) {
27
28 // Return the same region if the region types are compatible.
29 if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) {
30 ASTContext& Ctx = StateMgr.getContext();
31 QualType Ta = Ctx.getCanonicalType(TR->getLValueType(Ctx));
32 QualType Tb = Ctx.getCanonicalType(CastToTy);
33
34 if (Ta == Tb)
35 return CastResult(state, R);
36 }
37
38 // FIXME: We should handle the case when we are casting *back* to a
39 // previous type. For example:
40 //
41 // void* x = ...;
42 // char* y = (char*) x;
43 // void* z = (void*) y; // <-- we should get the same region that is
44 // bound to 'x'
45 const MemRegion* ViewR = MRMgr.getTypedViewRegion(CastToTy, R);
46 return CastResult(AddRegionView(state, ViewR, R), ViewR);
47}