blob: fbc45236aa47273286501a39913f2ee7422b6954 [file] [log] [blame]
Mike Stump60294662009-03-05 01:23:13 +00001// RUN: clang %s -emit-llvm -o %t -fblocks -f__block &&
Mike Stump4a0e5132009-03-06 04:53:30 +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 &&
7// RUN: grep "i32 135)" %t | count 1
Mike Stumpb3a6fac2009-03-04 13:17:22 +00008#include <stdio.h>
9
Mike Stumpf13eac12009-03-04 22:48:06 +000010void test1() {
11 __block int a;
12 int b=2;
13 a=1;
14 printf("a is %d, b is %d\n", a, b);
15 ^{ a = 10; printf("a is %d, b is %d\n", a, b); }();
16 printf("a is %d, b is %d\n", a, b);
17 a = 1;
18 printf("a is %d, b is %d\n", a, b);
19}
20
21
22void test2() {
23 __block int a;
24 a=1;
25 printf("a is %d\n", a);
26 ^{
27 ^{
28 a = 10;
29 }();
30 }();
31 printf("a is %d\n", a);
32 a = 1;
33 printf("a is %d\n", a);
34}
35
Mike Stumpecd79422009-03-06 01:33:24 +000036void test3() {
Mike Stumpf4b62342009-03-06 02:29:21 +000037 __block int k;
Mike Stumpecd79422009-03-06 01:33:24 +000038 __block int (^j)(int);
Mike Stumpf4b62342009-03-06 02:29:21 +000039 ^{j=0; k=0;}();
Mike Stumpecd79422009-03-06 01:33:24 +000040}
41
Mike Stumpb3a6fac2009-03-04 13:17:22 +000042int main() {
Mike Stumpf13eac12009-03-04 22:48:06 +000043 test1();
44 test2();
Mike Stumpecd79422009-03-06 01:33:24 +000045 test3();
Mike Stumpf13eac12009-03-04 22:48:06 +000046 return 0;
Mike Stumpb3a6fac2009-03-04 13:17:22 +000047}