Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / BlocksRuntime / recursive-block.c
bloba93ceb6a780a868871f33288d6600c72046f79f0
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 #include <stdio.h>
7 #include <Block.h>
8 #include <Block_private.h>
9 #include <stdlib.h>
11 // CONFIG
14 int cumulation = 0;
16 int doSomething(int i) {
17 cumulation += i;
18 return cumulation;
21 void dirtyStack() {
22 int i = random();
23 int j = doSomething(i);
24 int k = doSomething(j);
25 doSomething(i + j + k);
28 typedef void (^voidVoid)(void);
30 voidVoid testFunction() {
31 int i = random();
32 __block voidVoid inner = ^{ doSomething(i); };
33 //printf("inner, on stack, is %p\n", (void*)inner);
34 /*__block*/ voidVoid outer = ^{
35 //printf("will call inner block %p\n", (void *)inner);
36 inner();
38 //printf("outer looks like: %s\n", _Block_dump(outer));
39 voidVoid result = Block_copy(outer);
40 //Block_release(inner);
41 return result;
45 int main(int argc, char **argv) {
46 voidVoid block = testFunction();
47 dirtyStack();
48 block();
49 Block_release(block);
51 printf("%s: success\n", argv[0]);
53 return 0;