aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/RegionStore.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-07-10 22:30:06 +0000
committerTed Kremenek <kremenek@apple.com>2009-07-10 22:30:06 +0000
commit7ecbfbcddd278eede10bd38fa03a95a2110b191a (patch)
tree04be65925ff24bcfc36c847cef9d9cc3d1d0cb14 /lib/Analysis/RegionStore.cpp
parent88bd3406013a491fd628610be2d74f9063cfdb05 (diff)
Restructure RegionStoreManager::getSizeInElements() to use a switch statement
over the types of MemRegions. This allows the compiler to warn us which regions are not handled, and also is a little faster. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75304 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/RegionStore.cpp')
-rw-r--r--lib/Analysis/RegionStore.cpp119
1 files changed, 67 insertions, 52 deletions
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp
index 1e95f174b5..45a6198647 100644
--- a/lib/Analysis/RegionStore.cpp
+++ b/lib/Analysis/RegionStore.cpp
@@ -538,64 +538,79 @@ SVal RegionStoreManager::getLValueElement(const GRState *St,
//===----------------------------------------------------------------------===//
SVal RegionStoreManager::getSizeInElements(const GRState *state,
- const MemRegion* R) {
- if (const VarRegion* VR = dyn_cast<VarRegion>(R)) {
- // Get the type of the variable.
- QualType T = VR->getDesugaredValueType(getContext());
+ const MemRegion *R) {
+
+ switch (R->getKind()) {
+ case MemRegion::MemSpaceRegionKind:
+ assert(0 && "Cannot index into a MemSpace");
+ return UnknownVal();
+
+ case MemRegion::CodeTextRegionKind:
+ // Technically this can happen if people do funny things with casts.
+ return UnknownVal();
- // FIXME: Handle variable-length arrays.
- if (isa<VariableArrayType>(T))
+ // Not yet handled.
+ case MemRegion::AllocaRegionKind:
+ case MemRegion::CompoundLiteralRegionKind:
+ case MemRegion::ElementRegionKind:
+ case MemRegion::FieldRegionKind:
+ case MemRegion::ObjCIvarRegionKind:
+ case MemRegion::ObjCObjectRegionKind:
+ case MemRegion::SymbolicRegionKind:
return UnknownVal();
-
- if (const ConstantArrayType* CAT = dyn_cast<ConstantArrayType>(T)) {
- // return the size as signed integer.
- return ValMgr.makeIntVal(CAT->getSize(), false);
+
+ case MemRegion::StringRegionKind: {
+ const StringLiteral* Str = cast<StringRegion>(R)->getStringLiteral();
+ // We intentionally made the size value signed because it participates in
+ // operations with signed indices.
+ return ValMgr.makeIntVal(Str->getByteLength()+1, false);
}
+
+ // TypedViewRegion will soon be removed.
+ case MemRegion::TypedViewRegionKind:
+ return UnknownVal();
- const QualType* CastTy = state->get<RegionCasts>(VR);
-
- // If the VarRegion is cast to other type, compute the size with respect to
- // that type.
- if (CastTy) {
- QualType EleTy =cast<PointerType>(CastTy->getTypePtr())->getPointeeType();
- QualType VarTy = VR->getValueType(getContext());
- uint64_t EleSize = getContext().getTypeSize(EleTy);
- uint64_t VarSize = getContext().getTypeSize(VarTy);
- assert(VarSize != 0);
- return ValMgr.makeIntVal(VarSize/EleSize, false);
+ case MemRegion::VarRegionKind: {
+ const VarRegion* VR = cast<VarRegion>(R);
+ // Get the type of the variable.
+ QualType T = VR->getDesugaredValueType(getContext());
+
+ // FIXME: Handle variable-length arrays.
+ if (isa<VariableArrayType>(T))
+ return UnknownVal();
+
+ if (const ConstantArrayType* CAT = dyn_cast<ConstantArrayType>(T)) {
+ // return the size as signed integer.
+ return ValMgr.makeIntVal(CAT->getSize(), false);
+ }
+
+ const QualType* CastTy = state->get<RegionCasts>(VR);
+
+ // If the VarRegion is cast to other type, compute the size with respect to
+ // that type.
+ if (CastTy) {
+ QualType EleTy =cast<PointerType>(CastTy->getTypePtr())->getPointeeType();
+ QualType VarTy = VR->getValueType(getContext());
+ uint64_t EleSize = getContext().getTypeSize(EleTy);
+ uint64_t VarSize = getContext().getTypeSize(VarTy);
+ assert(VarSize != 0);
+ return ValMgr.makeIntVal(VarSize/EleSize, false);
+ }
+
+ // Clients can use ordinary variables as if they were arrays. These
+ // essentially are arrays of size 1.
+ return ValMgr.makeIntVal(1, false);
}
-
- // Clients can use ordinary variables as if they were arrays. These
- // essentially are arrays of size 1.
- return ValMgr.makeIntVal(1, false);
- }
-
- if (const StringRegion* SR = dyn_cast<StringRegion>(R)) {
- const StringLiteral* Str = SR->getStringLiteral();
- // We intentionally made the size value signed because it participates in
- // operations with signed indices.
- return ValMgr.makeIntVal(Str->getByteLength()+1, false);
- }
-
- if (const FieldRegion* FR = dyn_cast<FieldRegion>(R)) {
- // FIXME: Unsupported yet.
- FR = 0;
- return UnknownVal();
- }
-
- if (isa<SymbolicRegion>(R)) {
- return UnknownVal();
- }
-
- if (isa<AllocaRegion>(R)) {
- return UnknownVal();
- }
-
- if (isa<ElementRegion>(R)) {
- return UnknownVal();
+
+ case MemRegion::BEG_DECL_REGIONS:
+ case MemRegion::END_DECL_REGIONS:
+ case MemRegion::BEG_TYPED_REGIONS:
+ case MemRegion::END_TYPED_REGIONS:
+ assert(0 && "Infeasible region");
+ return UnknownVal();
}
-
- assert(0 && "Other regions are not supported yet.");
+
+ assert(0 && "Unreachable");
return UnknownVal();
}