[cfe-commits] r161365 - /cfe/trunk/test/Analysis/inlining/ObjCImproperDynamictallyDetectableCast.m
Anna Zaks
ganna at apple.com
Mon Aug 6 16:58:16 PDT 2012
Author: zaks
Date: Mon Aug 6 18:58:16 2012
New Revision: 161365
URL: http://llvm.org/viewvc/llvm-project?rev=161365&view=rev
Log:
[analyzer] DynTypes: Add a test for improper cast performed by user.
Dynamic type inference does the right thing in this case. However, as
Jordan suggested, it would be nice to add a warning here as well.
Added:
cfe/trunk/test/Analysis/inlining/ObjCImproperDynamictallyDetectableCast.m
Added: cfe/trunk/test/Analysis/inlining/ObjCImproperDynamictallyDetectableCast.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/ObjCImproperDynamictallyDetectableCast.m?rev=161365&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/inlining/ObjCImproperDynamictallyDetectableCast.m (added)
+++ cfe/trunk/test/Analysis/inlining/ObjCImproperDynamictallyDetectableCast.m Mon Aug 6 18:58:16 2012
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-ipa=dynamic -verify %s
+
+typedef signed char BOOL;
+ at protocol NSObject - (BOOL)isEqual:(id)object; @end
+ at interface NSObject <NSObject> {}
++(id)alloc;
+-(id)init;
++(id)new;
+-(id)autorelease;
+-(id)copy;
+- (Class)class;
+-(id)retain;
+ at end
+void clang_analyzer_eval(BOOL);
+
+ at interface SomeOtherClass : NSObject
+- (int)getZero;
+ at end
+ at implementation SomeOtherClass
+- (int)getZero { return 0; }
+ at end
+
+ at interface MyClass : NSObject
+- (int)getZero;
+ at end
+
+ at implementation MyClass
+- (int)getZero { return 1; }
+
+// TODO: Not only we should correctly determine that the type of o at runtime
+// is MyClass, but we should also warn about it.
++ (void) testCastToParent {
+ id a = [[self alloc] init];
+ SomeOtherClass *o = a;
+ clang_analyzer_eval([o getZero] == 0); // expected-warning{{FALSE}}
+}
+ at end
\ No newline at end of file
More information about the cfe-commits
mailing list