blob: 8572f8d6cf85d93996d63b2db90a6a3fc781b257 [file] [log] [blame]
Mike Stump797b6322009-03-05 01:23:13 +00001// RUN: clang %s -emit-llvm -o %t -fblocks -f__block &&
Mike Stump1edf6b62009-03-07 02:53:18 +00002// RUN: grep "_Block_object_dispose" %t | count 10 &&
Mike Stump1851b682009-03-06 04:53:30 +00003// RUN: grep "__copy_helper_block_" %t | count 6 &&
4// RUN: grep "__destroy_helper_block_" %t | count 6 &&
5// RUN: grep "__Block_byref_id_object_copy_" %t | count 2 &&
6// RUN: grep "__Block_byref_id_object_dispose_" %t | count 2 &&
Mike Stump80bd2062009-03-06 06:35:21 +00007// RUN: grep "i32 135)" %t | count 2 &&
Mike Stump08920992009-03-07 02:35:30 +00008// RUN: grep "_Block_object_assign" %t | count 6
Mike Stump80bd2062009-03-06 06:35:21 +00009
Mike Stump58919e12009-03-04 13:17:22 +000010#include <stdio.h>
11
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
23
24void test2() {
25 __block int a;
26 a=1;
27 printf("a is %d\n", a);
28 ^{
29 ^{
30 a = 10;
31 }();
32 }();
33 printf("a is %d\n", a);
34 a = 1;
35 printf("a is %d\n", a);
36}
37
Mike Stumpa4f668f2009-03-06 01:33:24 +000038void test3() {
Mike Stump45031c02009-03-06 02:29:21 +000039 __block int k;
Mike Stumpa4f668f2009-03-06 01:33:24 +000040 __block int (^j)(int);
Mike Stump45031c02009-03-06 02:29:21 +000041 ^{j=0; k=0;}();
Mike Stumpa4f668f2009-03-06 01:33:24 +000042}
43
Mike Stump7f28a9c2009-03-13 23:34:28 +000044int test4() {
45 extern int g;
46 static int i = 1;
47 ^(int j){ i = j; g = 0; }(0);
48 return i + g;
49}
50
51int g;
52
Mike Stump58919e12009-03-04 13:17:22 +000053int main() {
Mike Stump7f28a9c2009-03-13 23:34:28 +000054 int rv = 0;
Mike Stump58a85142009-03-04 22:48:06 +000055 test1();
56 test2();
Mike Stumpa4f668f2009-03-06 01:33:24 +000057 test3();
Mike Stump7f28a9c2009-03-13 23:34:28 +000058 rv += test4();
59 return rv;
Mike Stump58919e12009-03-04 13:17:22 +000060}