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 |
9 | |
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 |
18 | |
19 | int printf(const char *, ...); |
20 | |
21 | void test1() { |
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); |
30 | } |
31 | |
32 | void test2() { |
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); |
44 | } |
45 | |
46 | void test3() { |
47 | __block int k; |
48 | __block int (^j)(int); |
49 | ^{j=0; k=0;}(); // needs copy/dispose |
50 | } |
51 | |
52 | int test4() { |
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; |
57 | } |
58 | |
59 | int g; |
60 | |
61 | void test5() { |
62 | __block struct { int i; } i; |
63 | ^{ (void)i; }(); // needs copy/dispose |
64 | } |
65 | |
66 | void test6() { |
67 | __block int i; |
68 | ^{ i=1; }(); // needs copy/dispose |
69 | ^{}(); // does not need copy/dispose |
70 | } |
71 | |
72 | void test7() { |
73 | ^{ // does not need copy/dispose |
74 | __block int i; |
75 | ^{ i = 1; }(); // needs copy/dispose |
76 | }(); |
77 | } |
78 | |
79 | int main() { |
80 | int rv = 0; |
81 | test1(); |
82 | test2(); |
83 | test3(); |
84 | rv += test4(); |
85 | test5(); |
86 | return rv; |
87 | } |
88 | |