[Sanitizer] Add rudimentary support for wide-character strings to scanf/printf interc...
[blocksruntime.git] / test / BlocksRuntime / recursive-block.c
blob454ad48267df7b2d448919c2439c09fa683c4dfd
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.
7 #include <stdio.h>
8 #include <Block.h>
9 #include <Block_private.h>
10 #include <stdlib.h>
12 // CONFIG
15 int cumulation = 0;
17 int doSomething(int i) {
18 cumulation += i;
19 return cumulation;
22 void dirtyStack() {
23 int i = random();
24 int j = doSomething(i);
25 int k = doSomething(j);
26 doSomething(i + j + k);
29 typedef void (^voidVoid)(void);
31 voidVoid testFunction() {
32 int i = random();
33 __block voidVoid inner = ^{ doSomething(i); };
34 //printf("inner, on stack, is %p\n", (void*)inner);
35 /*__block*/ voidVoid outer = ^{
36 //printf("will call inner block %p\n", (void *)inner);
37 inner();
39 //printf("outer looks like: %s\n", _Block_dump(outer));
40 voidVoid result = Block_copy(outer);
41 //Block_release(inner);
42 return result;
46 int main(int argc, char **argv) {
47 voidVoid block = testFunction();
48 dirtyStack();
49 block();
50 Block_release(block);
52 printf("%s: success\n", argv[0]);
54 return 0;