Ted Kremenek | c62abc1 | 2009-04-21 21:51:34 +0000 | [diff] [blame^] | 1 | //== 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 | |
| 17 | using namespace clang; |
| 18 | |
| 19 | StoreManager::StoreManager(GRStateManager &stateMgr) |
| 20 | : ValMgr(stateMgr.getValueManager()), |
| 21 | StateMgr(stateMgr), |
| 22 | MRMgr(ValMgr.getRegionManager()) {} |
| 23 | |
| 24 | StoreManager::CastResult |
| 25 | StoreManager::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 | } |