diff options
author | Anna Zaks <ganna@apple.com> | 2012-08-06 23:58:16 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-08-06 23:58:16 +0000 |
commit | 0a5e1b840aaed19a36ebf19c38e34e669090a27e (patch) | |
tree | a270ddd5ec5a96e0e9a284fd5ce0ae99439c2b7b /clang/test | |
parent | 14f1aa70a9fae2e57f1eb91b6769cd92dc6dc0db (diff) | |
download | bcm5719-llvm-0a5e1b840aaed19a36ebf19c38e34e669090a27e.tar.gz bcm5719-llvm-0a5e1b840aaed19a36ebf19c38e34e669090a27e.zip |
[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.
llvm-svn: 161365
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Analysis/inlining/ObjCImproperDynamictallyDetectableCast.m | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/clang/test/Analysis/inlining/ObjCImproperDynamictallyDetectableCast.m b/clang/test/Analysis/inlining/ObjCImproperDynamictallyDetectableCast.m new file mode 100644 index 00000000000..b43304d5f44 --- /dev/null +++ b/clang/test/Analysis/inlining/ObjCImproperDynamictallyDetectableCast.m @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-ipa=dynamic -verify %s + +typedef signed char BOOL; +@protocol NSObject - (BOOL)isEqual:(id)object; @end +@interface NSObject <NSObject> {} ++(id)alloc; +-(id)init; ++(id)new; +-(id)autorelease; +-(id)copy; +- (Class)class; +-(id)retain; +@end +void clang_analyzer_eval(BOOL); + +@interface SomeOtherClass : NSObject +- (int)getZero; +@end +@implementation SomeOtherClass +- (int)getZero { return 0; } +@end + +@interface MyClass : NSObject +- (int)getZero; +@end + +@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}} +} +@end
\ No newline at end of file |