[cfe-commits] r161391 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp lib/StaticAnalyzer/Core/CallEvent.cpp test/Analysis/inlining/ObjCDynTypePopagation.m
Anna Zaks
ganna at apple.com
Mon Aug 6 22:12:25 PDT 2012
Author: zaks
Date: Tue Aug 7 00:12:24 2012
New Revision: 161391
URL: http://llvm.org/viewvc/llvm-project?rev=161391&view=rev
Log:
[analyzer] Address Jordan's review of DynamicTypePropagation.
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
cfe/trunk/test/Analysis/inlining/ObjCDynTypePopagation.m
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp?rev=161391&r1=161390&r2=161391&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp Tue Aug 7 00:12:24 2012
@@ -75,7 +75,8 @@
// Assume, the result of the init method has the same dynamic type as
// the receiver and propagate the dynamic type info.
const MemRegion *RecReg = Msg->getReceiverSVal().getAsRegion();
- assert(RecReg);
+ if (!RecReg)
+ return;
DynamicTypeInfo RecDynType = State->getDynamicTypeInfo(RecReg);
C.addTransition(State->addDynamicTypeInfo(RetReg, RecDynType));
break;
Modified: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp?rev=161391&r1=161390&r2=161391&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp Tue Aug 7 00:12:24 2012
@@ -670,14 +670,14 @@
const ObjCObjectPointerType *ReceiverT = 0;
QualType SupersType = E->getSuperType();
if (!SupersType.isNull()) {
- ReceiverT = cast<ObjCObjectPointerType>(SupersType.getTypePtr());
+ ReceiverT = cast<ObjCObjectPointerType>(SupersType);
} else {
const MemRegion *Receiver = getReceiverSVal().getAsRegion();
if (!Receiver)
return 0;
QualType DynType = getState()->getDynamicTypeInfo(Receiver).getType();
- ReceiverT = dyn_cast<ObjCObjectPointerType>(DynType.getTypePtr());
+ ReceiverT = dyn_cast<ObjCObjectPointerType>(DynType);
}
// Lookup the method implementation.
Modified: cfe/trunk/test/Analysis/inlining/ObjCDynTypePopagation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/ObjCDynTypePopagation.m?rev=161391&r1=161390&r2=161391&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/inlining/ObjCDynTypePopagation.m (original)
+++ cfe/trunk/test/Analysis/inlining/ObjCDynTypePopagation.m Tue Aug 7 00:12:24 2012
@@ -1,6 +1,10 @@
// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-ipa=dynamic -verify %s
typedef signed char BOOL;
+typedef struct objc_class *Class;
+typedef struct objc_object {
+ Class isa;
+} *id;
void clang_analyzer_eval(BOOL);
@@ -84,10 +88,20 @@
clang_analyzer_eval([p getZero] == 0); // expected-warning{{TRUE}}
}
-// Test implisit cast.
+// Test implicit cast.
+// Note, in this case, p could also be a subclass of MyParent.
+ (void) testCastFromId:(id) a {
MyParent *p = a;
clang_analyzer_eval([p getZero] == 0); // expected-warning{{TRUE}}
}
+ at end
- at end
\ No newline at end of file
+// TODO: Would be nice to handle the case of dynamically obtained class info
+// as well. We need a MemRegion for class types for this.
+int testDynamicClass(BOOL coin) {
+ Class AllocClass = (coin ? [NSObject class] : [MyClass class]);
+ id x = [[AllocClass alloc] init];
+ if (coin)
+ return [x getZero];
+ return 1;
+}
More information about the cfe-commits
mailing list