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 */
10
11#import <stdio.h>
12#import <stdlib.h>
13#import <objc/objc-auto.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 = 0;
28    return (id)0;
29}
30
31id objc_assign_strongCast(id val __unused, id *dest __unused) {
32    GlobalInt = 1;
33    return (id)0;
34}
35
36#ifdef __cplusplus
37}
38#endif
39
40typedef struct {
41    void (^ivarBlock)(void);
42} StructWithBlock_t;
43
44
45int main() {
46   StructWithBlock_t *swbp = (StructWithBlock_t *)malloc(sizeof(StructWithBlock_t*));
47   __block int i = 10;
48   // assigning a Block into an struct slot should elicit a write-barrier under GC
49   swbp->ivarBlock = ^ { ++i; };
50   if (GlobalInt != 1) {
51       fail("missing strong cast write-barrier for Block");
52   }
53
54   succeed(__FILE__);
55}
56
57