blob: 56d9bc10f9797699dd28f9924a739c1c4aa730e0 [file] [log] [blame]
Fariborz Jahanian878f8502012-04-04 20:05:25 +00001// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -Wreceiver-is-weak -verify %s
2// rdar://10225276
3
4@interface Test0
5- (void) setBlock: (void(^)(void)) block;
6- (void) addBlock: (void(^)(void)) block;
7- (void) actNow;
8@end
9
10void test0(Test0 *x) {
11 __weak Test0 *weakx = x;
12 [x addBlock: ^{ [weakx actNow]; }]; // expected-warning {{weak receiver may be unpredictably null in ARC mode}}
13 [x setBlock: ^{ [weakx actNow]; }]; // expected-warning {{weak receiver may be unpredictably null in ARC mode}}
14 x.block = ^{ [weakx actNow]; }; // expected-warning {{weak receiver may be unpredictably null in ARC mode}}
15
16 [weakx addBlock: ^{ [x actNow]; }]; // expected-warning {{weak receiver may be unpredictably null in ARC mode}}
17 [weakx setBlock: ^{ [x actNow]; }]; // expected-warning {{weak receiver may be unpredictably null in ARC mode}}
Fariborz Jahanian31170392012-06-04 19:16:34 +000018 weakx.block = ^{ [x actNow]; }; // expected-warning {{weak receiver may be unpredictably null in ARC mode}}
Fariborz Jahanian878f8502012-04-04 20:05:25 +000019}
Fariborz Jahanian289677d2012-04-19 21:44:57 +000020
21@interface Test
22{
23 __weak Test* weak_prop;
24}
25- (void) Meth;
Fariborz Jahanian98795562012-04-19 23:49:39 +000026@property __weak Test* weak_prop; // expected-note {{property declared here}}
27@property (weak, atomic) id weak_atomic_prop; // expected-note {{property declared here}}
28- (__weak id) P; // expected-note {{method 'P' declared here}}
Fariborz Jahanian289677d2012-04-19 21:44:57 +000029@end
30
31@implementation Test
32- (void) Meth {
Fariborz Jahanian98795562012-04-19 23:49:39 +000033 if (self.weak_prop) {
Fariborz Jahanian289677d2012-04-19 21:44:57 +000034 self.weak_prop = 0;
35 }
Fariborz Jahanian98795562012-04-19 23:49:39 +000036 if (self.weak_atomic_prop) {
Fariborz Jahanian289677d2012-04-19 21:44:57 +000037 self.weak_atomic_prop = 0;
38 }
39 [self.weak_prop Meth]; // expected-warning {{weak property may be unpredictably null in ARC mode}}
Fariborz Jahanian98795562012-04-19 23:49:39 +000040 id pi = self.P;
Fariborz Jahanian289677d2012-04-19 21:44:57 +000041
42 [self.weak_atomic_prop Meth]; // expected-warning {{weak property may be unpredictably null in ARC mode}}
43
44 [self.P Meth]; // expected-warning {{weak implicit property may be unpredictably null in ARC mode}}
45}
46
47- (__weak id) P { return 0; }
48@dynamic weak_prop, weak_atomic_prop;
49@end
50
Fariborz Jahanian31170392012-06-04 19:16:34 +000051
52@interface MyClass {
53 __weak MyClass *_parent;
54}
55@property (weak) MyClass *parent; // expected-note 2 {{property declared here}}
56@end
57
58@implementation MyClass
59@synthesize parent = _parent;
60
61- (void)doSomething
62{
63 [[self parent] doSomething]; // expected-warning {{weak property may be unpredictably null in ARC mode}}
64
65 (void)self.parent.doSomething; // expected-warning {{weak property may be unpredictably null in ARC mode}}
66}
67
68@end