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 rdar://6255170
8 
9 #include <stdio.h>
10 #include <stdbool.h>
11 #include <stdlib.h>
12 #include <Block.h>
13 #include <Block_private.h>
14 #include <assert.h>
15 
16 
17 int
main(int argc,char * argv[])18 main(int argc, char *argv[])
19 {
20     __block int var = 0;
21     int shouldbe = 0;
22     void (^b)(void) = ^{ var++; /*printf("var is at %p with value %d\n", &var, var);*/ };
23     __typeof(b) _b;
24     //printf("before copy...\n");
25     b(); ++shouldbe;
26     size_t i;
27 
28     for (i = 0; i < 10; i++) {
29             _b = Block_copy(b); // make a new copy each time
30             assert(_b);
31             ++shouldbe;
32             _b();               // should still update the stack
33             Block_release(_b);
34     }
35 
36     //printf("after...\n");
37     b(); ++shouldbe;
38 
39     if (var != shouldbe) {
40         printf("Hmm, var is %d but should be %d\n", var, shouldbe);
41         return 1;
42     }
43     printf("%s: Success!!\n", argv[0]);
44 
45     return 0;
46 }
47