Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / BlocksRuntime / recursive-test.c
blob473bdefbda5b41a7e411169d6e65e14749f0a115
1 //
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
7 // was rdar://5847976
8 // was rdar://6348320
10 #include <stdio.h>
11 #include <Block.h>
13 int verbose = 0;
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);
24 if (i > 0) {
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);
41 other_local_block(5);
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);
49 });
51 if (verbose) printf("other_copied_block's address is %p, running it:\n", (void*)other_copied_block);
53 other_copied_block(5);
54 #endif
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);
62 if (i > 0) {
63 recursive_copy_block(i - 1);
65 });
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]);
72 return 0;