aboutsummaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/Core/RegionStore.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-06-11 23:20:52 +0000
committerJordan Rose <jordan_rose@apple.com>2012-06-11 23:20:52 +0000
commit570d03c6831a8e19447dc863aa94ffff020077eb (patch)
treeb513219a733e1b553a92ad5cbc8928b3864d3966 /lib/StaticAnalyzer/Core/RegionStore.cpp
parentdd895f056bff47d2d1a924b49e7b40d48749fcc0 (diff)
[analyzer] Treat LValueBitCasts like regular pointer bit casts.
These casts only appear in very well-defined circumstances, in which the target of a reinterpret_cast or a function formal parameter is an lvalue reference. According to the C++ standard, the following are equivalent: reinterpret_cast<T&>( x) *reinterpret_cast<T*>(&x) [expr.reinterpret.cast]p11 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158338 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Core/RegionStore.cpp')
-rw-r--r--lib/StaticAnalyzer/Core/RegionStore.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/StaticAnalyzer/Core/RegionStore.cpp b/lib/StaticAnalyzer/Core/RegionStore.cpp
index 9c00d96343..86a68a6b3a 100644
--- a/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -878,10 +878,15 @@ SVal RegionStoreManager::ArrayToPointer(Loc Array) {
if (!ArrayR)
return UnknownVal();
- // Strip off typedefs from the ArrayRegion's ValueType.
- QualType T = ArrayR->getValueType().getDesugaredType(Ctx);
- const ArrayType *AT = cast<ArrayType>(T);
- T = AT->getElementType();
+ // Extract the element type from the array region's ValueType.
+ // Be careful about weird things happening due to user-written casts.
+ QualType T = ArrayR->getValueType();
+ if (const ArrayType *AT = Ctx.getAsArrayType(T))
+ T = AT->getElementType();
+ else if (const PointerType *PT = T->getAs<PointerType>())
+ T = PT->getPointeeType();
+ else
+ return UnknownVal();
NonLoc ZeroIdx = svalBuilder.makeZeroArrayIndex();
return loc::MemRegionVal(MRMgr.getElementRegion(T, ZeroIdx, ArrayR, Ctx));