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