direct-ivar-assignment-in-annotated-functions.m revision a05d2741c40c71b59cf6d2f8bbc5d433a5d0e6de
1// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.osx.cocoa.DirectIvarAssignmentForAnnotatedFunctions -fobjc-default-synthesize-properties -verify -fblocks %s 2 3typedef signed char BOOL; 4@protocol NSObject - (BOOL)isEqual:(id)object; @end 5@interface NSObject <NSObject> {} 6+(id)alloc; 7-(id)init; 8-(id)autorelease; 9-(id)copy; 10-(id)retain; 11@end 12 13@interface MyClass; 14@end 15 16@interface AnnotatedClass :NSObject { 17} 18 - (void) someMethod: (MyClass*)In __attribute__((annotate("objc_no_direct_instance_variable_assignment"))); 19 - (void) someMethodNotAnnaotated: (MyClass*)In; 20@end 21 22 23@interface TestProperty :AnnotatedClass { 24 MyClass *_Z; 25 id _nonSynth; 26} 27 28 @property (assign, nonatomic) MyClass* A; // explicitely synthesized, not implemented, non-default ivar name 29 30 @property (assign) MyClass* X; // automatically synthesized, not implemented 31 32 @property (assign, nonatomic) MyClass* Y; // automatically synthesized, implemented 33 34 @property (assign, nonatomic) MyClass* Z; // non synthesized ivar, implemented setter 35 @property (readonly) id nonSynth; // non synthesized, explicitly implemented to return ivar with expected name 36 @end 37 38@implementation TestProperty 39 @synthesize A = __A; 40 41 - (void) someMethod: (MyClass*)In { 42 (__A) = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}} 43 _X = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}} 44 _Y = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}} 45 _Z = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}} 46 _nonSynth = 0; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}} 47 } 48 - (void) someMethodNotAnnaotated: (MyClass*)In { 49 (__A) = In; 50 _X = In; // no-warning 51 _Y = In; // no-warning 52 _Z = In; // no-warning 53 _nonSynth = 0; // no-warning 54 } 55 56@end