blob: 454ad48267df7b2d448919c2439c09fa683c4dfd [file] [log] [blame]
Blaine Garst86d0ba42010-08-04 23:34:21 +00001//
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#include <stdio.h>
8#include <Block.h>
9#include <Block_private.h>
10#include <stdlib.h>
11
12// CONFIG
13
14
15int cumulation = 0;
16
17int doSomething(int i) {
18 cumulation += i;
19 return cumulation;
20}
21
22void dirtyStack() {
23 int i = random();
24 int j = doSomething(i);
25 int k = doSomething(j);
26 doSomething(i + j + k);
27}
28
29typedef void (^voidVoid)(void);
30
31voidVoid 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();
38 };
39 //printf("outer looks like: %s\n", _Block_dump(outer));
40 voidVoid result = Block_copy(outer);
41 //Block_release(inner);
42 return result;
43}
44
45
46int main(int argc, char **argv) {
47 voidVoid block = testFunction();
48 dirtyStack();
49 block();
50 Block_release(block);
51
52 printf("%s: success\n", argv[0]);
53
54 return 0;
55}