• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //                     The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 
7 // CONFIG open rdar://6416474
8 // was  rdar://5847976
9 // was  rdar://6348320
10 
11 #include <stdio.h>
12 #include <Block.h>
13 
14 int verbose = 0;
15 
main(int argc,char * argv[])16 int main(int argc, char* argv[]) {
17 
18         if (argc > 1) verbose = 1;
19 
20 	__block void (^recursive_local_block)(int);
21 
22 	if (verbose) printf("recursive_local_block is a local recursive block\n");
23 	recursive_local_block = ^(int i) {
24 		if (verbose) printf("%d\n", i);
25 		if (i > 0) {
26 			recursive_local_block(i - 1);
27 		}
28     };
29 
30 	if (verbose) printf("recursive_local_block's address is %p, running it:\n", (void*)recursive_local_block);
31 	recursive_local_block(5);
32 
33 	if (verbose) printf("Creating other_local_block: a local block that calls recursive_local_block\n");
34 
35 	void (^other_local_block)(int) = ^(int i) {
36 		if (verbose) printf("other_local_block running\n");
37 		recursive_local_block(i);
38     };
39 
40 	if (verbose) printf("other_local_block's address is %p, running it:\n", (void*)other_local_block);
41 
42 	other_local_block(5);
43 
44 #if __APPLE_CC__ >= 5627
45 	if (verbose) printf("Creating other_copied_block: a Block_copy of a block that will call recursive_local_block\n");
46 
47 	void (^other_copied_block)(int) = Block_copy(^(int i) {
48 		if (verbose) printf("other_copied_block running\n");
49 		recursive_local_block(i);
50     });
51 
52 	if (verbose) printf("other_copied_block's address is %p, running it:\n", (void*)other_copied_block);
53 
54 	other_copied_block(5);
55 #endif
56 
57 	__block void (^recursive_copy_block)(int);
58 
59 	if (verbose) printf("Creating recursive_copy_block: a Block_copy of a block that will call recursive_copy_block recursively\n");
60 
61 	recursive_copy_block = Block_copy(^(int i) {
62 		if (verbose) printf("%d\n", i);
63 		if (i > 0) {
64 			recursive_copy_block(i - 1);
65 		}
66     });
67 
68 	if (verbose) printf("recursive_copy_block's address is %p, running it:\n", (void*)recursive_copy_block);
69 
70 	recursive_copy_block(5);
71 
72         printf("%s: Success\n", argv[0]);
73 	return 0;
74 }
75