Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / blocks-1.c
blob22046f57ae2d6e858fd74d528a6b56e55ee1c1b0
1 // RUN: %clang_cc1 -triple thumbv7-apple-ios %s -emit-llvm -o %t -fblocks
2 // RUN: grep "_Block_object_dispose" %t | count 12
3 // RUN: grep "__copy_helper_block_" %t | count 9
4 // RUN: grep "__destroy_helper_block_" %t | count 9
5 // RUN: grep "__Block_byref_object_copy_" %t | count 2
6 // RUN: grep "__Block_byref_object_dispose_" %t | count 2
7 // RUN: grep "i32 135)" %t | count 2
8 // RUN: grep "_Block_object_assign" %t | count 5
10 // RUN: %clang_cc1 -triple thumbv7-unknown-windows %s -emit-llvm -o %t -fblocks
11 // RUN: grep "_Block_object_dispose" %t | count 12
12 // RUN: grep "__copy_helper_block_" %t | count 11
13 // RUN: grep "__destroy_helper_block_" %t | count 11
14 // RUN: grep "__Block_byref_object_copy_" %t | count 2
15 // RUN: grep "__Block_byref_object_dispose_" %t | count 2
16 // RUN: grep "i32 135)" %t | count 2
17 // RUN: grep "_Block_object_assign" %t | count 5
19 int printf(const char *, ...);
21 void test1(void) {
22 __block int a;
23 int b=2;
24 a=1;
25 printf("a is %d, b is %d\n", a, b);
26 ^{ a = 10; printf("a is %d, b is %d\n", a, b); }(); // needs copy/dispose
27 printf("a is %d, b is %d\n", a, b);
28 a = 1;
29 printf("a is %d, b is %d\n", a, b);
32 void test2(void) {
33 __block int a;
34 a=1;
35 printf("a is %d\n", a);
36 ^{ // needs copy/dispose
37 ^{ // needs copy/dispose
38 a = 10;
39 }();
40 }();
41 printf("a is %d\n", a);
42 a = 1;
43 printf("a is %d\n", a);
46 void test3(void) {
47 __block int k;
48 __block int (^j)(int);
49 ^{j=0; k=0;}(); // needs copy/dispose
52 int test4(void) {
53 extern int g;
54 static int i = 1;
55 ^(int j){ i = j; g = 0; }(0); // does not need copy/dispose
56 return i + g;
59 int g;
61 void test5(void) {
62 __block struct { int i; } i;
63 ^{ (void)i; }(); // needs copy/dispose
66 void test6(void) {
67 __block int i;
68 ^{ i=1; }(); // needs copy/dispose
69 ^{}(); // does not need copy/dispose
72 void test7(void) {
73 ^{ // does not need copy/dispose
74 __block int i;
75 ^{ i = 1; }(); // needs copy/dispose
76 }();
79 int main(void) {
80 int rv = 0;
81 test1();
82 test2();
83 test3();
84 rv += test4();
85 test5();
86 return rv;