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
36@interface Foo : NSObject {
37@public
38    void (^__weak ivar)(void);
39}
40@end
41@implementation Foo
42@end
43
44int main() {
45    // an object should not be retained within a stack Block
46    __block int i = 0;
47    Foo *foo = [[Foo alloc] init];
48    foo->ivar = ^ {  ++i; };
49    if (GlobalInt != 1) {
50        fail("problem with weak write-barrier assignment of ivar");
51    }
52
53    succeed(__FILE__);
54}
55
56