annotate clang/test/Analysis/objc-properties.m @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.osx.cocoa.DirectIvarAssignment -verify -fblocks %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 typedef signed char BOOL;
anatofuz
parents:
diff changeset
4 @protocol NSObject - (BOOL)isEqual:(id)object; @end
anatofuz
parents:
diff changeset
5 @interface NSObject <NSObject> {}
anatofuz
parents:
diff changeset
6 +(id)alloc;
anatofuz
parents:
diff changeset
7 -(id)init;
anatofuz
parents:
diff changeset
8 -(id)autorelease;
anatofuz
parents:
diff changeset
9 -(id)copy;
anatofuz
parents:
diff changeset
10 -(id)retain;
anatofuz
parents:
diff changeset
11 @end
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 @interface MyClass;
anatofuz
parents:
diff changeset
14 @end
anatofuz
parents:
diff changeset
15 @interface TestProperty :NSObject {
anatofuz
parents:
diff changeset
16 MyClass *_Z;
anatofuz
parents:
diff changeset
17 id _nonSynth;
anatofuz
parents:
diff changeset
18 }
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 @property (assign, nonatomic) MyClass* A; // explicitly synthesized, not implemented, non-default ivar name
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 @property (assign) MyClass* X; // automatically synthesized, not implemented
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 @property (assign, nonatomic) MyClass* Y; // automatically synthesized, implemented
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 @property (assign, nonatomic) MyClass* Z; // non-synthesized ivar, implemented setter
anatofuz
parents:
diff changeset
27 @property (readonly) id nonSynth; // non-synthesized, explicitly implemented to return ivar with expected name
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 - (id) initWithPtr:(MyClass*) value;
anatofuz
parents:
diff changeset
30 - (id) myInitWithPtr:(MyClass*) value;
anatofuz
parents:
diff changeset
31 - (void) someMethod: (MyClass*)In;
anatofuz
parents:
diff changeset
32 @end
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 @implementation TestProperty
anatofuz
parents:
diff changeset
35 @synthesize A = __A;
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 - (id) initWithPtr: (MyClass*) value {
anatofuz
parents:
diff changeset
38 _Y = value; // no-warning
anatofuz
parents:
diff changeset
39 return self;
anatofuz
parents:
diff changeset
40 }
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 - (id) copyWithPtrY: (TestProperty*) value {
anatofuz
parents:
diff changeset
43 TestProperty *another = [[TestProperty alloc] init];
anatofuz
parents:
diff changeset
44 another->_Y = value->_Y; // no-warning
anatofuz
parents:
diff changeset
45 return another;
anatofuz
parents:
diff changeset
46 }
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 - (id) myInitWithPtr: (MyClass*) value {
anatofuz
parents:
diff changeset
49 _Y = value; // no-warning
anatofuz
parents:
diff changeset
50 return self;
anatofuz
parents:
diff changeset
51 }
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 - (void) setY:(MyClass*) NewValue {
anatofuz
parents:
diff changeset
54 _Y = NewValue; // no-warning
anatofuz
parents:
diff changeset
55 }
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 - (void) setZ:(MyClass*) NewValue {
anatofuz
parents:
diff changeset
58 _Z = NewValue; // no-warning
anatofuz
parents:
diff changeset
59 }
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 - (id)nonSynth {
anatofuz
parents:
diff changeset
62 return _nonSynth;
anatofuz
parents:
diff changeset
63 }
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 - (void) someMethod: (MyClass*)In {
anatofuz
parents:
diff changeset
66 (__A) = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
anatofuz
parents:
diff changeset
67 _X = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
anatofuz
parents:
diff changeset
68 _Y = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
anatofuz
parents:
diff changeset
69 _Z = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
anatofuz
parents:
diff changeset
70 _nonSynth = 0; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
anatofuz
parents:
diff changeset
71 }
anatofuz
parents:
diff changeset
72 @end