[cfe-commits] r74867 - in /cfe/trunk: lib/Analysis/Store.cpp test/Analysis/misc-ps.m
Ted Kremenek
kremenek at apple.com
Mon Jul 6 15:23:45 PDT 2009
Author: kremenek
Date: Mon Jul 6 17:23:45 2009
New Revision: 74867
URL: http://llvm.org/viewvc/llvm-project?rev=74867&view=rev
Log:
StoreManager::NewCastRegion:
- Refactor logic that creates ElementRegions into a help method 'MakeElementRegion'.
- Fix crash due to not handling StringRegions. Casts of StringRegions now
result in a new ElementRegion layered on the original StringRegion.
Modified:
cfe/trunk/lib/Analysis/Store.cpp
cfe/trunk/test/Analysis/misc-ps.m
Modified: cfe/trunk/lib/Analysis/Store.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/Store.cpp?rev=74867&r1=74866&r2=74867&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/Store.cpp (original)
+++ cfe/trunk/lib/Analysis/Store.cpp Mon Jul 6 17:23:45 2009
@@ -23,6 +23,19 @@
MRMgr(ValMgr.getRegionManager()) {}
StoreManager::CastResult
+StoreManager::MakeElementRegion(const GRState *state, const MemRegion *region,
+ QualType pointeeTy, QualType castToTy) {
+
+ // Record the cast type of the region.
+ state = setCastType(state, region, castToTy);
+
+ // Create a new ElementRegion at offset 0.
+ SVal idx = ValMgr.makeZeroArrayIndex();
+ return CastResult(state, MRMgr.getElementRegion(pointeeTy, idx, region,
+ ValMgr.getContext()));
+}
+
+StoreManager::CastResult
StoreManager::NewCastRegion(const GRState *state, const MemRegion* R,
QualType CastToTy) {
@@ -38,19 +51,23 @@
&& CastToTy->getAsPointerType()->getPointeeType()->isVoidType()));
return CastResult(state, R);
}
-
+
// Check cast to ObjCQualifiedID type.
if (ToTy->isObjCQualifiedIdType()) {
// FIXME: Record the type information aside.
return CastResult(state, R);
}
-
+
// Now assume we are casting from pointer to pointer. Other cases should
// already be handled.
QualType PointeeTy = cast<PointerType>(ToTy.getTypePtr())->getPointeeType();
-
+
// Process region cast according to the kind of the region being cast.
+ // Handle casts of string literals.
+ if (isa<StringRegion>(R))
+ return MakeElementRegion(state, R, PointeeTy, ToTy);
+
// FIXME: Need to handle arbitrary downcasts.
if (isa<SymbolicRegion>(R) || isa<AllocaRegion>(R)) {
state = setCastType(state, R, ToTy);
@@ -77,13 +94,8 @@
if ((PointeeTySize > 0 && PointeeTySize < ObjTySize) ||
(ObjTy->isAggregateType() && PointeeTy->isScalarType()) ||
- ObjTySize == 0 /* R has 'void*' type. */) {
- // Record the cast type of the region.
- state = setCastType(state, R, ToTy);
-
- SVal Idx = ValMgr.makeZeroArrayIndex();
- ElementRegion* ER = MRMgr.getElementRegion(PointeeTy, Idx,R, Ctx);
- return CastResult(state, ER);
+ ObjTySize == 0 /* R has 'void*' type. */) {
+ return MakeElementRegion(state, R, PointeeTy, ToTy);
} else {
state = setCastType(state, R, ToTy);
return CastResult(state, R);
Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=74867&r1=74866&r2=74867&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Mon Jul 6 17:23:45 2009
@@ -297,4 +297,13 @@
(rdar_7027684_aux() ? rdar_7027684_aux_2() : (void) 0);
}
+// Test that we handle casts of string literals to arbitrary types.
+unsigned const char *string_literal_test1() {
+ return (const unsigned char*) "hello";
+}
+
+const float *string_literal_test2() {
+ return (const float*) "hello";
+}
+
More information about the cfe-commits
mailing list