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;
17int GlobalInt2 = 0;
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22id objc_assign_weak(id value, id *location) {
23    GlobalInt = 1;
24    *location = value;
25    return value;
26}
27
28id objc_read_weak(id *location) {
29    GlobalInt2 = 1;
30    return *location;
31}
32#ifdef __cplusplus
33}
34#endif
35
36void (^__weak Henry)(void);
37
38int main() {
39    __block int i = 0;
40    Henry = ^ {  ++i; };
41    if (GlobalInt != 1) {
42        fail("problem with weak write-barrier assignment of global block");
43    }
44
45    succeed(__FILE__);
46}
47
48