blob: 71b4de8beff596aa9c1c3fdf48f5982d1c889f26 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -emit-llvm -o %t -fblocks
Daniel Dunbar4fcfde42009-11-08 01:45:36 +00002// RUN: grep "_Block_object_dispose" %t | count 17
3// RUN: grep "__copy_helper_block_" %t | count 16
4// RUN: grep "__destroy_helper_block_" %t | count 16
5// RUN: grep "__Block_byref_id_object_copy_" %t | count 2
6// RUN: grep "__Block_byref_id_object_dispose_" %t | count 2
7// RUN: grep "i32 135)" %t | count 2
Mike Stumpb7477cf2009-04-10 18:52:28 +00008// RUN: grep "_Block_object_assign" %t | count 10
Mike Stump80bd2062009-03-06 06:35:21 +00009
Daniel Dunbar23afaad2009-11-17 08:57:36 +000010int printf(const char *, ...);
Mike Stump58919e12009-03-04 13:17:22 +000011
Mike Stump58a85142009-03-04 22:48:06 +000012void test1() {
13 __block int a;
14 int b=2;
15 a=1;
16 printf("a is %d, b is %d\n", a, b);
17 ^{ a = 10; printf("a is %d, b is %d\n", a, b); }();
18 printf("a is %d, b is %d\n", a, b);
19 a = 1;
20 printf("a is %d, b is %d\n", a, b);
21}
22
Mike Stump58a85142009-03-04 22:48:06 +000023void test2() {
24 __block int a;
25 a=1;
26 printf("a is %d\n", a);
27 ^{
28 ^{
29 a = 10;
30 }();
31 }();
32 printf("a is %d\n", a);
33 a = 1;
34 printf("a is %d\n", a);
35}
36
Mike Stumpa4f668f2009-03-06 01:33:24 +000037void test3() {
Mike Stump45031c02009-03-06 02:29:21 +000038 __block int k;
Mike Stumpa4f668f2009-03-06 01:33:24 +000039 __block int (^j)(int);
Mike Stump45031c02009-03-06 02:29:21 +000040 ^{j=0; k=0;}();
Mike Stumpa4f668f2009-03-06 01:33:24 +000041}
42
Mike Stump7f28a9c2009-03-13 23:34:28 +000043int test4() {
44 extern int g;
45 static int i = 1;
46 ^(int j){ i = j; g = 0; }(0);
47 return i + g;
48}
49
50int g;
51
Mike Stumpf8575aa2009-03-18 15:54:29 +000052void test5() {
53 __block struct { int i; } i;
54 ^{ (void)i; }();
55}
56
Mike Stumpa8b60c92009-03-21 21:00:35 +000057void test6() {
58 __block int i;
59 ^{ i=1; }();
Mike Stumpb7477cf2009-04-10 18:52:28 +000060 ^{}();
61}
62
63void test7() {
64 ^{
65 __block int i;
66 ^{ i = 1; }();
67 }();
Mike Stumpa8b60c92009-03-21 21:00:35 +000068}
69
Mike Stump58919e12009-03-04 13:17:22 +000070int main() {
Mike Stump7f28a9c2009-03-13 23:34:28 +000071 int rv = 0;
Mike Stump58a85142009-03-04 22:48:06 +000072 test1();
73 test2();
Mike Stumpa4f668f2009-03-06 01:33:24 +000074 test3();
Mike Stump7f28a9c2009-03-13 23:34:28 +000075 rv += test4();
Mike Stumpf8575aa2009-03-18 15:54:29 +000076 test5();
Mike Stump7f28a9c2009-03-13 23:34:28 +000077 return rv;
Mike Stump58919e12009-03-04 13:17:22 +000078}