1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LLVM_LICENSE_HEADER@
5 */
6
7// TEST_CONFIG SDK=macosx MEM=gc
8
9#import <stdio.h>
10#import <stdlib.h>
11#import <objc/objc-auto.h>
12#import "test.h"
13
14int GlobalInt = 0;
15int GlobalInt2 = 0;
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20id objc_assign_weak(id value, id *location) {
21    GlobalInt = 1;
22    *location = value;
23    return value;
24}
25
26id objc_read_weak(id *location) {
27    GlobalInt2 = 1;
28    return *location;
29}
30#ifdef __cplusplus
31}
32#endif
33
34
35void (^__weak Henry)(void);
36
37int main() {
38    // an object should not be retained within a stack Block
39    void (^local)(void);
40    __block int i = 10;
41    Henry = ^ {  ++i; };
42    local = Henry;
43    if (GlobalInt2 != 1) {
44        fail("problem with weak read barrier of global block");
45    }
46
47    succeed(__FILE__);
48}
49
50