xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/blocks-1.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -emit-llvm -o %t -fblocks
2*f4a2713aSLionel Sambuc // RUN: grep "_Block_object_dispose" %t | count 17
3*f4a2713aSLionel Sambuc // RUN: grep "__copy_helper_block_" %t | count 14
4*f4a2713aSLionel Sambuc // RUN: grep "__destroy_helper_block_" %t | count 14
5*f4a2713aSLionel Sambuc // RUN: grep "__Block_byref_object_copy_" %t | count 2
6*f4a2713aSLionel Sambuc // RUN: grep "__Block_byref_object_dispose_" %t | count 2
7*f4a2713aSLionel Sambuc // RUN: grep "i32 135)" %t | count 2
8*f4a2713aSLionel Sambuc // RUN: grep "_Block_object_assign" %t | count 10
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc int printf(const char *, ...);
11*f4a2713aSLionel Sambuc 
test1()12*f4a2713aSLionel Sambuc void test1() {
13*f4a2713aSLionel Sambuc   __block int a;
14*f4a2713aSLionel Sambuc   int b=2;
15*f4a2713aSLionel Sambuc   a=1;
16*f4a2713aSLionel Sambuc   printf("a is %d, b is %d\n", a, b);
17*f4a2713aSLionel Sambuc   ^{ a = 10; printf("a is %d, b is %d\n", a, b); }(); // needs copy/dispose
18*f4a2713aSLionel Sambuc   printf("a is %d, b is %d\n", a, b);
19*f4a2713aSLionel Sambuc   a = 1;
20*f4a2713aSLionel Sambuc   printf("a is %d, b is %d\n", a, b);
21*f4a2713aSLionel Sambuc }
22*f4a2713aSLionel Sambuc 
test2()23*f4a2713aSLionel Sambuc void test2() {
24*f4a2713aSLionel Sambuc   __block int a;
25*f4a2713aSLionel Sambuc   a=1;
26*f4a2713aSLionel Sambuc   printf("a is %d\n", a);
27*f4a2713aSLionel Sambuc   ^{ // needs copy/dispose
28*f4a2713aSLionel Sambuc     ^{ // needs copy/dispose
29*f4a2713aSLionel Sambuc       a = 10;
30*f4a2713aSLionel Sambuc     }();
31*f4a2713aSLionel Sambuc   }();
32*f4a2713aSLionel Sambuc   printf("a is %d\n", a);
33*f4a2713aSLionel Sambuc   a = 1;
34*f4a2713aSLionel Sambuc   printf("a is %d\n", a);
35*f4a2713aSLionel Sambuc }
36*f4a2713aSLionel Sambuc 
test3()37*f4a2713aSLionel Sambuc void test3() {
38*f4a2713aSLionel Sambuc   __block int k;
39*f4a2713aSLionel Sambuc   __block int (^j)(int);
40*f4a2713aSLionel Sambuc   ^{j=0; k=0;}(); // needs copy/dispose
41*f4a2713aSLionel Sambuc }
42*f4a2713aSLionel Sambuc 
test4()43*f4a2713aSLionel Sambuc int test4() {
44*f4a2713aSLionel Sambuc   extern int g;
45*f4a2713aSLionel Sambuc   static int i = 1;
46*f4a2713aSLionel Sambuc   ^(int j){ i = j; g = 0; }(0); // does not need copy/dispose
47*f4a2713aSLionel Sambuc   return i + g;
48*f4a2713aSLionel Sambuc }
49*f4a2713aSLionel Sambuc 
50*f4a2713aSLionel Sambuc int g;
51*f4a2713aSLionel Sambuc 
test5()52*f4a2713aSLionel Sambuc void test5() {
53*f4a2713aSLionel Sambuc   __block struct { int i; } i;
54*f4a2713aSLionel Sambuc   ^{ (void)i; }(); // needs copy/dispose
55*f4a2713aSLionel Sambuc }
56*f4a2713aSLionel Sambuc 
test6()57*f4a2713aSLionel Sambuc void test6() {
58*f4a2713aSLionel Sambuc   __block int i;
59*f4a2713aSLionel Sambuc   ^{ i=1; }(); // needs copy/dispose
60*f4a2713aSLionel Sambuc   ^{}(); // does not need copy/dispose
61*f4a2713aSLionel Sambuc }
62*f4a2713aSLionel Sambuc 
test7()63*f4a2713aSLionel Sambuc void test7() {
64*f4a2713aSLionel Sambuc   ^{ // does not need copy/dispose
65*f4a2713aSLionel Sambuc     __block int i;
66*f4a2713aSLionel Sambuc     ^{ i = 1; }(); // needs copy/dispose
67*f4a2713aSLionel Sambuc   }();
68*f4a2713aSLionel Sambuc }
69*f4a2713aSLionel Sambuc 
main()70*f4a2713aSLionel Sambuc int main() {
71*f4a2713aSLionel Sambuc   int rv = 0;
72*f4a2713aSLionel Sambuc   test1();
73*f4a2713aSLionel Sambuc   test2();
74*f4a2713aSLionel Sambuc   test3();
75*f4a2713aSLionel Sambuc   rv += test4();
76*f4a2713aSLionel Sambuc   test5();
77*f4a2713aSLionel Sambuc   return rv;
78*f4a2713aSLionel Sambuc }
79