blocks-1.c revision 80bd206870d5e4f959d203ae03e2aa345f67cf89
1// RUN: clang %s -emit-llvm -o %t -fblocks -f__block &&
2// RUN: grep "_Block_object_dispose" %t | count 6 &&
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 2 &&
8// RUN: grep "_Block_object_assign" %t | count 2
9
10#include <stdio.h>
11
12void 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
38void test3() {
39  __block int k;
40  __block int (^j)(int);
41  ^{j=0; k=0;}();
42}
43
44int main() {
45  test1();
46  test2();
47  test3();
48  return 0;
49}
50