1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LLVM_LICENSE_HEADER@
5 */
6
7/*
8  TEST_CONFIG SDK=macosx MEM=gc
9  TEST_CFLAGS -framework Foundation
10 */
11
12#import <objc/objc-auto.h>
13#import <Foundation/Foundation.h>
14#import "test.h"
15
16int GlobalInt = 0;
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21id objc_assign_global(id val __unused, id *dest __unused) {
22    GlobalInt = 1;
23    return (id)0;
24}
25
26id objc_assign_ivar(id val __unused, id dest __unused, ptrdiff_t offset __unused) {
27    GlobalInt = 1;
28    return (id)0;
29}
30
31id objc_assign_strongCast(id val __unused, id *dest __unused) {
32    GlobalInt = 0;
33    return (id)0;
34}
35#ifdef __cplusplus
36}
37#endif
38
39@interface TestObject : NSObject {
40@public
41    void (^ivarBlock)(void);
42    id x;
43}
44@end
45
46@implementation TestObject
47@end
48
49
50int main() {
51   __block int i = 0;
52   TestObject *to = [[TestObject alloc] init];
53   // assigning a Block into an ivar should elicit a  write-barrier under GC
54   to->ivarBlock =  ^ {  ++i; };		// fails to gen write-barrier
55   //to->x = to;				// gens write-barrier
56   if (GlobalInt != 1) {
57       fail("missing ivar write-barrier for Block");
58   }
59
60   succeed(__FILE__);
61}
62
63