Automatic Reference Counting.

Language-design credit goes to a lot of people, but I particularly want
to single out Blaine Garst and Patrick Beard for their contributions.

Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself,
in no particular order.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133103 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/SemaObjC/Inputs/arc-system-header.h b/test/SemaObjC/Inputs/arc-system-header.h
new file mode 100644
index 0000000..9e76cd8
--- /dev/null
+++ b/test/SemaObjC/Inputs/arc-system-header.h
@@ -0,0 +1,42 @@
+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
diff --git a/test/SemaObjC/arc-bridged-cast.m b/test/SemaObjC/arc-bridged-cast.m
new file mode 100644
index 0000000..227cce2
--- /dev/null
+++ b/test/SemaObjC/arc-bridged-cast.m
@@ -0,0 +1,40 @@
+// 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(); 
+}
+
+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..c7efde0
--- /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_lifetime(none))) i;
+    void * vp;
+    int i1;
+};
+
+// rdar://9046528
+
+@class NSError;
+
+__autoreleasing id X; // expected-error {{global variables cannot have __autoreleasing lifetime}}
+__autoreleasing NSError *E; // expected-error {{global variables cannot have __autoreleasing lifetime}}
+
+
+extern id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing lifetime}}
+
+void func()
+{
+    id X;
+    static id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing lifetime}}
+    extern id __autoreleasing E; // expected-error {{global variables cannot have __autoreleasing lifetime}}
+
+}
+
+// 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-no-runtime.m b/test/SemaObjC/arc-no-runtime.m
new file mode 100644
index 0000000..0bf7d52
--- /dev/null
+++ b/test/SemaObjC/arc-no-runtime.m
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fobjc-arc -fobjc-nonfragile-abi -fobjc-no-arc-runtime -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..62d07ae
--- /dev/null
+++ b/test/SemaObjC/arc-non-pod-memaccess.m
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify -fblocks -triple x86_64-apple-darwin10.0.0 %s
+// RUN: %clang_cc1 -x objective-c++ -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -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 lifetime-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 lifetime-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 lifetime-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 lifetime-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 lifetime-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 lifetime-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 lifetime-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 lifetime-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 lifetime-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 lifetime-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 lifetime-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 lifetime-qualified type}} \
+                      // expected-note{{explicitly cast the pointer to silence this warning}}
+  memmove(ptr, uip, 17);
+}
diff --git a/test/SemaObjC/arc-property-decl-attrs.m b/test/SemaObjC/arc-property-decl-attrs.m
new file mode 100644
index 0000000..4a661ee
--- /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 -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 lifetime}}
+}
+@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 lifetime}}
+}
+@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 lifetime}}
+}
+@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..c2571a5
--- /dev/null
+++ b/test/SemaObjC/arc-property-lifetime.m
@@ -0,0 +1,112 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -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 lifetime}}
+}
+@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 lifetime}}
+}
+@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 lifetime}}
+}
+@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..641ae1f
--- /dev/null
+++ b/test/SemaObjC/arc-property.m
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -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 lifetime}}
+}
+@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..e635dc0
--- /dev/null
+++ b/test/SemaObjC/arc-system-header.m
@@ -0,0 +1,48 @@
+// 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 lifetime}}
+}
+
+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
diff --git a/test/SemaObjC/arc-type-conversion.m b/test/SemaObjC/arc-type-conversion.m
new file mode 100644
index 0000000..e723a63
--- /dev/null
+++ b/test/SemaObjC/arc-type-conversion.m
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-nonfragile-abi -verify %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 {{pointer to non-const type 'id' with no explicit lifetime}} expected-error {{cast of an Objective-C pointer to '__autoreleasing 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}}
+}
diff --git a/test/SemaObjC/arc-unsafe_unretained.m b/test/SemaObjC/arc-unsafe_unretained.m
new file mode 100644
index 0000000..20ae792
--- /dev/null
+++ b/test/SemaObjC/arc-unsafe_unretained.m
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -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..fa3a061
--- /dev/null
+++ b/test/SemaObjC/arc.m
@@ -0,0 +1,550 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -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-error {{initializing '__strong id *' with an expression of type 'const __unsafe_unretained id *' changes retain/release properties of pointer}}
+  }
+
+  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 lifetime}}
+}
+
+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 lifetime: type is '__strong id'}}
+static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial lifetime: type is '__strong id'}}
+static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial lifetime: type is '__weak id'}}
+static __thread __autoreleasing id test20_autoreleasing; // expected-error {{thread-local variable has non-trivial lifetime: type is '__autoreleasing id'}} expected-error {{global variables cannot have __autoreleasing lifetime}}
+static __thread __unsafe_unretained id test20_unsafe;
+void test20(void) {
+  static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial lifetime: type is '__strong id'}}
+  static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial lifetime: type is '__strong id'}}
+  static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial lifetime: type is '__weak id'}}
+  static __thread __autoreleasing id test20_autoreleasing; // expected-error {{thread-local variable has non-trivial lifetime: type is '__autoreleasing id'}} expected-error {{global variables cannot have __autoreleasing lifetime}}
+  static __thread __unsafe_unretained id test20_unsafe;
+}
+
+// rdar://9310049
+_Bool fn(id obj) {
+    return (_Bool)obj;
+}
+
+// Check casting w/ lifetime 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 lifetime 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 lifetime}}
+
+  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-error {{ARC forbids properties of Objective-C objects with unspecified storage attribute}}
+@property int y;
+@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 {{cannot assign retained object to weak variable}}
+  id __unsafe_unretained u = [Test30 new]; // expected-warning {{cannot assign retained object to unsafe_unretained variable}}
+  id y = [Test30 new];
+  x = [Test30 new]; // expected-warning {{cannot assign retained object to weak variable}}
+  u = [Test30 new]; // expected-warning {{cannot assign 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}}
+}
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-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/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/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/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 @@
 }
 @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/warn-retain-cycle.m b/test/SemaObjC/warn-retain-cycle.m
new file mode 100644
index 0000000..fd69ce2
--- /dev/null
+++ b/test/SemaObjC/warn-retain-cycle.m
@@ -0,0 +1,91 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi -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..3fabac0
--- /dev/null
+++ b/test/SemaObjC/weak-property.m
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1  -fsyntax-only -fobjc-nonfragile-abi -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