blob: 4a602e27d3cdebc8860bccc9105a00264018ca21 [file] [log] [blame]
Mike Stump797b6322009-03-05 01:23:13 +00001// RUN: clang %s -emit-llvm -o %t -fblocks -f__block &&
Mike Stumpa4f668f2009-03-06 01:33:24 +00002// RUN: grep "_Block_object_dispose" %t | count 4
3// RUN: grep "__copy_helper_block_" %t | count 2
4// RUN: grep "__destroy_helper_block_" %t | count 2
Mike Stump58919e12009-03-04 13:17:22 +00005#include <stdio.h>
6
Mike Stump58a85142009-03-04 22:48:06 +00007void test1() {
8 __block int a;
9 int b=2;
10 a=1;
11 printf("a is %d, b is %d\n", a, b);
12 ^{ a = 10; printf("a is %d, b is %d\n", a, b); }();
13 printf("a is %d, b is %d\n", a, b);
14 a = 1;
15 printf("a is %d, b is %d\n", a, b);
16}
17
18
19void test2() {
20 __block int a;
21 a=1;
22 printf("a is %d\n", a);
23 ^{
24 ^{
25 a = 10;
26 }();
27 }();
28 printf("a is %d\n", a);
29 a = 1;
30 printf("a is %d\n", a);
31}
32
Mike Stumpa4f668f2009-03-06 01:33:24 +000033void test3() {
34 __block int (^j)(int);
35 ^{j=0;}();
36}
37
Mike Stump58919e12009-03-04 13:17:22 +000038int main() {
Mike Stump58a85142009-03-04 22:48:06 +000039 test1();
40 test2();
Mike Stumpa4f668f2009-03-06 01:33:24 +000041 test3();
Mike Stump58a85142009-03-04 22:48:06 +000042 return 0;
Mike Stump58919e12009-03-04 13:17:22 +000043}