aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-06-24 18:25:34 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-06-24 18:25:34 +0000
commit921c14322977253a60dcb171f45e468c95fe41f8 (patch)
treeb85c224856580bdeb5720b0e5514e75b1c51421a /test
parentf58de90e209eac7159a52e75dcd6e99b3a6311a6 (diff)
objc-arc: Check on a variety of unsafe assignment of retained
objects. // rdar://9495837 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133806 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/SemaObjC/arc-unsafe-assigns.m41
-rw-r--r--test/SemaObjC/arc.m4
2 files changed, 43 insertions, 2 deletions
diff --git a/test/SemaObjC/arc-unsafe-assigns.m b/test/SemaObjC/arc-unsafe-assigns.m
new file mode 100644
index 0000000000..be8f90295e
--- /dev/null
+++ b/test/SemaObjC/arc-unsafe-assigns.m
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify %s
+// rdar://9495837
+
+@interface Foo {
+ __unsafe_unretained id unsafe_ivar;
+}
+
+@property (assign,nonatomic) id unsafe_prop;
+
+- (id)init;
++ (id)new;
++ (id)alloc;
+
+-(void)Meth;
+@end
+
+@implementation Foo
+@synthesize unsafe_prop;
+-(id)init { return self; }
++(id)new { return 0; }
++(id)alloc { return 0; }
+
+-(void)Meth {
+ self.unsafe_prop = [Foo new]; // expected-warning {{assigning retained object to unsafe property}}
+ self->unsafe_ivar = [Foo new]; // expected-warning {{assigning retained object to unsafe_unretained}}
+ self.unsafe_prop = [[Foo alloc] init]; // expected-warning {{assigning retained object to unsafe property}}
+ self->unsafe_ivar = [[Foo alloc] init]; // expected-warning {{assigning retained object to unsafe_unretained}}
+
+ __unsafe_unretained id unsafe_var;
+ unsafe_var = [Foo new]; // expected-warning {{assigning retained object to unsafe_unretained}}
+ unsafe_var = [[Foo alloc] init]; // expected-warning {{assigning retained object to unsafe_unretained}}
+}
+@end
+
+void bar(Foo *f) {
+ f.unsafe_prop = [Foo new]; // expected-warning {{assigning retained object to unsafe property}}
+
+ __unsafe_unretained id unsafe_var;
+ unsafe_var = [Foo new]; // expected-warning {{assigning retained object to unsafe_unretained}}
+ unsafe_var = [[Foo alloc] init]; // expected-warning {{assigning retained object to unsafe_unretained}}
+}
diff --git a/test/SemaObjC/arc.m b/test/SemaObjC/arc.m
index 4877930ea0..3a548e084a 100644
--- a/test/SemaObjC/arc.m
+++ b/test/SemaObjC/arc.m
@@ -518,12 +518,12 @@ typedef struct Bark Bark;
// rdar://9495837
@interface Test30
-- (id) new;
++ (id) new;
- (void)Meth;
@end
@implementation Test30
-- (id) new { return 0; }
++ (id) new { return 0; }
- (void) Meth {
__weak id x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}}
id __unsafe_unretained u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}}