2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 // CONFIG open rdar://6416474
15 int main(int argc
, char* argv
[]) {
17 if (argc
> 1) verbose
= 1;
19 __block
void (^recursive_local_block
)(int);
21 if (verbose
) printf("recursive_local_block is a local recursive block\n");
22 recursive_local_block
= ^(int i
) {
23 if (verbose
) printf("%d\n", i
);
25 recursive_local_block(i
- 1);
29 if (verbose
) printf("recursive_local_block's address is %p, running it:\n", (void*)recursive_local_block
);
30 recursive_local_block(5);
32 if (verbose
) printf("Creating other_local_block: a local block that calls recursive_local_block\n");
34 void (^other_local_block
)(int) = ^(int i
) {
35 if (verbose
) printf("other_local_block running\n");
36 recursive_local_block(i
);
39 if (verbose
) printf("other_local_block's address is %p, running it:\n", (void*)other_local_block
);
43 #if __APPLE_CC__ >= 5627
44 if (verbose
) printf("Creating other_copied_block: a Block_copy of a block that will call recursive_local_block\n");
46 void (^other_copied_block
)(int) = Block_copy(^(int i
) {
47 if (verbose
) printf("other_copied_block running\n");
48 recursive_local_block(i
);
51 if (verbose
) printf("other_copied_block's address is %p, running it:\n", (void*)other_copied_block
);
53 other_copied_block(5);
56 __block
void (^recursive_copy_block
)(int);
58 if (verbose
) printf("Creating recursive_copy_block: a Block_copy of a block that will call recursive_copy_block recursively\n");
60 recursive_copy_block
= Block_copy(^(int i
) {
61 if (verbose
) printf("%d\n", i
);
63 recursive_copy_block(i
- 1);
67 if (verbose
) printf("recursive_copy_block's address is %p, running it:\n", (void*)recursive_copy_block
);
69 recursive_copy_block(5);
71 printf("%s: Success\n", argv
[0]);