1 // TEST_CFLAGS -Os -framework Foundation
2 // TEST_DISABLED pending clang support for rdar://20530049
11 // no optimization on i386 (neither Mac nor Simulator)
17 #include <objc/objc-internal.h>
18 #include <objc/objc-abi.h>
19 #include <Foundation/Foundation.h>
21 @interface TestObject : TestRoot @end
22 @implementation TestObject @end
26 # define MAGIC asm volatile("mov r7, r7")
27 # define NOT_MAGIC asm volatile("mov r6, r6")
29 # define MAGIC asm volatile("mov x29, x29")
30 # define NOT_MAGIC asm volatile("mov x28, x28")
32 # define MAGIC asm volatile("")
33 # define NOT_MAGIC asm volatile("nop")
35 # error unknown architecture
39 @interface Tester : NSObject @end
40 @implementation Tester {
58 objc_retainAutoreleasedReturnValue(id obj)
59 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0);
61 // Accept a value returned through a +0 autoreleasing convention for use at +0.
64 objc_unsafeClaimAutoreleasedReturnValue(id obj)
65 __OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0);
72 Tester *tt = [Tester new];
75 // need to get DYLD to resolve the stubs on x86
77 TestObject *warm_up = [[TestObject alloc] init];
79 warm_up = objc_retainAutoreleasedReturnValue(warm_up);
80 warm_up = objc_unsafeClaimAutoreleasedReturnValue(warm_up);
85 testprintf(" Successful +1 -> +1 handshake\n");
88 obj = [[TestObject alloc] init];
95 TestRootAutorelease = 0;
98 TestObject *tmp = [tt return1];
100 testassert(TestRootDealloc == 0);
101 testassert(TestRootRetain == 1);
102 testassert(TestRootRelease == 0);
103 testassert(TestRootAutorelease == 0);
106 testassert(TestRootDealloc == 0);
107 testassert(TestRootRetain == 1);
108 testassert(TestRootRelease == 1);
109 testassert(TestRootAutorelease == 0);
112 testassert(TestRootDealloc == 1);
113 testassert(TestRootRetain == 1);
114 testassert(TestRootRelease == 2);
115 testassert(TestRootAutorelease == 0);
119 testprintf(" Successful +0 -> +0 handshake\n");
122 obj = [[TestObject alloc] init];
129 TestRootAutorelease = 0;
132 __unsafe_unretained TestObject *tmp = [tt return0];
134 testassert(TestRootDealloc == 0);
135 testassert(TestRootRetain == 0);
136 testassert(TestRootRelease == 0);
137 testassert(TestRootAutorelease == 0);
140 testassert(TestRootDealloc == 0);
141 testassert(TestRootRetain == 0);
142 testassert(TestRootRelease == 0);
143 testassert(TestRootAutorelease == 0);
146 testassert(TestRootDealloc == 1);
147 testassert(TestRootRetain == 0);
148 testassert(TestRootRelease == 1);
149 testassert(TestRootAutorelease == 0);
154 testprintf(" Successful +1 -> +0 handshake\n");
157 obj = [[TestObject alloc] init];
164 TestRootAutorelease = 0;
167 __unsafe_unretained TestObject *tmp = [tt return1];
169 testassert(TestRootDealloc == 0);
170 testassert(TestRootRetain == 1);
171 testassert(TestRootRelease == 1);
172 testassert(TestRootAutorelease == 0);
175 testassert(TestRootDealloc == 0);
176 testassert(TestRootRetain == 1);
177 testassert(TestRootRelease == 1);
178 testassert(TestRootAutorelease == 0);
181 testassert(TestRootDealloc == 1);
182 testassert(TestRootRetain == 1);
183 testassert(TestRootRelease == 2);
184 testassert(TestRootAutorelease == 0);
189 testprintf(" Successful +0 -> +1 handshake\n");
192 obj = [[TestObject alloc] init];
199 TestRootAutorelease = 0;
202 TestObject *tmp = [tt return0];
204 testassert(TestRootDealloc == 0);
205 testassert(TestRootRetain == 1);
206 testassert(TestRootRelease == 0);
207 testassert(TestRootAutorelease == 0);
210 testassert(TestRootDealloc == 0);
211 testassert(TestRootRetain == 1);
212 testassert(TestRootRelease == 1);
213 testassert(TestRootAutorelease == 0);
216 testassert(TestRootDealloc == 1);
217 testassert(TestRootRetain == 1);
218 testassert(TestRootRelease == 2);
219 testassert(TestRootAutorelease == 0);