diff options
-rw-r--r-- | lib/Analysis/RegionStore.cpp | 9 | ||||
-rw-r--r-- | test/Analysis/misc-ps-region-store.m | 9 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 9fe41bed2a..f63e9d874e 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -1060,6 +1060,13 @@ SVal RegionStoreManager::RetrieveElement(const GRState* state, // Check if the region is an element region of a string literal. if (const StringRegion *StrR=dyn_cast<StringRegion>(superR)) { + // FIXME: Handle loads from strings where the literal is treated as + // an integer, e.g., *((unsigned int*)"hello") + ASTContext &Ctx = getContext(); + QualType T = StrR->getValueType(Ctx)->getAs<ArrayType>()->getElementType(); + if (T != Ctx.getCanonicalType(R->getElementType())) + return UnknownVal(); + const StringLiteral *Str = StrR->getStringLiteral(); SVal Idx = R->getIndex(); if (nonloc::ConcreteInt *CI = dyn_cast<nonloc::ConcreteInt>(&Idx)) { @@ -1072,7 +1079,7 @@ SVal RegionStoreManager::RetrieveElement(const GRState* state, return UnknownVal(); } char c = (i == byteLength) ? '\0' : Str->getStrData()[i]; - return ValMgr.makeIntVal(c, getContext().CharTy); + return ValMgr.makeIntVal(c, T); } } diff --git a/test/Analysis/misc-ps-region-store.m b/test/Analysis/misc-ps-region-store.m index 66f01fc7b3..24ebe5b236 100644 --- a/test/Analysis/misc-ps-region-store.m +++ b/test/Analysis/misc-ps-region-store.m @@ -278,3 +278,12 @@ int test_handle_array_wrapper() { return p->z; // no-warning } +// <rdar://problem/7261075> [RegionStore] crash when +// handling load: '*((unsigned int *)"????")' +int rdar_7261075(void) { + unsigned int var = 0; + if (var == *((unsigned int *)"????")) + return 1; + return 0; +} + |