Mike Stump | 797b632 | 2009-03-05 01:23:13 +0000 | [diff] [blame] | 1 | // RUN: clang %s -emit-llvm -o %t -fblocks -f__block && |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame^] | 2 | // 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 Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 5 | #include <stdio.h> |
| 6 | |
Mike Stump | 58a8514 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 7 | void 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 | |
| 19 | void 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 Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame^] | 33 | void test3() { |
| 34 | __block int (^j)(int); |
| 35 | ^{j=0;}(); |
| 36 | } |
| 37 | |
Mike Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 38 | int main() { |
Mike Stump | 58a8514 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 39 | test1(); |
| 40 | test2(); |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame^] | 41 | test3(); |
Mike Stump | 58a8514 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 42 | return 0; |
Mike Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 43 | } |