blob: 804b688afb36872828ee0e1d545c2af406bf7881 [file] [log] [blame]
Mike Stump797b6322009-03-05 01:23:13 +00001// RUN: clang %s -emit-llvm -o %t -fblocks -f__block &&
Mike Stump45031c02009-03-06 02:29:21 +00002// RUN: grep "_Block_object_dispose" %t | count 5
3// 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 Stump58919e12009-03-04 13:17:22 +00007#include <stdio.h>
8
Mike Stump58a85142009-03-04 22:48:06 +00009void test1() {
10 __block int a;
11 int b=2;
12 a=1;
13 printf("a is %d, b is %d\n", a, b);
14 ^{ a = 10; printf("a is %d, b is %d\n", a, b); }();
15 printf("a is %d, b is %d\n", a, b);
16 a = 1;
17 printf("a is %d, b is %d\n", a, b);
18}
19
20
21void test2() {
22 __block int a;
23 a=1;
24 printf("a is %d\n", a);
25 ^{
26 ^{
27 a = 10;
28 }();
29 }();
30 printf("a is %d\n", a);
31 a = 1;
32 printf("a is %d\n", a);
33}
34
Mike Stumpa4f668f2009-03-06 01:33:24 +000035void test3() {
Mike Stump45031c02009-03-06 02:29:21 +000036 __block int k;
Mike Stumpa4f668f2009-03-06 01:33:24 +000037 __block int (^j)(int);
Mike Stump45031c02009-03-06 02:29:21 +000038 ^{j=0; k=0;}();
Mike Stumpa4f668f2009-03-06 01:33:24 +000039}
40
Mike Stump58919e12009-03-04 13:17:22 +000041int main() {
Mike Stump58a85142009-03-04 22:48:06 +000042 test1();
43 test2();
Mike Stumpa4f668f2009-03-06 01:33:24 +000044 test3();
Mike Stump58a85142009-03-04 22:48:06 +000045 return 0;
Mike Stump58919e12009-03-04 13:17:22 +000046}