1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LLVM_LICENSE_HEADER@
5 */
6
7//
8//  notcopied.m
9//  testObjects
10//
11//  Created by Blaine Garst on 2/12/09.
12//  Copyright 2009 Apple. All rights reserved.
13//
14
15// TEST_CFLAGS -framework Foundation
16
17// rdar://6557292
18// Test that a __block Block variable with a reference to a stack based Block is not copied
19// when a Block referencing the __block Block varible is copied.
20// No magic for __block variables.
21
22#import <stdio.h>
23#import <Block.h>
24#import <Block_private.h>
25#import <Foundation/Foundation.h>
26#import "test.h"
27
28int Retained = 0;
29
30@interface TestObject : NSObject
31@end
32@implementation TestObject
33- (id)retain {
34    Retained = 1;
35    return [super retain];
36}
37@end
38
39
40int main() {
41    TestObject *to = [[TestObject alloc] init];
42    __block void (^someBlock)(void) = ^ { [to self]; };
43    void (^someOtherBlock)(void) = ^ {
44          someBlock();   // reference someBlock.  It shouldn't be copied under the new rules.
45    };
46    someOtherBlock = [someOtherBlock copy];
47    if (Retained != 0) {
48        fail("__block Block was copied when it shouldn't have");
49    }
50
51    succeed(__FILE__);
52}
53