atomic-property-synthesis-rules.m
17.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
/*
Conditions for warning:
1. the property is atomic
2. the current @implementation contains an @synthesize for the property
3. the current @implementation contains a hand-written setter XOR getter
4. the property is read-write
Cases marked WARN should warn one the following:
warning: Atomic property 'x' has a synthesized setter and a
manually-implemented getter, which may break atomicity.
warning: Atomic property 'x' has a synthesized getter and a
manually-implemented setter, which may break atomicity.
Cases not marked WARN only satisfy the indicated subset
of the conditions required to warn.
There should be 8 warnings.
*/
@interface Foo
{
/* 12 4 */ int GetSet;
/* WARN */ int Get;
/* WARN */ int Set;
/* 12 4 */ int None;
/* 2 4 */ int GetSet_Nonatomic;
/* 234 */ int Get_Nonatomic;
/* 234 */ int Set_Nonatomic;
/* 2 4 */ int None_Nonatomic;
/* 12 */ int GetSet_ReadOnly;
/* 123 */ int Get_ReadOnly;
/* 123 */ int Set_ReadOnly;
/* 12 */ int None_ReadOnly;
/* 2 */ int GetSet_Nonatomic_ReadOnly;
/* 23 */ int Get_Nonatomic_ReadOnly;
/* 23 */ int Set_Nonatomic_ReadOnly;
/* 2 */ int None_Nonatomic_ReadOnly;
/* 12 4 */ int GetSet_ReadWriteInExt;
/* WARN */ int Get_ReadWriteInExt;
/* WARN */ int Set_ReadWriteInExt;
/* 12 4 */ int None_ReadWriteInExt;
/* 2 4 */ int GetSet_Nonatomic_ReadWriteInExt;
/* 234 */ int Get_Nonatomic_ReadWriteInExt;
/* 234 */ int Set_Nonatomic_ReadWriteInExt;
/* 2 4 */ int None_Nonatomic_ReadWriteInExt;
/* 12 4 */ int GetSet_LateSynthesize;
/* WARN */ int Get_LateSynthesize;
/* WARN */ int Set_LateSynthesize;
/* 12 4 */ int None_LateSynthesize;
/* 2 4 */ int GetSet_Nonatomic_LateSynthesize;
/* 234 */ int Get_Nonatomic_LateSynthesize;
/* 234 */ int Set_Nonatomic_LateSynthesize;
/* 2 4 */ int None_Nonatomic_LateSynthesize;
/* 12 */ int GetSet_ReadOnly_LateSynthesize;
/* 123 */ int Get_ReadOnly_LateSynthesize;
/* 123 */ int Set_ReadOnly_LateSynthesize;
/* 12 */ int None_ReadOnly_LateSynthesize;
/* 2 */ int GetSet_Nonatomic_ReadOnly_LateSynthesize;
/* 23 */ int Get_Nonatomic_ReadOnly_LateSynthesize;
/* 23 */ int Set_Nonatomic_ReadOnly_LateSynthesize;
/* 2 */ int None_Nonatomic_ReadOnly_LateSynthesize;
/* 12 4 */ int GetSet_ReadWriteInExt_LateSynthesize;
/* WARN */ int Get_ReadWriteInExt_LateSynthesize;
/* WARN */ int Set_ReadWriteInExt_LateSynthesize;
/* 12 4 */ int None_ReadWriteInExt_LateSynthesize;
/* 2 4 */ int GetSet_Nonatomic_ReadWriteInExt_LateSynthesize;
/* 234 */ int Get_Nonatomic_ReadWriteInExt_LateSynthesize;
/* 234 */ int Set_Nonatomic_ReadWriteInExt_LateSynthesize;
/* 2 4 */ int None_Nonatomic_ReadWriteInExt_LateSynthesize;
/* 1 4 */ int GetSet_NoSynthesize;
/* 1 34 */ int Get_NoSynthesize;
/* 1 34 */ int Set_NoSynthesize;
/* 1 4 */ int None_NoSynthesize;
/* 4 */ int GetSet_Nonatomic_NoSynthesize;
/* 34 */ int Get_Nonatomic_NoSynthesize;
/* 34 */ int Set_Nonatomic_NoSynthesize;
/* 4 */ int None_Nonatomic_NoSynthesize;
/* 1 */ int GetSet_ReadOnly_NoSynthesize;
/* 1 3 */ int Get_ReadOnly_NoSynthesize;
/* 1 3 */ int Set_ReadOnly_NoSynthesize;
/* 1 */ int None_ReadOnly_NoSynthesize;
/* */ int GetSet_Nonatomic_ReadOnly_NoSynthesize;
/* 3 */ int Get_Nonatomic_ReadOnly_NoSynthesize;
/* 3 */ int Set_Nonatomic_ReadOnly_NoSynthesize;
/* */ int None_Nonatomic_ReadOnly_NoSynthesize;
/* 1 4 */ int GetSet_ReadWriteInExt_NoSynthesize;
/* 1 34 */ int Get_ReadWriteInExt_NoSynthesize;
/* 1 34 */ int Set_ReadWriteInExt_NoSynthesize;
/* 1 4 */ int None_ReadWriteInExt_NoSynthesize;
/* 4 */ int GetSet_Nonatomic_ReadWriteInExt_NoSynthesize;
/* 34 */ int Get_Nonatomic_ReadWriteInExt_NoSynthesize;
/* 34 */ int Set_Nonatomic_ReadWriteInExt_NoSynthesize;
/* 4 */ int None_Nonatomic_ReadWriteInExt_NoSynthesize;
}
// read-write - might warn
@property int GetSet;
@property int Get; // expected-note {{property declared here}} \
// expected-note {{setter and getter must both be synthesized}}
@property int Set; // expected-note {{property declared here}} \
// expected-note {{setter and getter must both be synthesized}}
@property int None;
@property(nonatomic) int GetSet_Nonatomic;
@property(nonatomic) int Get_Nonatomic;
@property(nonatomic) int Set_Nonatomic;
@property(nonatomic) int None_Nonatomic;
// read-only - must not warn
@property(readonly) int GetSet_ReadOnly;
@property(readonly) int Get_ReadOnly;
@property(readonly) int Set_ReadOnly;
@property(readonly) int None_ReadOnly;
@property(nonatomic,readonly) int GetSet_Nonatomic_ReadOnly;
@property(nonatomic,readonly) int Get_Nonatomic_ReadOnly;
@property(nonatomic,readonly) int Set_Nonatomic_ReadOnly;
@property(nonatomic,readonly) int None_Nonatomic_ReadOnly;
// read-only in class, read-write in class extension - might warn
@property(readonly) int GetSet_ReadWriteInExt;
@property(readonly) int Get_ReadWriteInExt;
@property(readonly) int Set_ReadWriteInExt;
@property(readonly) int None_ReadWriteInExt;
@property(nonatomic,readonly) int GetSet_Nonatomic_ReadWriteInExt;
@property(nonatomic,readonly) int Get_Nonatomic_ReadWriteInExt;
@property(nonatomic,readonly) int Set_Nonatomic_ReadWriteInExt;
@property(nonatomic,readonly) int None_Nonatomic_ReadWriteInExt;
// same as above, but @synthesize follows the hand-written methods - might warn
@property int GetSet_LateSynthesize;
@property int Get_LateSynthesize; // expected-note {{property declared here}} \
// expected-note {{setter and getter must both be synthesized}}
@property int Set_LateSynthesize; // expected-note {{property declared here}} \
// expected-note {{setter and getter must both be synthesized}}
@property int None_LateSynthesize;
@property(nonatomic) int GetSet_Nonatomic_LateSynthesize;
@property(nonatomic) int Get_Nonatomic_LateSynthesize;
@property(nonatomic) int Set_Nonatomic_LateSynthesize;
@property(nonatomic) int None_Nonatomic_LateSynthesize;
@property(readonly) int GetSet_ReadOnly_LateSynthesize;
@property(readonly) int Get_ReadOnly_LateSynthesize;
@property(readonly) int Set_ReadOnly_LateSynthesize;
@property(readonly) int None_ReadOnly_LateSynthesize;
@property(nonatomic,readonly) int GetSet_Nonatomic_ReadOnly_LateSynthesize;
@property(nonatomic,readonly) int Get_Nonatomic_ReadOnly_LateSynthesize;
@property(nonatomic,readonly) int Set_Nonatomic_ReadOnly_LateSynthesize;
@property(nonatomic,readonly) int None_Nonatomic_ReadOnly_LateSynthesize;
@property(readonly) int GetSet_ReadWriteInExt_LateSynthesize;
@property(readonly) int Get_ReadWriteInExt_LateSynthesize;
@property(readonly) int Set_ReadWriteInExt_LateSynthesize;
@property(readonly) int None_ReadWriteInExt_LateSynthesize;
@property(nonatomic,readonly) int GetSet_Nonatomic_ReadWriteInExt_LateSynthesize;
@property(nonatomic,readonly) int Get_Nonatomic_ReadWriteInExt_LateSynthesize;
@property(nonatomic,readonly) int Set_Nonatomic_ReadWriteInExt_LateSynthesize;
@property(nonatomic,readonly) int None_Nonatomic_ReadWriteInExt_LateSynthesize;
// same as above, but with no @synthesize - must not warn
@property int GetSet_NoSynthesize;
@property int Get_NoSynthesize;
@property int Set_NoSynthesize;
@property int None_NoSynthesize;
@property(nonatomic) int GetSet_Nonatomic_NoSynthesize;
@property(nonatomic) int Get_Nonatomic_NoSynthesize;
@property(nonatomic) int Set_Nonatomic_NoSynthesize;
@property(nonatomic) int None_Nonatomic_NoSynthesize;
@property(readonly) int GetSet_ReadOnly_NoSynthesize;
@property(readonly) int Get_ReadOnly_NoSynthesize;
@property(readonly) int Set_ReadOnly_NoSynthesize;
@property(readonly) int None_ReadOnly_NoSynthesize;
@property(nonatomic,readonly) int GetSet_Nonatomic_ReadOnly_NoSynthesize;
@property(nonatomic,readonly) int Get_Nonatomic_ReadOnly_NoSynthesize;
@property(nonatomic,readonly) int Set_Nonatomic_ReadOnly_NoSynthesize;
@property(nonatomic,readonly) int None_Nonatomic_ReadOnly_NoSynthesize;
@property(readonly) int GetSet_ReadWriteInExt_NoSynthesize;
@property(readonly) int Get_ReadWriteInExt_NoSynthesize;
@property(readonly) int Set_ReadWriteInExt_NoSynthesize;
@property(readonly) int None_ReadWriteInExt_NoSynthesize;
@property(nonatomic,readonly) int GetSet_Nonatomic_ReadWriteInExt_NoSynthesize;
@property(nonatomic,readonly) int Get_Nonatomic_ReadWriteInExt_NoSynthesize;
@property(nonatomic,readonly) int Set_Nonatomic_ReadWriteInExt_NoSynthesize;
@property(nonatomic,readonly) int None_Nonatomic_ReadWriteInExt_NoSynthesize;
@end
@interface Foo ()
@property(readwrite) int GetSet_ReadWriteInExt;
@property(readwrite) int Get_ReadWriteInExt; // expected-note {{property declared here}} \
// expected-note {{setter and getter must both be synthesized}}
@property(readwrite) int Set_ReadWriteInExt; // expected-note {{property declared here}} \
// expected-note {{setter and getter must both be synthesized}}
@property(readwrite) int None_ReadWriteInExt;
@property(nonatomic,readwrite) int GetSet_Nonatomic_ReadWriteInExt;
@property(nonatomic,readwrite) int Get_Nonatomic_ReadWriteInExt;
@property(nonatomic,readwrite) int Set_Nonatomic_ReadWriteInExt;
@property(nonatomic,readwrite) int None_Nonatomic_ReadWriteInExt;
@property(readwrite) int GetSet_ReadWriteInExt_LateSynthesize;
@property(readwrite) int Get_ReadWriteInExt_LateSynthesize; // expected-note {{property declared here}} \
// expected-note {{setter and getter must both be synthesized}}
@property(readwrite) int Set_ReadWriteInExt_LateSynthesize; // expected-note {{property declared here}} \
// expected-note {{setter and getter must both be synthesized}}
@property(readwrite) int None_ReadWriteInExt_LateSynthesize;
@property(nonatomic,readwrite) int GetSet_Nonatomic_ReadWriteInExt_LateSynthesize;
@property(nonatomic,readwrite) int Get_Nonatomic_ReadWriteInExt_LateSynthesize;
@property(nonatomic,readwrite) int Set_Nonatomic_ReadWriteInExt_LateSynthesize;
@property(nonatomic,readwrite) int None_Nonatomic_ReadWriteInExt_LateSynthesize;
@property(readwrite) int GetSet_ReadWriteInExt_NoSynthesize;
@property(readwrite) int Get_ReadWriteInExt_NoSynthesize;
@property(readwrite) int Set_ReadWriteInExt_NoSynthesize;
@property(readwrite) int None_ReadWriteInExt_NoSynthesize;
@property(nonatomic,readwrite) int GetSet_Nonatomic_ReadWriteInExt_NoSynthesize;
@property(nonatomic,readwrite) int Get_Nonatomic_ReadWriteInExt_NoSynthesize;
@property(nonatomic,readwrite) int Set_Nonatomic_ReadWriteInExt_NoSynthesize;
@property(nonatomic,readwrite) int None_Nonatomic_ReadWriteInExt_NoSynthesize;
@end
@implementation Foo
@synthesize GetSet, Get, Set, None, GetSet_Nonatomic, Get_Nonatomic, Set_Nonatomic, None_Nonatomic;
@synthesize GetSet_ReadOnly, Get_ReadOnly, Set_ReadOnly, None_ReadOnly, GetSet_Nonatomic_ReadOnly, Get_Nonatomic_ReadOnly, Set_Nonatomic_ReadOnly, None_Nonatomic_ReadOnly;
@synthesize GetSet_ReadWriteInExt, Get_ReadWriteInExt, Set_ReadWriteInExt, None_ReadWriteInExt, GetSet_Nonatomic_ReadWriteInExt, Get_Nonatomic_ReadWriteInExt, Set_Nonatomic_ReadWriteInExt, None_Nonatomic_ReadWriteInExt;
#define GET(x) \
-(int) x { return self->x; }
#define SET(x) \
-(void) set##x:(int)value { self->x = value; }
GET(GetSet)
SET(GetSet)
GET(Get) // expected-warning {{writable atomic property 'Get' cannot pair a synthesized setter with a user defined getter}}
SET(Set) // expected-warning {{writable atomic property 'Set' cannot pair a synthesized getter with a user defined setter}}
GET(GetSet_Nonatomic)
SET(GetSet_Nonatomic)
GET(Get_Nonatomic)
SET(Set_Nonatomic)
GET(GetSet_ReadOnly)
SET(GetSet_ReadOnly)
GET(Get_ReadOnly)
SET(Set_ReadOnly)
GET(GetSet_Nonatomic_ReadOnly)
SET(GetSet_Nonatomic_ReadOnly)
GET(Get_Nonatomic_ReadOnly)
SET(Set_Nonatomic_ReadOnly)
GET(GetSet_ReadWriteInExt)
SET(GetSet_ReadWriteInExt)
GET(Get_ReadWriteInExt) // expected-warning {{writable atomic property 'Get_ReadWriteInExt' cannot pair a synthesized setter with a user defined getter}}
SET(Set_ReadWriteInExt) // expected-warning {{writable atomic property 'Set_ReadWriteInExt' cannot pair a synthesized getter with a user defined setter}}
GET(GetSet_Nonatomic_ReadWriteInExt)
SET(GetSet_Nonatomic_ReadWriteInExt)
GET(Get_Nonatomic_ReadWriteInExt)
SET(Set_Nonatomic_ReadWriteInExt)
GET(GetSet_LateSynthesize)
SET(GetSet_LateSynthesize)
GET(Get_LateSynthesize) // expected-warning {{writable atomic property 'Get_LateSynthesize' cannot pair a synthesized setter with a user defined getter}}
SET(Set_LateSynthesize) // expected-warning {{writable atomic property 'Set_LateSynthesize' cannot pair a synthesized getter with a user defined setter}}
GET(GetSet_Nonatomic_LateSynthesize)
SET(GetSet_Nonatomic_LateSynthesize)
GET(Get_Nonatomic_LateSynthesize)
SET(Set_Nonatomic_LateSynthesize)
GET(GetSet_ReadOnly_LateSynthesize)
SET(GetSet_ReadOnly_LateSynthesize)
GET(Get_ReadOnly_LateSynthesize)
SET(Set_ReadOnly_LateSynthesize)
GET(GetSet_Nonatomic_ReadOnly_LateSynthesize)
SET(GetSet_Nonatomic_ReadOnly_LateSynthesize)
GET(Get_Nonatomic_ReadOnly_LateSynthesize)
SET(Set_Nonatomic_ReadOnly_LateSynthesize)
GET(GetSet_ReadWriteInExt_LateSynthesize)
SET(GetSet_ReadWriteInExt_LateSynthesize)
GET(Get_ReadWriteInExt_LateSynthesize) // expected-warning {{writable atomic property 'Get_ReadWriteInExt_LateSynthesize' cannot pair a synthesized setter with a user defined getter}}
SET(Set_ReadWriteInExt_LateSynthesize) // expected-warning {{writable atomic property 'Set_ReadWriteInExt_LateSynthesize' cannot pair a synthesized getter with a user defined setter}}
GET(GetSet_Nonatomic_ReadWriteInExt_LateSynthesize)
SET(GetSet_Nonatomic_ReadWriteInExt_LateSynthesize)
GET(Get_Nonatomic_ReadWriteInExt_LateSynthesize)
SET(Set_Nonatomic_ReadWriteInExt_LateSynthesize)
GET(GetSet_NoSynthesize)
SET(GetSet_NoSynthesize)
GET(Get_NoSynthesize)
SET(Set_NoSynthesize)
GET(GetSet_Nonatomic_NoSynthesize)
SET(GetSet_Nonatomic_NoSynthesize)
GET(Get_Nonatomic_NoSynthesize)
SET(Set_Nonatomic_NoSynthesize)
GET(GetSet_ReadOnly_NoSynthesize)
SET(GetSet_ReadOnly_NoSynthesize)
GET(Get_ReadOnly_NoSynthesize)
SET(Set_ReadOnly_NoSynthesize)
GET(GetSet_Nonatomic_ReadOnly_NoSynthesize)
SET(GetSet_Nonatomic_ReadOnly_NoSynthesize)
GET(Get_Nonatomic_ReadOnly_NoSynthesize)
SET(Set_Nonatomic_ReadOnly_NoSynthesize)
GET(GetSet_ReadWriteInExt_NoSynthesize)
SET(GetSet_ReadWriteInExt_NoSynthesize)
GET(Get_ReadWriteInExt_NoSynthesize)
SET(Set_ReadWriteInExt_NoSynthesize)
GET(GetSet_Nonatomic_ReadWriteInExt_NoSynthesize)
SET(GetSet_Nonatomic_ReadWriteInExt_NoSynthesize)
GET(Get_Nonatomic_ReadWriteInExt_NoSynthesize)
SET(Set_Nonatomic_ReadWriteInExt_NoSynthesize)
// late synthesize - follows getter/setter implementations
@synthesize GetSet_LateSynthesize, Get_LateSynthesize, Set_LateSynthesize, None_LateSynthesize, GetSet_Nonatomic_LateSynthesize, Get_Nonatomic_LateSynthesize, Set_Nonatomic_LateSynthesize, None_Nonatomic_LateSynthesize;
@synthesize GetSet_ReadOnly_LateSynthesize, Get_ReadOnly_LateSynthesize, Set_ReadOnly_LateSynthesize, None_ReadOnly_LateSynthesize, GetSet_Nonatomic_ReadOnly_LateSynthesize, Get_Nonatomic_ReadOnly_LateSynthesize, Set_Nonatomic_ReadOnly_LateSynthesize, None_Nonatomic_ReadOnly_LateSynthesize;
@synthesize GetSet_ReadWriteInExt_LateSynthesize, Get_ReadWriteInExt_LateSynthesize, Set_ReadWriteInExt_LateSynthesize, None_ReadWriteInExt_LateSynthesize, GetSet_Nonatomic_ReadWriteInExt_LateSynthesize, Get_Nonatomic_ReadWriteInExt_LateSynthesize, Set_Nonatomic_ReadWriteInExt_LateSynthesize, None_Nonatomic_ReadWriteInExt_LateSynthesize;
// no synthesize - use dynamic instead
@dynamic GetSet_NoSynthesize, Get_NoSynthesize, Set_NoSynthesize, None_NoSynthesize, GetSet_Nonatomic_NoSynthesize, Get_Nonatomic_NoSynthesize, Set_Nonatomic_NoSynthesize, None_Nonatomic_NoSynthesize;
@dynamic GetSet_ReadOnly_NoSynthesize, Get_ReadOnly_NoSynthesize, Set_ReadOnly_NoSynthesize, None_ReadOnly_NoSynthesize, GetSet_Nonatomic_ReadOnly_NoSynthesize, Get_Nonatomic_ReadOnly_NoSynthesize, Set_Nonatomic_ReadOnly_NoSynthesize, None_Nonatomic_ReadOnly_NoSynthesize;
@dynamic GetSet_ReadWriteInExt_NoSynthesize, Get_ReadWriteInExt_NoSynthesize, Set_ReadWriteInExt_NoSynthesize, None_ReadWriteInExt_NoSynthesize, GetSet_Nonatomic_ReadWriteInExt_NoSynthesize, Get_Nonatomic_ReadWriteInExt_NoSynthesize, Set_Nonatomic_ReadWriteInExt_NoSynthesize, None_Nonatomic_ReadWriteInExt_NoSynthesize;
@end
/*
// the following method should cause a warning along the lines of
// :warning: Atomic property 'x' cannot pair a synthesized setter/getter with a manually implemented setter/getter
- (void) setX: (int) aValue
{
x = aValue;
}
// no warning 'cause this is nonatomic
- (void) setY: (int) aValue
{
y = aValue;
}
// the following method should cause a warning along the lines of
// :warning: Atomic property 'x' cannot pair a synthesized setter/getter with a manually implemented setter/getter
- (int) j
{
return j;
}
// no warning 'cause this is nonatomic
- (int) k
{
return k;
}
@end
*/
int main (int argc, const char * argv[]) {
return 0;
}