[cfe-commits] r74884 - in /cfe/trunk: lib/Analysis/Store.cpp test/Analysis/misc-ps.m
Ted Kremenek
kremenek at apple.com
Mon Jul 6 16:47:20 PDT 2009
Author: kremenek
Date: Mon Jul 6 18:47:19 2009
New Revision: 74884
URL: http://llvm.org/viewvc/llvm-project?rev=74884&view=rev
Log:
NewCastRegion: Handle casts *from* pointers to incomplete structs to other types.
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=74884&r1=74883&r2=74884&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/Store.cpp (original)
+++ cfe/trunk/lib/Analysis/Store.cpp Mon Jul 6 18:47:19 2009
@@ -35,6 +35,16 @@
ValMgr.getContext()));
}
+static bool IsCompleteType(ASTContext &Ctx, QualType Ty) {
+ if (const RecordType *RT = Ty->getAsRecordType()) {
+ const RecordDecl *D = RT->getDecl();
+ if (!D->getDefinition(Ctx))
+ return false;
+ }
+
+ return true;
+}
+
StoreManager::CastResult
StoreManager::NewCastRegion(const GRState *state, const MemRegion* R,
QualType CastToTy) {
@@ -53,7 +63,7 @@
// Now assume we are casting from pointer to pointer. Other cases should
// already be handled.
QualType PointeeTy = CastToTy->getAsPointerType()->getPointeeType();
-
+
// Process region cast according to the kind of the region being cast.
switch (R->getKind()) {
case MemRegion::BEG_TYPED_REGIONS:
@@ -96,15 +106,15 @@
// the cast-to pointee type is of smaller size. In other cases, we return
// the original VarRegion.
- // If the pointee type is incomplete, do not compute its size, and return
- // the original region.
- if (const RecordType *RT = PointeeTy->getAsRecordType()) {
- const RecordDecl *D = RT->getDecl();
- if (!D->getDefinition(Ctx))
- return CastResult(state, R);
- }
-
+ // If the pointee or object type is incomplete, do compute their sizes,
+ // and return the original region.
QualType ObjTy = cast<TypedRegion>(R)->getValueType(Ctx);
+
+ if (!IsCompleteType(Ctx, PointeeTy) || !IsCompleteType(Ctx, ObjTy)) {
+ state = setCastType(state, R, ToTy);
+ break;
+ }
+
uint64_t PointeeTySize = Ctx.getTypeSize(PointeeTy);
uint64_t ObjTySize = Ctx.getTypeSize(ObjTy);
Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=74884&r1=74883&r2=74884&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Mon Jul 6 18:47:19 2009
@@ -306,4 +306,10 @@
return (const float*) "hello";
}
+// Test that we handle casts *from* incomplete struct types.
+extern const struct _FooAssertStruct _cmd;
+void test_cast_from_incomplete_struct_aux(volatile const void *x);
+void test_cast_from_incomplete_struct() {
+ test_cast_from_incomplete_struct_aux(&_cmd);
+}
More information about the cfe-commits
mailing list