summaryrefslogtreecommitdiffstats
path: root/test/SemaObjC
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaObjC')
-rw-r--r--test/SemaObjC/Inputs/arc-system-header.h52
-rw-r--r--test/SemaObjC/arc-bridged-cast.m43
-rw-r--r--test/SemaObjC/arc-decls.m64
-rw-r--r--test/SemaObjC/arc-jump-block.m84
-rw-r--r--test/SemaObjC/arc-no-runtime.m15
-rw-r--r--test/SemaObjC/arc-non-pod-memaccess.m55
-rw-r--r--test/SemaObjC/arc-peformselector.m38
-rw-r--r--test/SemaObjC/arc-property-decl-attrs.m67
-rw-r--r--test/SemaObjC/arc-property-lifetime.m112
-rw-r--r--test/SemaObjC/arc-property.m48
-rw-r--r--test/SemaObjC/arc-system-header.m50
-rw-r--r--test/SemaObjC/arc-type-conversion.m77
-rw-r--r--test/SemaObjC/arc-unavailable-for-weakref.m47
-rw-r--r--test/SemaObjC/arc-unbridged-cast.m18
-rw-r--r--test/SemaObjC/arc-unsafe-assigns.m41
-rw-r--r--test/SemaObjC/arc-unsafe_unretained.m12
-rw-r--r--test/SemaObjC/arc.m628
-rw-r--r--test/SemaObjC/autoreleasepool.m22
-rw-r--r--test/SemaObjC/class-proto-1.m4
-rw-r--r--test/SemaObjC/class-unavail-warning.m2
-rw-r--r--test/SemaObjC/debugger-support.m14
-rw-r--r--test/SemaObjC/error-property-gc-attr.m4
-rw-r--r--test/SemaObjC/forward-class-1.m15
-rw-r--r--test/SemaObjC/ivar-ref-misuse.m5
-rw-r--r--test/SemaObjC/method-lookup-3.m16
-rw-r--r--test/SemaObjC/no-warning-unavail-unimp.m12
-rw-r--r--test/SemaObjC/property-10.m17
-rw-r--r--test/SemaObjC/property-inherited.m4
-rw-r--r--test/SemaObjC/property-ns-returns-not-retained-attr.m21
-rw-r--r--test/SemaObjC/related-result-type-inference.m2
-rw-r--r--test/SemaObjC/selector-3.m25
-rw-r--r--test/SemaObjC/self-declared-in-block.m15
-rw-r--r--test/SemaObjC/sizeof-interface.m2
-rw-r--r--test/SemaObjC/special-dep-unavail-warning.m10
-rw-r--r--test/SemaObjC/synthesized-ivar.m8
-rw-r--r--test/SemaObjC/typedef-class.m2
-rw-r--r--test/SemaObjC/undef-superclass-1.m6
-rw-r--r--test/SemaObjC/warn-retain-cycle.m91
-rw-r--r--test/SemaObjC/weak-property.m24
39 files changed, 1741 insertions, 31 deletions
diff --git a/test/SemaObjC/Inputs/arc-system-header.h b/test/SemaObjC/Inputs/arc-system-header.h
new file mode 100644
index 0000000..5012a2a
--- /dev/null
+++ b/test/SemaObjC/Inputs/arc-system-header.h
@@ -0,0 +1,52 @@
+static inline void *test0(id x) {
+ return x;
+}
+
+static inline void **test1(__strong id* x) {
+ return (void**) x;
+}
+
+
+
+
+
+struct Test3 {
+ id *field;
+};
+
+@interface Test4 {
+@public
+ id *field1;
+ __strong id *field2;
+}
+@end
+
+struct Test5 {
+ id field;
+};
+
+
+
+
+
+
+
+extern struct Test6 *const kMagicConstant;
+
+
+
+
+
+@interface Test7
+@property id *prop;
+@end
+
+
+
+
+
+
+
+static inline void *test8(id ptr) {
+ return (__bridge_retain void*) ptr;
+}
diff --git a/test/SemaObjC/arc-bridged-cast.m b/test/SemaObjC/arc-bridged-cast.m
new file mode 100644
index 0000000..e883406
--- /dev/null
+++ b/test/SemaObjC/arc-bridged-cast.m
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -fblocks -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fblocks %s
+
+typedef const void *CFTypeRef;
+typedef const struct __CFString *CFStringRef;
+
+@interface NSString
+@end
+
+CFTypeRef CFCreateSomething();
+CFStringRef CFCreateString();
+CFTypeRef CFGetSomething();
+CFStringRef CFGetString();
+
+id CreateSomething();
+NSString *CreateNSString();
+
+void from_cf() {
+ id obj1 = (__bridge_transfer id)CFCreateSomething();
+ id obj2 = (__bridge_transfer NSString*)CFCreateString();
+ (__bridge int*)CFCreateSomething(); // expected-error{{incompatible types casting 'CFTypeRef' (aka 'const void *') to 'int *' with a __bridge cast}}
+ id obj3 = (__bridge id)CFGetSomething();
+ id obj4 = (__bridge NSString*)CFGetString();
+}
+
+void to_cf(id obj) {
+ CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething();
+ CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString();
+ CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething();
+ CFStringRef cf4 = (__bridge CFStringRef)CreateNSString();
+
+ // rdar://problem/9629566 - temporary workaround
+ CFTypeRef cf5 = (__bridge_retain CFTypeRef)CreateSomething(); // expected-error {{unknown cast annotation __bridge_retain; did you mean __bridge_retained?}}
+}
+
+void fixits() {
+ id obj1 = (id)CFCreateSomething(); // expected-error{{cast of C pointer type 'CFTypeRef' (aka 'const void *') to Objective-C pointer type 'id' requires a bridged cast}} \
+ // expected-note{{use __bridge to convert directly (no change in ownership)}} \
+ // expected-note{{use __bridge_transfer to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}}
+ CFTypeRef cf1 = (CFTypeRef)CreateSomething(); // expected-error{{cast of Objective-C pointer type 'id' to C pointer type 'CFTypeRef' (aka 'const void *') requires a bridged cast}} \
+ // expected-note{{use __bridge to convert directly (no change in ownership)}} \
+ // expected-note{{use __bridge_retained to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
+}
diff --git a/test/SemaObjC/arc-decls.m b/test/SemaObjC/arc-decls.m
new file mode 100644
index 0000000..e713d23
--- /dev/null
+++ b/test/SemaObjC/arc-decls.m
@@ -0,0 +1,64 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-nonfragile-abi -verify %s
+
+// rdar://8843524
+
+struct A {
+ id x; // expected-error {{ARC forbids Objective-C objects in structs or unions}}
+};
+
+union u {
+ id u; // expected-error {{ARC forbids Objective-C objects in structs or unions}}
+};
+
+@interface I {
+ struct A a;
+ struct B {
+ id y[10][20]; // expected-error {{ARC forbids Objective-C objects in structs or unions}}
+ id z;
+ } b;
+
+ union u c;
+};
+@end
+
+struct S {
+ id __attribute__((objc_ownership(none))) i;
+ void * vp;
+ int i1;
+};
+
+// rdar://9046528
+
+@class NSError;
+
+__autoreleasing id X; // expected-error {{global variables cannot have __autoreleasing ownership}}
+__autoreleasing NSError *E; // expected-error {{global variables cannot have __autoreleasing ownership}}
+
+
+extern id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}}
+
+void func()
+{
+ id X;
+ static id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}}
+ extern id __autoreleasing E; // expected-error {{global variables cannot have __autoreleasing ownership}}
+
+}
+
+// rdar://9157348
+
+@interface J
+@property (retain) id newFoo; // expected-note {{property declared here}}
+@property (strong) id copyBar; // expected-note {{property declared here}}
+@property (copy) id allocBaz; // expected-note {{property declared here}}
+@property (copy, nonatomic) id new;
+@end
+
+@implementation J
+@synthesize newFoo; // expected-error {{property's synthesized getter follows Cocoa naming convention for returning}}
+@synthesize copyBar; // expected-error {{property's synthesized getter follows Cocoa naming convention for returning}}
+@synthesize allocBaz; // expected-error {{property's synthesized getter follows Cocoa naming convention for returning}}
+@synthesize new;
+- new {return 0; };
+@end
+
diff --git a/test/SemaObjC/arc-jump-block.m b/test/SemaObjC/arc-jump-block.m
new file mode 100644
index 0000000..1c7b21e
--- /dev/null
+++ b/test/SemaObjC/arc-jump-block.m
@@ -0,0 +1,84 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -fblocks -verify %s
+// rdar://9535237
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+
+typedef void (^dispatch_block_t)(void);
+
+void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
+
+extern __attribute__((visibility("default"))) struct dispatch_queue_s _dispatch_main_q;
+
+@interface SwitchBlockCrashAppDelegate
+- (void)pageLeft;
+- (void)pageRight;;
+@end
+
+@implementation SwitchBlockCrashAppDelegate
+
+- (void)choose:(int)button {
+ switch (button) {
+ case 0:
+ dispatch_async((&_dispatch_main_q), ^{ [self pageLeft]; }); // expected-note 3 {{jump enters lifetime of block which strongly captures a variable}}
+ break;
+ case 2: // expected-error {{switch case is in protected scope}}
+ dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; }); // expected-note 2 {{jump enters lifetime of block which strongly captures a variable}}
+ break;
+ case 3: // expected-error {{switch case is in protected scope}}
+ {
+ dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; });
+ break;
+ }
+ case 4: // expected-error {{switch case is in protected scope}}
+ break;
+ }
+
+ __block SwitchBlockCrashAppDelegate *captured_block_obj;
+ switch (button) {
+ case 10:
+ {
+ dispatch_async((&_dispatch_main_q), ^{ [self pageLeft]; });
+ break;
+ }
+ case 12:
+ if (button)
+ dispatch_async((&_dispatch_main_q), ^{ [captured_block_obj pageRight]; });
+ break;
+ case 13:
+ while (button)
+ dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; });
+ break;
+ case 14:
+ break;
+ }
+
+ switch (button) {
+ case 10:
+ {
+ dispatch_async((&_dispatch_main_q), ^{ [self pageLeft]; });
+ break;
+ }
+ case 12:
+ if (button)
+ dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; });
+ switch (button) {
+ case 0:
+ {
+ dispatch_async((&_dispatch_main_q), ^{ [self pageLeft]; });
+ break;
+ }
+ case 4:
+ break;
+ }
+ break;
+ case 13:
+ while (button)
+ dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; });
+ break;
+ case 14:
+ break;
+ }
+}
+- (void)pageLeft {}
+- (void)pageRight {}
+@end
diff --git a/test/SemaObjC/arc-no-runtime.m b/test/SemaObjC/arc-no-runtime.m
new file mode 100644
index 0000000..94299e2
--- /dev/null
+++ b/test/SemaObjC/arc-no-runtime.m
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fobjc-arc -fobjc-nonfragile-abi -verify %s
+
+// rdar://problem/9150784
+void test(void) {
+ __weak id x; // expected-error {{the current deployment target does not support automated __weak references}}
+}
+
+@interface A
+@property (weak) id testObjectWeakProperty; // expected-note {{declared here}}
+@end
+
+@implementation A
+// rdar://9605088
+@synthesize testObjectWeakProperty; // expected-error {{the current deployment target does not support automated __weak references}}
+@end
diff --git a/test/SemaObjC/arc-non-pod-memaccess.m b/test/SemaObjC/arc-non-pod-memaccess.m
new file mode 100644
index 0000000..c9a7751
--- /dev/null
+++ b/test/SemaObjC/arc-non-pod-memaccess.m
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify -fblocks -triple x86_64-apple-darwin10.0.0 %s
+// RUN: %clang_cc1 -x objective-c++ -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify -fblocks -triple x86_64-apple-darwin10.0.0 %s
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void *memset(void *, int, __SIZE_TYPE__);
+void *memmove(void *s1, const void *s2, __SIZE_TYPE__ n);
+void *memcpy(void *s1, const void *s2, __SIZE_TYPE__ n);
+
+#ifdef __cplusplus
+}
+#endif
+
+void test(id __strong *sip, id __weak *wip, id __autoreleasing *aip,
+ id __unsafe_unretained *uip, void *ptr) {
+ // All okay.
+ memset(sip, 0, 17);
+ memset(wip, 0, 17);
+ memset(aip, 0, 17);
+ memset(uip, 0, 17);
+
+ memcpy(sip, ptr, 17); // expected-warning{{destination for this 'memcpy' call is a pointer to ownership-qualified type}} \
+ // expected-note{{explicitly cast the pointer to silence this warning}}
+ memcpy(wip, ptr, 17); // expected-warning{{destination for this 'memcpy' call is a pointer to ownership-qualified type}} \
+ // expected-note{{explicitly cast the pointer to silence this warning}}
+ memcpy(aip, ptr, 17); // expected-warning{{destination for this 'memcpy' call is a pointer to ownership-qualified type}} \
+ // expected-note{{explicitly cast the pointer to silence this warning}}
+ memcpy(uip, ptr, 17);
+
+ memcpy(ptr, sip, 17); // expected-warning{{source of this 'memcpy' call is a pointer to ownership-qualified type}} \
+ // expected-note{{explicitly cast the pointer to silence this warning}}
+ memcpy(ptr, wip, 17); // expected-warning{{source of this 'memcpy' call is a pointer to ownership-qualified type}} \
+ // expected-note{{explicitly cast the pointer to silence this warning}}
+ memcpy(ptr, aip, 17); // expected-warning{{source of this 'memcpy' call is a pointer to ownership-qualified type}} \
+ // expected-note{{explicitly cast the pointer to silence this warning}}
+ memcpy(ptr, uip, 17);
+
+ memmove(sip, ptr, 17); // expected-warning{{destination for this 'memmove' call is a pointer to ownership-qualified type}} \
+ // expected-note{{explicitly cast the pointer to silence this warning}}
+ memmove(wip, ptr, 17); // expected-warning{{destination for this 'memmove' call is a pointer to ownership-qualified type}} \
+ // expected-note{{explicitly cast the pointer to silence this warning}}
+ memmove(aip, ptr, 17); // expected-warning{{destination for this 'memmove' call is a pointer to ownership-qualified type}} \
+ // expected-note{{explicitly cast the pointer to silence this warning}}
+ memmove(uip, ptr, 17);
+
+ memmove(ptr, sip, 17); // expected-warning{{source of this 'memmove' call is a pointer to ownership-qualified type}} \
+ // expected-note{{explicitly cast the pointer to silence this warning}}
+ memmove(ptr, wip, 17); // expected-warning{{source of this 'memmove' call is a pointer to ownership-qualified type}} \
+ // expected-note{{explicitly cast the pointer to silence this warning}}
+ memmove(ptr, aip, 17); // expected-warning{{source of this 'memmove' call is a pointer to ownership-qualified type}} \
+ // expected-note{{explicitly cast the pointer to silence this warning}}
+ memmove(ptr, uip, 17);
+}
diff --git a/test/SemaObjC/arc-peformselector.m b/test/SemaObjC/arc-peformselector.m
new file mode 100644
index 0000000..e637f3d
--- /dev/null
+++ b/test/SemaObjC/arc-peformselector.m
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify %s
+// rdar://9659270
+
+@interface NSObject
+- (id)copy; // expected-note {{method declared here}}
+- (id) test __attribute__((ns_returns_retained)); // expected-note {{method declared here}}
++ (id) new ; // expected-note {{method declared here}}
+- (id) init __attribute__((ns_returns_not_retained));
+- (id)PlusZero;
+- (id)PlusOne __attribute__((ns_returns_retained)); // expected-note {{method declared here}}
+@end
+
+@interface I : NSObject
+{
+ SEL sel1;
+}
+- (id)performSelector:(SEL)aSelector;
+- (id)performSelector:(SEL)aSelector withObject:(id)object;
+- (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2;
+@end
+
+@implementation I
+- (id) Meth {
+ return [self performSelector : @selector(copy)]; // expected-error {{performSelector names a selector which retains the object}}
+ return [self performSelector : @selector(test)]; // expected-error {{performSelector names a selector which retains the object}}
+ return [self performSelector : @selector(new)]; // expected-error {{performSelector names a selector which retains the object}}
+ return [self performSelector : @selector(init)];
+ return [self performSelector : sel1]; // expected-warning {{performSelector may cause a leak because its selector is unknown}} \
+ // expected-note {{used here}}
+
+ return [self performSelector : @selector(PlusZero)];
+ return [self performSelector : @selector(PlusOne)]; // expected-error {{performSelector names a selector which retains the object}}
+}
+
+- (id)performSelector:(SEL)aSelector { return 0; }
+- (id)performSelector:(SEL)aSelector withObject:(id)object { return 0; }
+- (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2 { return 0; }
+@end
diff --git a/test/SemaObjC/arc-property-decl-attrs.m b/test/SemaObjC/arc-property-decl-attrs.m
new file mode 100644
index 0000000..0dd74b8
--- /dev/null
+++ b/test/SemaObjC/arc-property-decl-attrs.m
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s
+// rdar://9340606
+
+@interface Foo {
+@public
+ id __unsafe_unretained x;
+ id __weak y;
+ id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}}
+}
+@property(strong) id x;
+@property(strong) id y;
+@property(strong) id z;
+@end
+
+@interface Bar {
+@public
+ id __unsafe_unretained x;
+ id __weak y;
+ id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}}
+}
+@property(retain) id x;
+@property(retain) id y;
+@property(retain) id z;
+@end
+
+@interface Bas {
+@public
+ id __unsafe_unretained x;
+ id __weak y;
+ id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}}
+}
+@property(copy) id x;
+@property(copy) id y;
+@property(copy) id z;
+@end
+
+// Errors should start about here :-)
+
+@interface Bat
+@property(strong) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}}
+@property(strong) __weak id y; // expected-error {{strong property 'y' may not also be declared __weak}} expected-error {{property attributes 'strong' and 'weak' are mutually exclusive}}
+@property(strong) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}}
+@end
+
+@interface Bau
+@property(retain) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}}
+@property(retain) __weak id y; // expected-error {{strong property 'y' may not also be declared __weak}} expected-error {{property attributes 'retain' and 'weak' are mutually exclusive}}
+@property(retain) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}}
+@end
+
+@interface Bav
+@property(copy) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}}
+@property(copy) __weak id y; // expected-error {{strong property 'y' may not also be declared __weak}} expected-error {{property attributes 'copy' and 'weak' are mutually exclusive}}
+@property(copy) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}}
+@end
+
+@interface Bingo
+@property(assign) __unsafe_unretained id x;
+@property(assign) __weak id y; // expected-error {{property attributes 'assign' and 'weak' are mutually exclusive}}
+@property(assign) __autoreleasing id z; // expected-error {{unsafe_unretained property 'z' may not also be declared __autoreleasing}}
+@end
+
+@interface Batman
+@property(unsafe_unretained) __unsafe_unretained id x;
+@property(unsafe_unretained) __weak id y; // expected-error {{property attributes 'unsafe_unretained' and 'weak' are mutually exclusive}}
+@property(unsafe_unretained) __autoreleasing id z; // expected-error {{unsafe_unretained property 'z' may not also be declared __autoreleasing}}
+@end
diff --git a/test/SemaObjC/arc-property-lifetime.m b/test/SemaObjC/arc-property-lifetime.m
new file mode 100644
index 0000000..b1c84c7
--- /dev/null
+++ b/test/SemaObjC/arc-property-lifetime.m
@@ -0,0 +1,112 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s
+// rdar://9340606
+
+@interface Foo {
+@public
+ id __unsafe_unretained x;
+ id __weak y;
+ id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}}
+}
+@property(strong) id x; // expected-note {{property declared here}}
+@property(strong) id y; // expected-note {{property declared here}}
+@property(strong) id z;
+@end
+
+@implementation Foo
+@synthesize x; // expected-error {{existing ivar 'x' for strong property 'x' may not be __unsafe_unretained}}
+@synthesize y; // expected-error {{existing ivar 'y' for strong property 'y' may not be __weak}}
+@synthesize z; // suppressed
+@end
+
+@interface Bar {
+@public
+ id __unsafe_unretained x;
+ id __weak y;
+ id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}}
+}
+@property(retain) id x; // expected-note {{property declared here}}
+@property(retain) id y; // expected-note {{property declared here}}
+@property(retain) id z;
+@end
+
+@implementation Bar
+@synthesize x; // expected-error {{existing ivar 'x' for strong property 'x' may not be __unsafe_unretained}}
+@synthesize y; // expected-error {{existing ivar 'y' for strong property 'y' may not be __weak}}
+@synthesize z; // suppressed
+@end
+
+@interface Bas {
+@public
+ id __unsafe_unretained x;
+ id __weak y;
+ id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}}
+}
+@property(copy) id x; // expected-note {{property declared here}}
+@property(copy) id y; // expected-note {{property declared here}}
+@property(copy) id z;
+@end
+
+@implementation Bas
+@synthesize x; // expected-error {{existing ivar 'x' for strong property 'x' may not be __unsafe_unretained}}
+@synthesize y; // expected-error {{existing ivar 'y' for strong property 'y' may not be __weak}}
+@synthesize z; // suppressed
+@end
+
+@interface Bat
+@property(strong) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}}
+@property(strong) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}}
+@end
+
+@interface Bau
+@property(retain) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}}
+@property(retain) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}}
+@end
+
+@interface Bav
+@property(copy) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}}
+@property(copy) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}}
+@end
+
+// rdar://9341593
+@interface Gorf {
+ id __unsafe_unretained x;
+ id y;
+}
+@property(assign) id __unsafe_unretained x;
+@property(assign) id y; // expected-note {{property declared here}}
+@property(assign) id z;
+@end
+
+@implementation Gorf
+@synthesize x;
+@synthesize y; // expected-error {{existing ivar 'y' for unsafe_unretained property 'y' must be __unsafe_unretained}}
+@synthesize z;
+@end
+
+@interface Gorf2 {
+ id __unsafe_unretained x;
+ id y;
+}
+@property(unsafe_unretained) id __unsafe_unretained x;
+@property(unsafe_unretained) id y; // expected-note {{property declared here}}
+@property(unsafe_unretained) id z;
+@end
+
+@implementation Gorf2
+@synthesize x;
+@synthesize y; // expected-error {{existing ivar 'y' for unsafe_unretained property 'y' must be __unsafe_unretained}}
+@synthesize z;
+@end
+
+// rdar://9355230
+@interface I {
+ char _isAutosaving;
+}
+@property char isAutosaving;
+
+@end
+
+@implementation I
+@synthesize isAutosaving = _isAutosaving;
+@end
+
diff --git a/test/SemaObjC/arc-property.m b/test/SemaObjC/arc-property.m
new file mode 100644
index 0000000..0651f18
--- /dev/null
+++ b/test/SemaObjC/arc-property.m
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify %s
+// rdar://9309489
+
+@interface MyClass {
+ id __weak myString;
+ id StrongIvar;
+ id __weak myString2;
+ id __weak myString3;
+ id StrongIvar5;
+}
+@property (strong) id myString; // expected-note {{property declared here}}
+@property (strong) id myString1;
+@property (retain) id myString2; // expected-note {{property declared here}}
+//
+@property (weak) id myString3;
+@property (weak) id myString4;
+@property __weak id myString5; // expected-note {{property declared here}}
+@end
+
+@implementation MyClass
+@synthesize myString; // expected-error {{existing ivar 'myString' for strong property 'myString' may not be __weak}}
+@synthesize myString1 = StrongIvar; // OK
+@synthesize myString2 = myString2; // expected-error {{existing ivar 'myString2' for strong property 'myString2' may not be __weak}}
+//
+@synthesize myString3; // OK
+@synthesize myString4; // OK
+@synthesize myString5 = StrongIvar5; // expected-error {{existing ivar 'StrongIvar5' for __weak property 'myString5' must be __weak}}
+
+@end
+
+// rdar://9340692
+@interface Foo {
+@public
+ id __unsafe_unretained x; // should be __weak
+ id __strong y;
+ id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}}
+}
+@property(weak) id x; // expected-note {{property declared here}}
+@property(weak) id y; // expected-note {{property declared here}}
+@property(weak) id z;
+@end
+
+@implementation Foo
+@synthesize x; // expected-error {{existing ivar 'x' for __weak property 'x' must be __weak}}
+@synthesize y; // expected-error {{existing ivar 'y' for __weak property 'y' must be __weak}}
+@synthesize z; // suppressed
+@end
+
diff --git a/test/SemaObjC/arc-system-header.m b/test/SemaObjC/arc-system-header.m
new file mode 100644
index 0000000..3f17657
--- /dev/null
+++ b/test/SemaObjC/arc-system-header.m
@@ -0,0 +1,50 @@
+// silly workaround expected-note {{marked unavailable here}}
+// RUN: %clang_cc1 -fobjc-arc -fobjc-nonfragile-abi -isystem %S/Inputs %s -DNO_USE
+// RUN: %clang_cc1 -fobjc-arc -fobjc-nonfragile-abi -isystem %S/Inputs %s -verify
+
+// another silly workaround expected-note {{marked unavailable here}}
+#include <arc-system-header.h>
+
+#ifndef NO_USE
+void test(id op, void *cp) {
+ cp = test0(op); // expected-error {{'test0' is unavailable: converts between Objective-C and C pointers in -fobjc-arc}}
+ cp = *test1(&op); // expected-error {{'test1' is unavailable: converts between Objective-C and C pointers in -fobjc-arc}}
+}
+
+// workaround expected-note {{marked unavailable here}}
+void test3(struct Test3 *p) {
+ p->field = 0; // expected-error {{'field' is unavailable: this system declaration uses an unsupported type}}
+}
+
+// workaround expected-note {{marked unavailable here}}
+void test4(Test4 *p) {
+ p->field1 = 0; // expected-error {{'field1' is unavailable: this system declaration uses an unsupported type}}
+ p->field2 = 0;
+}
+
+// workaround expected-note {{marked unavailable here}}
+void test5(struct Test5 *p) {
+ p->field = 0; // expected-error {{'field' is unavailable: this system field has retaining ownership}}
+}
+
+id test6() {
+ // This is actually okay to use if declared in a system header.
+ id x;
+ x = (id) kMagicConstant;
+ x = (id) (x ? kMagicConstant : kMagicConstant);
+ x = (id) (x ? kMagicConstant : (void*) 0);
+
+ extern void test6_helper();
+ x = (id) (test6_helper(), kMagicConstant);
+}
+
+// workaround expected-note 4 {{marked unavailable here}}
+void test7(Test7 *p) {
+ *p.prop = 0; // expected-error {{'prop' is unavailable: this system declaration uses an unsupported type}}
+ p.prop = 0; // expected-error {{'prop' is unavailable: this system declaration uses an unsupported type}}
+ *[p prop] = 0; // expected-error {{'prop' is unavailable: this system declaration uses an unsupported type}}
+ [p setProp: 0]; // expected-error {{'setProp:' is unavailable: this system declaration uses an unsupported type}}
+}
+#endif
+
+// test8 in header
diff --git a/test/SemaObjC/arc-type-conversion.m b/test/SemaObjC/arc-type-conversion.m
new file mode 100644
index 0000000..103db56
--- /dev/null
+++ b/test/SemaObjC/arc-type-conversion.m
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-nonfragile-abi -fobjc-runtime-has-weak -verify -fblocks %s
+
+void * cvt(id arg)
+{
+ void* voidp_val;
+ (void)(int*)arg; // expected-error {{cast of an Objective-C pointer to 'int *' is disallowed with ARC}}
+ (void)(id)arg;
+ (void)(__autoreleasing id*)arg; // expected-error {{cast of an Objective-C pointer to '__autoreleasing id *' is disallowed with ARC}}
+ (void)(id*)arg; // expected-error {{cast of an Objective-C pointer to '__strong id *' is disallowed with ARC}}
+
+ (void)(__autoreleasing id**)voidp_val;
+ (void)(void*)voidp_val;
+ (void)(void**)arg; // expected-error {{cast of an Objective-C pointer to 'void **' is disallowed with ARC}}
+ cvt((void*)arg); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \
+ // expected-error {{implicit conversion of a non-Objective-C pointer type 'void *' to 'id' is disallowed with ARC}} \
+ // expected-note{{use __bridge to convert directly (no change in ownership)}} \
+ // expected-note{{use __bridge_retained to make an ARC object available as a +1 'void *'}}
+ cvt(0);
+ (void)(__strong id**)(0);
+ return arg; // expected-error {{implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC}}
+}
+
+void to_void(__strong id *sip, __weak id *wip,
+ __autoreleasing id *aip,
+ __unsafe_unretained id *uip) {
+ void *vp1 = sip;
+ void *vp2 = wip;
+ void *vp3 = aip;
+ void *vp4 = uip;
+ (void)(void*)sip;
+ (void)(void*)wip;
+ (void)(void*)aip;
+ (void)(void*)uip;
+ (void)(void*)&sip;
+ (void)(void*)&wip;
+ (void)(void*)&aip;
+ (void)(void*)&uip;
+}
+
+void from_void(void *vp) {
+ __strong id *sip = (__strong id *)vp;
+ __weak id *wip = (__weak id *)vp;
+ __autoreleasing id *aip = (__autoreleasing id *)vp;
+ __unsafe_unretained id *uip = (__unsafe_unretained id *)vp;
+
+ __strong id **sipp = (__strong id **)vp;
+ __weak id **wipp = (__weak id **)vp;
+ __autoreleasing id **aipp = (__autoreleasing id **)vp;
+ __unsafe_unretained id **uipp = (__unsafe_unretained id **)vp;
+
+ sip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__strong id *' is disallowed with ARC}}
+ wip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__weak id *' is disallowed with ARC}}
+ aip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__autoreleasing id *' is disallowed with ARC}}
+ uip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__unsafe_unretained id *' is disallowed with ARC}}
+}
+
+typedef void (^Block)();
+typedef void (^Block_strong)() __strong;
+typedef void (^Block_autoreleasing)() __autoreleasing;
+
+@class NSString;
+
+void ownership_transfer_in_cast(void *vp, Block *pblk) {
+ __strong NSString **sip = (NSString**)(__strong id *)vp;
+ __weak NSString **wip = (NSString**)(__weak id *)vp;
+ __autoreleasing id *aip = (id*)(__autoreleasing id *)vp;
+ __unsafe_unretained id *uip = (id*)(__unsafe_unretained id *)vp;
+
+ __strong id **sipp = (id**)(__strong id **)vp;
+ __weak id **wipp = (id**)(__weak id **)vp;
+ __autoreleasing id **aipp = (id**)(__autoreleasing id **)vp;
+ __unsafe_unretained id **uipp = (id**)(__unsafe_unretained id **)vp;
+
+ Block_strong blk_strong1;
+ Block_strong blk_strong2 = (Block)blk_strong1;
+ Block_autoreleasing *blk_auto = (Block*)pblk;
+}
diff --git a/test/SemaObjC/arc-unavailable-for-weakref.m b/test/SemaObjC/arc-unavailable-for-weakref.m
new file mode 100644
index 0000000..104314e
--- /dev/null
+++ b/test/SemaObjC/arc-unavailable-for-weakref.m
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s
+// rdar://9693477
+
+__attribute__((objc_arc_weak_reference_unavailable))
+@interface NSOptOut1072 // expected-note {{class is declared here}}
+@end
+
+@interface sub : NSOptOut1072 @end // expected-note 2 {{class is declared here}}
+
+int main() {
+ __weak sub *w2; // expected-error {{class is incompatible with __weak references}}
+
+ __weak NSOptOut1072 *ns1; // expected-error {{class is incompatible with __weak references}}
+
+ id obj;
+
+ ns1 = (__weak sub *)obj; // expected-error {{assignment of a weak-unavailable object to a __weak object}} \
+ // expected-error {{class is incompatible with __weak references}}
+}
+
+// rdar://9732636
+__attribute__((objc_arc_weak_reference_unavailable))
+@interface NOWEAK
++ (id) new;
+@end
+
+NOWEAK * Test1() {
+ NOWEAK * strong1 = [NOWEAK new];
+ __weak id weak1;
+ weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
+
+ __weak id weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
+ return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *' to a __weak object of type '__weak id'}}
+}
+
+@protocol P @end
+@protocol P1 @end
+
+NOWEAK<P, P1> * Test2() {
+ NOWEAK<P, P1> * strong1 = 0;
+ __weak id<P> weak1;
+ weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
+
+ __weak id<P> weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
+ return (__weak id<P>)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK<P,P1> *' to a __weak object of type '__weak id<P>'}}
+}
+
diff --git a/test/SemaObjC/arc-unbridged-cast.m b/test/SemaObjC/arc-unbridged-cast.m
new file mode 100644
index 0000000..03c84cf
--- /dev/null
+++ b/test/SemaObjC/arc-unbridged-cast.m
@@ -0,0 +1,18 @@
+// // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify %s
+// rdar://9744349
+
+typedef const struct __CFString * CFStringRef;
+
+@interface I
+@property CFStringRef P;
+@end
+
+@implementation I
+@synthesize P;
+- (id) Meth {
+ I* p1 = (id)[p1 P];
+ id p2 = (__bridge_transfer id)[p1 P];
+ id p3 = (__bridge I*)[p1 P];
+ return (id) p1.P;
+}
+@end
diff --git a/test/SemaObjC/arc-unsafe-assigns.m b/test/SemaObjC/arc-unsafe-assigns.m
new file mode 100644
index 0000000..be8f902
--- /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-unsafe_unretained.m b/test/SemaObjC/arc-unsafe_unretained.m
new file mode 100644
index 0000000..77bdded
--- /dev/null
+++ b/test/SemaObjC/arc-unsafe_unretained.m
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fblocks -fobjc-nonfragile-abi %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -fobjc-nonfragile-abi -fobjc-arc %s
+
+struct X {
+ __unsafe_unretained id object;
+ int (^ __unsafe_unretained block)(int, int);
+};
+
+void f(struct X x) {
+ x.object = 0;
+ x.block = ^(int x, int y) { return x + y; };
+}
diff --git a/test/SemaObjC/arc.m b/test/SemaObjC/arc.m
new file mode 100644
index 0000000..3d190e5
--- /dev/null
+++ b/test/SemaObjC/arc.m
@@ -0,0 +1,628 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify %s
+
+typedef unsigned long NSUInteger;
+
+void test0(void (*fn)(int), int val) {
+ fn(val);
+}
+
+@interface A
+- (id)retain;
+- (id)autorelease;
+- (oneway void)release;
+- (void)dealloc;
+- (NSUInteger)retainCount;
+@end
+
+void test1(A *a) {
+ SEL s = @selector(retain); // expected-error {{ARC forbids use of 'retain' in a @selector}}
+ s = @selector(release); // expected-error {{ARC forbids use of 'release' in a @selector}}
+ s = @selector(autorelease); // expected-error {{ARC forbids use of 'autorelease' in a @selector}}
+ s = @selector(dealloc); // expected-error {{ARC forbids use of 'dealloc' in a @selector}}
+ [a dealloc]; // expected-error {{ARC forbids explicit message send of 'dealloc'}}
+ [a retain]; // expected-error {{ARC forbids explicit message send of 'retain'}}
+ [a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}}
+ [a release]; // expected-error {{ARC forbids explicit message send of 'release'}}
+ [a autorelease]; // expected-error {{ARC forbids explicit message send of 'autorelease'}}
+}
+
+@interface Test2 : A
+- (void) dealloc;
+@end
+@implementation Test2
+- (void) dealloc {
+ // This should maybe just be ignored. We're just going to warn about it for now.
+ [super dealloc]; // expected-error {{ARC forbids explicit message send of 'dealloc'}}
+}
+@end
+
+__weak __strong id x; // expected-error {{the type '__strong id' already has retainment attributes}}
+
+// rdar://8843638
+
+@interface I
+- (id)retain;
+- (id)autorelease;
+- (oneway void)release;
+- (NSUInteger)retainCount;
+@end
+
+@implementation I
+- (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}}
+- (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}}
+- (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}}
+- (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}}
+@end
+
+@implementation I(CAT)
+- (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}}
+- (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}}
+- (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}}
+- (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}}
+@end
+
+// rdar://8861761
+
+@interface B
+-(id)alloc;
+- (id)initWithInt: (int) i;
+@end
+
+void rdar8861761() {
+ B *o1 = [[B alloc] initWithInt:0];
+ B *o2 = [B alloc];
+ [o2 initWithInt:0]; // expected-warning {{expression result unused}}
+}
+
+// rdar://8925835
+@interface rdar8925835
+- (void)foo:(void (^)(unsigned captureCount, I * const capturedStrings[captureCount]))block;
+@end
+
+void test5() {
+ extern void test5_helper(__autoreleasing id *);
+ id x;
+
+ // Okay because of magic temporaries.
+ test5_helper(&x);
+
+ __autoreleasing id *a = &x; // expected-error {{initializing '__autoreleasing id *' with an expression of type '__strong id *' changes retain/release properties of pointer}}
+
+ a = &x; // expected-error {{assigning '__strong id *' to '__autoreleasing id *' changes retain/release properties of pointer}}
+
+ extern void test5_helper2(id const *);
+ test5_helper2(&x);
+
+ extern void test5_helper3(__weak id *); // expected-note {{passing argument to parameter here}}
+ test5_helper3(&x); // expected-error {{passing '__strong id *' to parameter of type '__weak id *' changes retain/release properties of pointer}}
+}
+
+// rdar://problem/8937869
+void test6(unsigned cond) {
+ switch (cond) {
+ case 0:
+ ;
+ id x; // expected-note {{jump bypasses initialization of retaining variable}}
+
+ case 1: // expected-error {{switch case is in protected scope}}
+ break;
+ }
+}
+
+@class NSError;
+void test7(void) {
+ extern void test7_helper(NSError **);
+ NSError *err;
+ test7_helper(&err);
+}
+void test7_weak(void) {
+ extern void test7_helper(NSError **);
+ __weak NSError *err;
+ test7_helper(&err);
+}
+void test7_unsafe(void) {
+ extern void test7_helper(NSError **); // expected-note {{passing argument to parameter here}}
+ __unsafe_unretained NSError *err;
+ test7_helper(&err); // expected-error {{passing 'NSError *__unsafe_unretained *' to parameter of type 'NSError *__autoreleasing *' changes retain/release properties of pointer}}
+}
+
+@class Test8_incomplete;
+@interface Test8_complete @end;
+@interface Test8_super @end;
+@interface Test8 : Test8_super
+- (id) init00;
+- (id) init01; // expected-note {{declaration in interface}} \
+ // expected-note{{overridden method}}
+- (id) init02; // expected-note{{overridden method}}
+- (id) init03; // covariance
+- (id) init04; // covariance
+- (id) init05; // expected-note{{overridden method}}
+
+- (void) init10; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
+- (void) init11;
+- (void) init12;
+- (void) init13; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
+- (void) init14; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
+- (void) init15;
+
+// These should be invalid to actually call.
+- (Test8_incomplete*) init20;
+- (Test8_incomplete*) init21; // expected-note {{declaration in interface}}
+- (Test8_incomplete*) init22;
+- (Test8_incomplete*) init23;
+- (Test8_incomplete*) init24;
+- (Test8_incomplete*) init25;
+
+- (Test8_super*) init30; // id exception to covariance
+- (Test8_super*) init31; // expected-note {{declaration in interface}} \
+ // expected-note{{overridden method}}
+- (Test8_super*) init32; // expected-note{{overridden method}}
+- (Test8_super*) init33;
+- (Test8_super*) init34; // covariance
+- (Test8_super*) init35; // expected-note{{overridden method}}
+
+- (Test8*) init40; // id exception to covariance
+- (Test8*) init41; // expected-note {{declaration in interface}} \
+ // expected-note{{overridden method}}
+- (Test8*) init42; // expected-note{{overridden method}}
+- (Test8*) init43; // this should be a warning, but that's a general language thing, not an ARC thing
+- (Test8*) init44;
+- (Test8*) init45; // expected-note{{overridden method}}
+
+- (Test8_complete*) init50; // expected-error {{init methods must return a type related to the receiver type}}
+- (Test8_complete*) init51; // expected-error {{init methods must return a type related to the receiver type}}
+- (Test8_complete*) init52; // expected-error {{init methods must return a type related to the receiver type}}
+- (Test8_complete*) init53; // expected-error {{init methods must return a type related to the receiver type}}
+- (Test8_complete*) init54; // expected-error {{init methods must return a type related to the receiver type}}
+- (Test8_complete*) init55; // expected-error {{init methods must return a type related to the receiver type}}
+@end
+@implementation Test8
+- (id) init00 { return 0; }
+- (id) init10 { return 0; } // expected-error {{method implementation does not match its declaration}}
+- (id) init20 { return 0; }
+- (id) init30 { return 0; }
+- (id) init40 { return 0; }
+- (id) init50 { return 0; }
+
+- (void) init01 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} \
+ // expected-warning{{ method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
+- (void) init11 {}
+- (void) init21 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}}
+- (void) init31 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} \
+ // expected-warning{{ method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
+- (void) init41 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} \
+ // expected-warning{{ method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
+- (void) init51 {}
+
+- (Test8_incomplete*) init02 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
+ // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
+- (Test8_incomplete*) init12 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
+- (Test8_incomplete*) init22 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
+- (Test8_incomplete*) init32 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
+ // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
+- (Test8_incomplete*) init42 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
+ // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
+- (Test8_incomplete*) init52 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
+
+- (Test8_super*) init03 { return 0; }
+- (Test8_super*) init13 { return 0; } // expected-error {{method implementation does not match its declaration}}
+- (Test8_super*) init23 { return 0; }
+- (Test8_super*) init33 { return 0; }
+- (Test8_super*) init43 { return 0; }
+- (Test8_super*) init53 { return 0; }
+
+- (Test8*) init04 { return 0; }
+- (Test8*) init14 { return 0; } // expected-error {{method implementation does not match its declaration}}
+- (Test8*) init24 { return 0; }
+- (Test8*) init34 { return 0; }
+- (Test8*) init44 { return 0; }
+- (Test8*) init54 { return 0; }
+
+- (Test8_complete*) init05 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
+ // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
+- (Test8_complete*) init15 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
+- (Test8_complete*) init25 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
+- (Test8_complete*) init35 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
+ // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
+- (Test8_complete*) init45 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
+ // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
+- (Test8_complete*) init55 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
+@end
+
+@class Test9_incomplete;
+@interface Test9
+- (Test9_incomplete*) init1; // expected-error {{init methods must return a type related to the receiver type}}
+- (Test9_incomplete*) init2;
+@end
+id test9(Test9 *v) {
+ return [v init1];
+}
+
+// Test that the inference rules are different for fast enumeration variables.
+void test10(id collection) {
+ for (id x in collection) {
+ __strong id *ptr = &x; // expected-warning {{initializing '__strong id *' with an expression of type 'const __strong id *' discards qualifiers}}
+ }
+
+ for (__strong id x in collection) {
+ __weak id *ptr = &x; // expected-error {{initializing '__weak id *' with an expression of type '__strong id *' changes retain/release properties of pointer}}
+ }
+}
+
+// rdar://problem/9078626
+#define nil ((void*) 0)
+void test11(id op, void *vp) {
+ _Bool b;
+ b = (op == nil);
+ b = (nil == op);
+
+ b = (vp == nil);
+ b = (nil == vp);
+
+ b = (vp == op); // expected-error {{implicit conversion of an Objective-C pointer to 'void *'}}
+ b = (op == vp); // expected-error {{implicit conversion of a non-Objective-C pointer type 'void *' to 'id'}}
+}
+
+void test12(id collection) {
+ for (id x in collection) {
+ x = 0; // expected-error {{fast enumeration variables can't be modified in ARC by default; declare the variable __strong to allow this}}
+ }
+
+ for (const id x in collection) {
+ x = 0; // expected-error {{read-only variable is not assignable}}
+ }
+
+ for (__strong id x in collection) {
+ x = 0;
+ }
+}
+
+@interface Test13
+- (id) init0;
+- (void) noninit;
+@end
+@implementation Test13
+- (id) init0 {
+ self = 0;
+}
+- (void) noninit {
+ self = 0; // expected-error {{cannot assign to 'self' outside of a method in the init family}}
+}
+@end
+
+// rdar://problem/9172151
+@class Test14A, Test14B;
+void test14() {
+ extern void test14_consume(id *);
+ extern int test14_cond(void);
+ extern float test14_nowriteback(id __autoreleasing const *); // expected-note{{passing argument to parameter here}}
+
+ Test14A *a;
+ Test14B *b;
+ id i;
+ id cla[10];
+ id vla[test14_cond() + 10];
+
+ test14_consume((__strong id*) &a);
+ test14_consume((test14_cond() ? (__strong id*) &b : &i));
+ test14_consume(test14_cond() ? 0 : &a);
+ test14_consume(test14_cond() ? (void*) 0 : (&a));
+ test14_consume(cla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
+ test14_consume(vla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
+ test14_consume(&cla[5]); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
+
+ __strong id *test14_indirect(void);
+ test14_consume(test14_indirect()); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
+
+ extern id test14_global;
+ test14_consume(&test14_global); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
+
+ extern __strong id *test14_global_ptr;
+ test14_consume(test14_global_ptr); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
+
+ static id static_local;
+ test14_consume(&static_local); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
+
+ __weak id* wip;
+ test14_nowriteback(&static_local); // okay, not a write-back.
+ test14_nowriteback(wip); // expected-error{{passing '__weak id *' to parameter of type '__autoreleasing id const *' changes retain/release properties of pointer}}
+}
+
+void test15() {
+ __block __autoreleasing id x; // expected-error {{__block variables cannot have __autoreleasing ownership}}
+}
+
+struct Test16;
+@interface Test16a
+- (void) test16_0: (int) x;
+- (int) test16_1: (int) x; // expected-note {{one possibility}}
+- (int) test16_2: (int) x; // expected-note {{one possibility}}
+- (id) test16_3: (int) x __attribute__((ns_returns_retained)); // expected-note {{one possibility}}
+- (void) test16_4: (int) x __attribute__((ns_consumes_self)); // expected-note {{one possibility}}
+- (void) test16_5: (id) __attribute__((ns_consumed)) x; // expected-note {{one possibility}}
+- (void) test16_6: (id) x;
+@end
+
+@interface Test16b
+- (void) test16_0: (int) x;
+- (int) test16_1: (char*) x; // expected-note {{also found}}
+- (char*) test16_2: (int) x; // expected-note {{also found}}
+- (id) test16_3: (int) x; // expected-note {{also found}}
+- (void) test16_4: (int) x; // expected-note {{also found}}
+- (void) test16_5: (id) x; // expected-note {{also found}}
+- (void) test16_6: (struct Test16 *) x;
+@end
+
+void test16(void) {
+ id v;
+ [v test16_0: 0];
+ [v test16_1: 0]; // expected-error {{multiple methods named 'test16_1:' found with mismatched result, parameter type or attributes}}
+ [v test16_2: 0]; // expected-error {{multiple methods named}}
+ [v test16_3: 0]; // expected-error {{multiple methods named}}
+ [v test16_4: 0]; // expected-error {{multiple methods named}}
+ [v test16_5: 0]; // expected-error {{multiple methods named}}
+ [v test16_6: 0];
+}
+
+@class Test17;
+@protocol Test17p
+- (void) test17;
++ (void) test17;
+@end
+void test17(void) {
+ Test17 *v0;
+ [v0 test17]; // expected-error {{receiver type 'Test17' for instance message is a forward declaration}}
+
+ Test17<Test17p> *v1;
+ [v1 test17]; // expected-error {{receiver type 'Test17<Test17p>' for instance message is a forward declaration}}
+
+ [Test17 test17]; // expected-error {{receiver 'Test17' for class message is a forward declaration}}
+}
+
+void test18(void) {
+ id x;
+ [x test18]; // expected-error {{no known instance method for selector 'test18'}}
+}
+
+extern struct Test19 *test19a;
+struct Test19 *const test19b = 0;
+void test19(void) {
+ id x;
+ x = (id) test19a; // expected-error {{bridged cast}} \
+ // expected-note{{use __bridge to convert directly (no change in ownership))}} \
+ // expected-note{{use __bridge_transfer to transfer ownership of a +1 'struct Test19 *' into ARC}}
+ x = (id) test19b; // expected-error {{bridged cast}} \
+ // expected-note{{use __bridge to convert directly (no change in ownership)}} \
+ // expected-note{{use __bridge_transfer to transfer ownership of a +1 'struct Test19 *' into ARC}}
+}
+
+// rdar://problem/8951453
+static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
+static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
+static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}}
+static __thread __autoreleasing id test20_autoreleasing; // expected-error {{thread-local variable has non-trivial ownership: type is '__autoreleasing id'}} expected-error {{global variables cannot have __autoreleasing ownership}}
+static __thread __unsafe_unretained id test20_unsafe;
+void test20(void) {
+ static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
+ static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
+ static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}}
+ static __thread __autoreleasing id test20_autoreleasing; // expected-error {{thread-local variable has non-trivial ownership: type is '__autoreleasing id'}} expected-error {{global variables cannot have __autoreleasing ownership}}
+ static __thread __unsafe_unretained id test20_unsafe;
+}
+
+// rdar://9310049
+_Bool fn(id obj) {
+ return (_Bool)obj;
+}
+
+// Check casting w/ ownership qualifiers.
+void test21() {
+ __strong id *sip;
+ (void)(__weak id *)sip; // expected-error{{casting '__strong id *' to type '__weak id *' changes retain/release properties of pointer}}
+ (void)(__weak const id *)sip; // expected-error{{casting '__strong id *' to type '__weak id const *' changes retain/release properties of pointer}}
+ (void)(__autoreleasing id *)sip; // expected-error{{casting '__strong id *' to type '__autoreleasing id *' changes retain/release properties of pointer}}
+ (void)(__autoreleasing const id *)sip; // okay
+}
+
+// rdar://problem/9340462
+void test22(id x[]) { // expected-error {{must explicitly describe intended ownership of an object array parameter}}
+}
+
+// rdar://problem/9400219
+void test23(void) {
+ void *ptr;
+ ptr = @"foo";
+ ptr = (ptr ? @"foo" : 0);
+ ptr = (ptr ? @"foo" : @"bar");
+}
+
+id test24(void) {
+ extern void test24_helper(void);
+ return test24_helper(), (void*) 0;
+}
+
+// rdar://9400841
+@interface Base
+@property (assign) id content;
+@end
+
+@interface Foo : Base
+-(void)test;
+@end
+
+@implementation Foo
+-(void)test {
+ super.content = 0;
+}
+@end
+
+// <rdar://problem/9398437>
+void test25(Class *classes) {
+ Class *other_classes;
+ test25(other_classes);
+}
+
+void test26(id y) {
+ extern id test26_var1;
+ __sync_swap(&test26_var1, 0, y); // expected-error {{cannot perform atomic operation on a pointer to type '__strong id': type has non-trivial ownership}}
+
+ extern __unsafe_unretained id test26_var2;
+ __sync_swap(&test26_var2, 0, y);
+}
+
+@interface Test26
+- (id) init;
+- (id) initWithInt: (int) x;
+@end
+@implementation Test26
+- (id) init { return self; }
+- (id) initWithInt: (int) x {
+ [self init]; // expected-error {{the result of a delegate init call must be immediately returned or assigned to 'self'}}
+ return self;
+}
+@end
+
+// rdar://9525555
+@interface Test27
+@property id x; // expected-warning {{no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed}} \
+ // expected-warning {{default property attribute 'assign' not appropriate for non-gc object}} \
+ // expected-note {{declared here}}
+@property (readonly) id ro; // expected-note {{declared here}}
+@property (readonly) id custom_ro;
+@property int y;
+@end
+
+@implementation Test27
+@synthesize x; // expected-error {{ARC forbids synthesizing a property of an Objective-C object with unspecified storage attribute}}
+@synthesize ro; // expected-error {{ARC forbids synthesizing a property of an Objective-C object with unspecified storage attribute}}
+@synthesize y;
+-(id)custom_ro { return 0; }
+@end
+
+// rdar://9569264
+@interface Test28
+@property (nonatomic, assign) __strong id a; // expected-error {{unsafe_unretained property 'a' may not also be declared __strong}}
+@end
+
+@interface Test28 ()
+@property (nonatomic, assign) __strong id b; // expected-error {{unsafe_unretained property 'b' may not also be declared __strong}}
+@end
+
+@implementation Test28
+@synthesize a;
+@synthesize b;
+@end
+
+// rdar://9573962
+typedef struct Bark Bark;
+@interface Test29
+@property Bark* P;
+@end
+
+@implementation Test29
+@synthesize P;
+- (id)Meth {
+ Bark** f = &P;
+ return 0;
+}
+@end
+
+// rdar://9495837
+@interface Test30
++ (id) new;
+- (void)Meth;
+@end
+
+@implementation Test30
++ (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}}
+ id y = [Test30 new];
+ x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}}
+ u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}}
+ y = [Test30 new];
+}
+@end
+
+// rdar://9411838
+@protocol PTest31 @end
+
+int Test31() {
+ Class cls;
+ id ids;
+ id<PTest31> pids;
+ Class<PTest31> pcls;
+
+ int i = (ids->isa ? 1 : 0); // expected-error {{member reference base type 'id' is not a structure or union}}
+ int j = (pids->isa ? 1 : 0); // expected-error {{member reference base type 'id<PTest31>' is not a structure or union}}
+ int k = (pcls->isa ? i : j); // expected-error {{member reference base type 'Class<PTest31>' is not a structure or union}}
+ return cls->isa ? i : j; // expected-error {{member reference base type 'Class' is not a structure or union}}
+}
+
+// rdar://9612030
+@interface ITest32 {
+@public
+ id ivar;
+}
+@end
+
+id Test32(__weak ITest32 *x) {
+ __weak ITest32 *y;
+ x->ivar = 0; // expected-error {{dereferencing a __weak pointer is not allowed}}
+ return y ? y->ivar // expected-error {{dereferencing a __weak pointer is not allowed}}
+ : (*x).ivar; // expected-error {{dereferencing a __weak pointer is not allowed}}
+}
+
+// rdar://9619861
+extern int printf(const char*, ...);
+typedef long intptr_t;
+
+int Test33(id someid) {
+ printf( "Hello%ld", (intptr_t)someid);
+ return (int)someid;
+}
+
+// rdar://9636091
+@interface I34
+@property (nonatomic, retain) id newName __attribute__((ns_returns_not_retained)) ;
+
+@property (nonatomic, retain) id newName1 __attribute__((ns_returns_not_retained)) ;
+- (id) newName1 __attribute__((ns_returns_not_retained));
+
+@property (nonatomic, retain) id newName2 __attribute__((ns_returns_not_retained)); // expected-note {{roperty declared here}}
+- (id) newName2; // expected-warning {{property declared as returning non-retained objects; getter returning retained objects}}
+@end
+
+@implementation I34
+@synthesize newName;
+
+@synthesize newName1;
+- (id) newName1 { return 0; }
+
+@synthesize newName2;
+@end
+
+void test35(void) {
+ extern void test36_helper(id*);
+ id x;
+ __strong id *xp = 0;
+
+ test36_helper(&x);
+ test36_helper(xp); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
+
+ // rdar://problem/9665710
+ __block id y;
+ test36_helper(&y);
+ ^{ test36_helper(&y); }();
+
+ __strong int non_objc_type; // expected-warning {{'__strong' only applies to objective-c object or block pointer types}}
+}
+
+void test36(int first, ...) {
+ // <rdar://problem/9758798>
+ __builtin_va_list arglist;
+ __builtin_va_start(arglist, first);
+ id obj = __builtin_va_arg(arglist, id);
+ __builtin_va_end(arglist);
+}
diff --git a/test/SemaObjC/autoreleasepool.m b/test/SemaObjC/autoreleasepool.m
new file mode 100644
index 0000000..41e1768
--- /dev/null
+++ b/test/SemaObjC/autoreleasepool.m
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void *objc_autoreleasepool_push();
+void autoreleasepool_pop(void*);
+
+@interface AUTORP @end
+
+@implementation AUTORP
+- (void) unregisterTask:(id) task {
+ goto L; // expected-error {{goto into protected scope}}
+
+ @autoreleasepool { // expected-note {{jump bypasses auto release push of @autoreleasepool block}}
+ void *tmp = objc_autoreleasepool_push();
+ L:
+ autoreleasepool_pop(tmp);
+ @autoreleasepool {
+ return;
+ }
+ }
+}
+@end
+
diff --git a/test/SemaObjC/class-proto-1.m b/test/SemaObjC/class-proto-1.m
index 246b500..8030976 100644
--- a/test/SemaObjC/class-proto-1.m
+++ b/test/SemaObjC/class-proto-1.m
@@ -23,9 +23,9 @@
@interface E2 <p1,p2,p3> @end // expected-warning {{cannot find protocol definition for 'p3'}}
-@class U1, U2;
+@class U1, U2; // expected-note {{forward class is declared here}}
-@interface E3 : U1 @end // expected-error {{cannot find interface declaration for 'U1', superclass of 'E3'}}
+@interface E3 : U1 @end // expected-error {{attempting to use the forward class 'U1' as superclass of 'E3'}}
@interface I3 : E3 @end
diff --git a/test/SemaObjC/class-unavail-warning.m b/test/SemaObjC/class-unavail-warning.m
index 426ac77..408647a 100644
--- a/test/SemaObjC/class-unavail-warning.m
+++ b/test/SemaObjC/class-unavail-warning.m
@@ -2,7 +2,7 @@
// rdar://9092208
__attribute__((unavailable("not available")))
-@interface MyClass { // expected-note 5 {{function has been explicitly marked unavailable here}}
+@interface MyClass { // expected-note 5 {{declaration has been explicitly marked unavailable here}}
@public
void *_test;
}
diff --git a/test/SemaObjC/debugger-support.m b/test/SemaObjC/debugger-support.m
new file mode 100644
index 0000000..21c096e
--- /dev/null
+++ b/test/SemaObjC/debugger-support.m
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fdebugger-support %s -emit-llvm -o - | FileCheck %s
+
+// rdar://problem/9416370
+void test0(id x) {
+ struct A { int w, x, y, z; };
+ struct A result = (struct A) [x makeStruct];
+ // CHECK: define void @test0(
+ // CHECK: [[X:%.*]] = alloca i8*, align 8
+ // CHECK-NEXT: [[RESULT:%.*]] = alloca [[A:%.*]], align 4
+ // CHECK-NEXT: store i8* {{%.*}}, i8** [[X]],
+ // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]],
+ // CHECK-NEXT: [[T1:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_"
+ // CHECK-NEXT: [[T2:%.*]] = call { i64, i64 } bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to { i64, i64 } (i8*, i8*)*)(i8* [[T0]], i8* [[T1]])
+}
diff --git a/test/SemaObjC/error-property-gc-attr.m b/test/SemaObjC/error-property-gc-attr.m
index a77b68b..829c082 100644
--- a/test/SemaObjC/error-property-gc-attr.m
+++ b/test/SemaObjC/error-property-gc-attr.m
@@ -20,9 +20,9 @@
@implementation INTF
@synthesize pweak=IVAR; // expected-error {{existing ivar 'IVAR' for __weak property 'pweak' must be __weak}}
-@synthesize NOT=II; // expected-error {{property 'NOT' must be declared __weak to match existing ivar 'II' with __weak attribute}}
+@synthesize NOT=II; // expected-error {{existing ivar 'II' for strong property 'NOT' may not be __weak}}
@synthesize WID;
@synthesize ID;
-@synthesize AWEAK; // expected-error {{property 'AWEAK' must be declared __weak to match existing ivar 'AWEAK' with __weak attribute}}
+@synthesize AWEAK; // expected-error {{existing ivar 'AWEAK' for strong property 'AWEAK' may not be __weak}}
@synthesize WI;
@end
diff --git a/test/SemaObjC/forward-class-1.m b/test/SemaObjC/forward-class-1.m
index ab213fb..de94e88 100644
--- a/test/SemaObjC/forward-class-1.m
+++ b/test/SemaObjC/forward-class-1.m
@@ -1,9 +1,9 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-@class FOO, BAR;
+@class FOO, BAR; // expected-note {{forward class is declared here}}
@class FOO, BAR;
-@interface INTF : FOO // expected-error {{cannot find interface declaration for 'FOO', superclass of 'INTF'}}
+@interface INTF : FOO // expected-error {{attempting to use the forward class 'FOO' as superclass of 'INTF'}}
@end
@interface FOO
@@ -45,3 +45,14 @@ typedef NSObject <XCElementP> XCElement;
@end
+// rdar://9653341
+@class B; // expected-note {{forward class is declared here}}
+@interface A : B {} // expected-error {{attempting to use the forward class 'B' as superclass of 'A'}}
+@end
+
+@interface B : A {}
+@end
+
+@implementation A @end
+@implementation B @end
+
diff --git a/test/SemaObjC/ivar-ref-misuse.m b/test/SemaObjC/ivar-ref-misuse.m
index ba2f115..f6d9c94 100644
--- a/test/SemaObjC/ivar-ref-misuse.m
+++ b/test/SemaObjC/ivar-ref-misuse.m
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-@interface Sprite {
+@interface Sprite { // expected-note{{'Sprite' declared here}}
int sprite, spree;
int UseGlobalBar;
}
@@ -17,7 +17,8 @@ int UseGlobalBar;
+ (void)setFoo:(int)foo {
sprite = foo; // expected-error {{instance variable 'sprite' accessed in class method}}
spree = foo;
- Xsprite = foo; // expected-error {{use of undeclared identifier 'Xsprite'}}
+ Xsprite = foo; // expected-error {{unknown type name 'Xsprite'; did you mean 'Sprite'?}} \
+ // expected-error{{expected identifier or '('}}
UseGlobalBar = 10;
}
+ (void)setSprite:(int)sprite {
diff --git a/test/SemaObjC/method-lookup-3.m b/test/SemaObjC/method-lookup-3.m
index 882b3d1..b3d9c46 100644
--- a/test/SemaObjC/method-lookup-3.m
+++ b/test/SemaObjC/method-lookup-3.m
@@ -55,3 +55,19 @@ void f5(id a0, Abstract *a1) {
void f6(id<A> a0) {
Abstract *l = [a0 x];
}
+
+struct test3a { int x, y; };
+struct test3b { unsigned x, y; };
+@interface Test3A - (struct test3a) test3; @end
+@interface Test3B - (struct test3b) test3; @end
+void test3(id x) {
+ (void) [x test3];
+}
+
+struct test4a { int x, y; };
+struct test4b { float x, y; };
+@interface Test4A - (struct test4a) test4; @end //expected-note{{using}}
+@interface Test4B - (struct test4b) test4; @end //expected-note{{also found}}
+void test4(id x) {
+ (void) [x test4]; //expected-warning {{multiple methods named 'test4' found}}
+}
diff --git a/test/SemaObjC/no-warning-unavail-unimp.m b/test/SemaObjC/no-warning-unavail-unimp.m
new file mode 100644
index 0000000..9409322
--- /dev/null
+++ b/test/SemaObjC/no-warning-unavail-unimp.m
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// rdar://9651605
+
+@interface Foo
+@property (getter=getVal) int val __attribute__((unavailable));
+- Method __attribute__((unavailable));
++ CMethod __attribute__((unavailable));
+@end
+
+@implementation Foo
+@end
+
diff --git a/test/SemaObjC/property-10.m b/test/SemaObjC/property-10.m
index 0119273..e89d68e 100644
--- a/test/SemaObjC/property-10.m
+++ b/test/SemaObjC/property-10.m
@@ -5,14 +5,24 @@
@interface I0
@property(readonly, readwrite) int p0; // expected-error {{property attributes 'readonly' and 'readwrite' are mutually exclusive}}
-@property(retain) int p1; // expected-error {{property with 'retain' attribute must be of object type}}
+@property(retain) int p1; // expected-error {{property with 'retain (or strong)' attribute must be of object type}}
+@property(strong) int s1; // expected-error {{property with 'retain (or strong)' attribute must be of object type}}
@property(copy) int p2; // expected-error {{property with 'copy' attribute must be of object type}}
@property(assign, copy) id p3_0; // expected-error {{property attributes 'assign' and 'copy' are mutually exclusive}}
@property(assign, retain) id p3_1; // expected-error {{property attributes 'assign' and 'retain' are mutually exclusive}}
+@property(assign, strong) id s3_1; // expected-error {{property attributes 'assign' and 'strong' are mutually exclusive}}
@property(copy, retain) id p3_2; // expected-error {{property attributes 'copy' and 'retain' are mutually exclusive}}
+@property(copy, strong) id s3_2; // expected-error {{property attributes 'copy' and 'strong' are mutually exclusive}}
@property(assign, copy, retain) id p3_3; // expected-error {{property attributes 'assign' and 'copy' are mutually exclusive}}, expected-error {{property attributes 'assign' and 'retain' are mutually exclusive}}
+@property(assign, copy, strong) id s3_3; // expected-error {{property attributes 'assign' and 'copy' are mutually exclusive}}, expected-error {{property attributes 'assign' and 'strong' are mutually exclusive}}
+
+@property(unsafe_unretained, copy) id p4_0; // expected-error {{property attributes 'unsafe_unretained' and 'copy' are mutually exclusive}}
+@property(unsafe_unretained, retain) id p4_1; // expected-error {{property attributes 'unsafe_unretained' and 'retain' are mutually exclusive}}
+@property(unsafe_unretained, strong) id s4_1; // expected-error {{property attributes 'unsafe_unretained' and 'strong' are mutually exclusive}}
+@property(unsafe_unretained, copy, retain) id p4_3; // expected-error {{property attributes 'unsafe_unretained' and 'copy' are mutually exclusive}}, expected-error {{property attributes 'unsafe_unretained' and 'retain' are mutually exclusive}}
+@property(unsafe_unretained, copy, strong) id s4_3; // expected-error {{property attributes 'unsafe_unretained' and 'copy' are mutually exclusive}}, expected-error {{property attributes 'unsafe_unretained' and 'strong' are mutually exclusive}}
@property id p4; // expected-warning {{no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed}}, expected-warning {{default property attribute 'assign' not appropriate for non-gc object}}
@@ -22,7 +32,8 @@
@end
@interface I0()
-@property (retain) int PROP; // expected-error {{property with 'retain' attribute must be of object type}}
+@property (retain) int PROP; // expected-error {{property with 'retain (or strong)' attribute must be of object type}}
+@property (strong) int SPROP; // expected-error {{property with 'retain (or strong)' attribute must be of object type}}
@property(nonatomic,copy) int (*PROP1)(); // expected-error {{property with 'copy' attribute must be of object type}}
+@property(nonatomic,weak) int (*PROP2)(); // expected-error {{property with 'weak' attribute must be of object type}}
@end
-
diff --git a/test/SemaObjC/property-inherited.m b/test/SemaObjC/property-inherited.m
index 5c5631e..11ef2be 100644
--- a/test/SemaObjC/property-inherited.m
+++ b/test/SemaObjC/property-inherited.m
@@ -1,6 +1,8 @@
// RUN: %clang_cc1 %s -fsyntax-only -verify
+// RUN: %clang_cc1 -x objective-c++ %s -fsyntax-only -verify
-// <rdar://problem/6497242> Inherited overridden protocol declared objects don't work
+// rdar://6497242 Inherited overridden protocol declared objects don't work
+// rdar://9740328 Case for c++
@protocol NSObject @end
@interface NSObject @end
diff --git a/test/SemaObjC/property-ns-returns-not-retained-attr.m b/test/SemaObjC/property-ns-returns-not-retained-attr.m
new file mode 100644
index 0000000..187c93f
--- /dev/null
+++ b/test/SemaObjC/property-ns-returns-not-retained-attr.m
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -verify %s
+// rdar://9636091
+
+@interface I
+@property (nonatomic, retain) id newName __attribute__((ns_returns_not_retained)) ;
+
+@property (nonatomic, retain) id newName1 __attribute__((ns_returns_not_retained)) ;
+- (id) newName1 __attribute__((ns_returns_not_retained));
+
+@property (nonatomic, retain) id newName2 __attribute__((ns_returns_not_retained)); // expected-note {{roperty declared here}}
+- (id) newName2; // expected-warning {{property declared as returning non-retained objects; getter returning retained objects}}
+@end
+
+@implementation I
+@synthesize newName;
+
+@synthesize newName1;
+- (id) newName1 { return 0; }
+
+@synthesize newName2;
+@end
diff --git a/test/SemaObjC/related-result-type-inference.m b/test/SemaObjC/related-result-type-inference.m
index f539918..094f19a 100644
--- a/test/SemaObjC/related-result-type-inference.m
+++ b/test/SemaObjC/related-result-type-inference.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fobjc-infer-related-result-type -verify %s
+// RUN: %clang_cc1 -verify %s
@interface Unrelated
@end
diff --git a/test/SemaObjC/selector-3.m b/test/SemaObjC/selector-3.m
index 69a74f8..b248a5d 100644
--- a/test/SemaObjC/selector-3.m
+++ b/test/SemaObjC/selector-3.m
@@ -27,3 +27,28 @@ SEL func()
{
return @selector(length); // expected-warning {{unimplemented selector 'length'}}
}
+
+// rdar://9545564
+@class MSPauseManager;
+
+@protocol MSPauseManagerDelegate
+@optional
+- (void)pauseManagerDidPause:(MSPauseManager *)manager;
+- (int)respondsToSelector:(SEL)aSelector;
+@end
+
+@interface MSPauseManager
+{
+ id<MSPauseManagerDelegate> _delegate;
+}
+@end
+
+
+@implementation MSPauseManager
+- (id) Meth {
+ if ([_delegate respondsToSelector:@selector(pauseManagerDidPause:)])
+ return 0;
+ return 0;
+}
+@end
+
diff --git a/test/SemaObjC/self-declared-in-block.m b/test/SemaObjC/self-declared-in-block.m
index 4bd7202..2131095 100644
--- a/test/SemaObjC/self-declared-in-block.m
+++ b/test/SemaObjC/self-declared-in-block.m
@@ -7,11 +7,12 @@
@implementation Blocky {
int _a;
}
-- (void)doAThing {
+- (int)doAThing {
^{
- char self; // expected-note {{declared here}}
- _a; // expected-error {{instance variable '_a' cannot be accessed because 'self' has been redeclared}}
+ char self;
+ return _a;
}();
+ return _a;
}
@end
@@ -37,14 +38,14 @@
(void)_anIvar;
}
{
- C* self; // expected-note {{declared here}}
- (void) _anIvar; // expected-error {{instance variable '_anIvar' cannot be accessed because 'self' has been redeclared}}
+ C* self;
+ (void) _anIvar;
}
}
- (void)doAThing {
^{
- id self; // expected-note {{declared here}}
- (void)_anIvar; // expected-error {{instance variable '_anIvar' cannot be accessed because 'self' has been redeclared}}
+ id self;
+ (void)_anIvar;
}();
}
@end
diff --git a/test/SemaObjC/sizeof-interface.m b/test/SemaObjC/sizeof-interface.m
index 3fe3964..65c8e49 100644
--- a/test/SemaObjC/sizeof-interface.m
+++ b/test/SemaObjC/sizeof-interface.m
@@ -7,7 +7,7 @@ int g0 = sizeof(I0); // expected-error{{invalid application of 'sizeof' to an in
// rdar://6821047
void *g3(I0 *P) {
- P = P+5; // expected-error {{arithmetic on pointer to incomplete type 'I0 *'}}
+ P = P+5; // expected-error {{arithmetic on a pointer to an incomplete type 'I0'}}
return &P[4]; // expected-error{{subscript of pointer to incomplete type 'I0'}}
}
diff --git a/test/SemaObjC/special-dep-unavail-warning.m b/test/SemaObjC/special-dep-unavail-warning.m
index 1d07a49..57a2fa3 100644
--- a/test/SemaObjC/special-dep-unavail-warning.m
+++ b/test/SemaObjC/special-dep-unavail-warning.m
@@ -3,24 +3,24 @@
@interface B
- (void) depInA;
-- (void) unavailMeth __attribute__((unavailable)); // expected-note {{function has been explicitly marked unavailable here}}
+- (void) unavailMeth __attribute__((unavailable)); // expected-note {{has been explicitly marked unavailable here}}
- (void) depInA1 __attribute__((deprecated));
- (void) unavailMeth1;
- (void) depInA2 __attribute__((deprecated));
-- (void) unavailMeth2 __attribute__((unavailable)); // expected-note {{function has been explicitly marked unavailable here}}
+- (void) unavailMeth2 __attribute__((unavailable)); // expected-note {{has been explicitly marked unavailable here}}
- (void) depunavailInA;
-- (void) depunavailInA1 __attribute__((deprecated)) __attribute__((unavailable)); // expected-note {{function has been explicitly marked unavailable here}}
+- (void) depunavailInA1 __attribute__((deprecated)) __attribute__((unavailable)); // expected-note {{has been explicitly marked unavailable here}}
- (void)FuzzyMeth __attribute__((deprecated));
- (void)FuzzyMeth1 __attribute__((unavailable));
@end
@interface A
-- (void) unavailMeth1 __attribute__((unavailable)); // expected-note {{function has been explicitly marked unavailable here}}
+- (void) unavailMeth1 __attribute__((unavailable)); // expected-note {{has been explicitly marked unavailable here}}
- (void) depInA __attribute__((deprecated));
- (void) depInA2 __attribute__((deprecated));
- (void) depInA1;
- (void) unavailMeth2 __attribute__((unavailable));
-- (void) depunavailInA __attribute__((deprecated)) __attribute__((unavailable)); // expected-note {{function has been explicitly marked unavailable here}}
+- (void) depunavailInA __attribute__((deprecated)) __attribute__((unavailable)); // expected-note {{has been explicitly marked unavailable here}}
- (void) depunavailInA1;
- (void)FuzzyMeth __attribute__((unavailable));
- (void)FuzzyMeth1 __attribute__((deprecated));
diff --git a/test/SemaObjC/synthesized-ivar.m b/test/SemaObjC/synthesized-ivar.m
index 3bc372b..4786d80 100644
--- a/test/SemaObjC/synthesized-ivar.m
+++ b/test/SemaObjC/synthesized-ivar.m
@@ -51,3 +51,11 @@ int f0(I *a) { return a->IP; } // expected-error {{instance variable 'IP' is pri
}
@end
+@interface A
+@property (weak) id testObjectWeakProperty; // expected-note {{declared here}}
+@end
+
+@implementation A
+// rdar://9605088
+@synthesize testObjectWeakProperty; // expected-error {{@synthesize of 'weak' property is only allowed in ARC or GC mode}}
+@end
diff --git a/test/SemaObjC/typedef-class.m b/test/SemaObjC/typedef-class.m
index 0f7e682..c983195 100644
--- a/test/SemaObjC/typedef-class.m
+++ b/test/SemaObjC/typedef-class.m
@@ -5,7 +5,7 @@ typedef struct _NSZone NSZone;
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
-@protocol NSObject - (BOOL) isEqual:(id) object; @end
+@protocol NSObject - (BOOL) isEqual:(id) object; - (id)init; @end
@protocol NSCopying - (id) copyWithZone:(NSZone *) zone; @end
@protocol NSCoding - (void) encodeWithCoder:(NSCoder *) aCoder; @end
diff --git a/test/SemaObjC/undef-superclass-1.m b/test/SemaObjC/undef-superclass-1.m
index c941f82..41cf143 100644
--- a/test/SemaObjC/undef-superclass-1.m
+++ b/test/SemaObjC/undef-superclass-1.m
@@ -1,8 +1,8 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-@class SUPER, Y;
+@class SUPER, Y; // expected-note 2 {{forward class is declared here}}
-@interface INTF :SUPER // expected-error {{cannot find interface declaration for 'SUPER', superclass of 'INTF'}}
+@interface INTF :SUPER // expected-error {{attempting to use the forward class 'SUPER' as superclass of 'INTF'}}
@end
@interface SUPER @end
@@ -13,7 +13,7 @@
@interface INTF2 : INTF1
@end
-@interface INTF3 : Y // expected-error {{cannot find interface declaration for 'Y', superclass of 'INTF3'}} \
+@interface INTF3 : Y // expected-error {{attempting to use the forward class 'Y' as superclass of 'INTF3'}} \
// expected-note{{'INTF3' declared here}}
@end
diff --git a/test/SemaObjC/warn-retain-cycle.m b/test/SemaObjC/warn-retain-cycle.m
new file mode 100644
index 0000000..71385b8
--- /dev/null
+++ b/test/SemaObjC/warn-retain-cycle.m
@@ -0,0 +1,91 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fobjc-arc -fblocks -verify %s
+
+@interface Test0
+- (void) setBlock: (void(^)(void)) block;
+- (void) addBlock: (void(^)(void)) block;
+- (void) actNow;
+@end
+void test0(Test0 *x) {
+ [x setBlock: // expected-note {{block will be retained by the captured object}}
+ ^{ [x actNow]; }]; // expected-warning {{capturing 'x' strongly in this block is likely to lead to a retain cycle}}
+ x.block = // expected-note {{block will be retained by the captured object}}
+ ^{ [x actNow]; }; // expected-warning {{capturing 'x' strongly in this block is likely to lead to a retain cycle}}
+
+ [x addBlock: // expected-note {{block will be retained by the captured object}}
+ ^{ [x actNow]; }]; // expected-warning {{capturing 'x' strongly in this block is likely to lead to a retain cycle}}
+
+ // These actually don't cause retain cycles.
+ __weak Test0 *weakx = x;
+ [x addBlock: ^{ [weakx actNow]; }];
+ [x setBlock: ^{ [weakx actNow]; }];
+ x.block = ^{ [weakx actNow]; };
+
+ // These do cause retain cycles, but we're not clever enough to figure that out.
+ [weakx addBlock: ^{ [x actNow]; }];
+ [weakx setBlock: ^{ [x actNow]; }];
+ weakx.block = ^{ [x actNow]; };
+}
+
+@interface BlockOwner
+@property (retain) void (^strong)(void);
+@end
+
+@interface Test1 {
+@public
+ BlockOwner *owner;
+};
+@property (retain) BlockOwner *owner;
+@property (assign) __strong BlockOwner *owner2; // expected-error {{unsafe_unretained property 'owner2' may not also be declared __strong}}
+@property (assign) BlockOwner *owner3;
+@end
+void test1(Test1 *x) {
+ x->owner.strong = ^{ (void) x; }; // expected-warning {{retain cycle}} expected-note {{block will be retained by an object strongly retained by the captured object}}
+ x.owner.strong = ^{ (void) x; }; // expected-warning {{retain cycle}} expected-note {{block will be retained by an object strongly retained by the captured object}}
+ x.owner2.strong = ^{ (void) x; };
+ x.owner3.strong = ^{ (void) x; };
+}
+
+@implementation Test1 {
+ BlockOwner * __unsafe_unretained owner3ivar;
+ __weak BlockOwner *weakowner;
+}
+@dynamic owner;
+@dynamic owner2;
+@synthesize owner3 = owner3ivar;
+
+- (id) init {
+ self.owner.strong = ^{ (void) owner; }; // expected-warning {{retain cycle}} expected-note {{block will be retained by an object strongly retained by the captured object}}
+ self.owner2.strong = ^{ (void) owner; };
+
+ // TODO: should we warn here? What's the story with this kind of mismatch?
+ self.owner3.strong = ^{ (void) owner; };
+
+ owner.strong = ^{ (void) owner; }; // expected-warning {{retain cycle}} expected-note {{block will be retained by an object strongly retained by the captured object}}
+
+ owner.strong = ^{ ^{ (void) owner; }(); }; // expected-warning {{retain cycle}} expected-note {{block will be retained by an object strongly retained by the captured object}}
+
+ owner.strong = ^{ (void) sizeof(self); // expected-note {{block will be retained by an object strongly retained by the captured object}}
+ (void) owner; }; // expected-warning {{capturing 'self' strongly in this block is likely to lead to a retain cycle}}
+
+ weakowner.strong = ^{ (void) owner; };
+
+ return self;
+}
+- (void) foo {
+ owner.strong = ^{ (void) owner; }; // expected-warning {{retain cycle}} expected-note {{block will be retained by an object strongly retained by the captured object}}
+}
+@end
+
+void test2_helper(id);
+@interface Test2 {
+ void (^block)(void);
+ id x;
+}
+@end
+@implementation Test2
+- (void) test {
+ block = ^{ // expected-note {{block will be retained by an object strongly retained by the captured object}}
+ test2_helper(x); // expected-warning {{capturing 'self' strongly in this block is likely to lead to a retain cycle}}
+ };
+}
+@end
diff --git a/test/SemaObjC/weak-property.m b/test/SemaObjC/weak-property.m
new file mode 100644
index 0000000..f000607
--- /dev/null
+++ b/test/SemaObjC/weak-property.m
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fobjc-arc -verify %s
+// rdar://8899430
+
+@interface WeakPropertyTest {
+ Class isa;
+ __weak id value;
+ id x;
+}
+@property (weak) id value1;
+@property __weak id value;
+@property () __weak id value2;
+
+@property (weak, assign) id v1; // expected-error {{property attributes 'assign' and 'weak' are mutually exclusive}}
+@property (weak, copy) id v2; // expected-error {{property attributes 'copy' and 'weak' are mutually exclusive}}
+@property (weak, retain) id v3; // expected-error {{property attributes 'retain' and 'weak' are mutually exclusive}}
+@property (weak, assign) id v4; // expected-error {{property attributes 'assign' and 'weak' are mutually exclusive}}
+
+@property () __weak id x; // expected-note {{property declared here}}
+@end
+
+@implementation WeakPropertyTest
+@synthesize x; // expected-error {{existing ivar 'x' for __weak property 'x' must be __weak}}
+@dynamic value1, value, value2, v1,v2,v3,v4;
+@end
OpenPOWER on IntegriCloud