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 | 45031c0 | 2009-03-06 02:29:21 +0000 | [diff] [blame^] | 2 | // 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 Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 7 | #include <stdio.h> |
| 8 | |
Mike Stump | 58a8514 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 9 | void 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 | |
| 21 | void 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 Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 35 | void test3() { |
Mike Stump | 45031c0 | 2009-03-06 02:29:21 +0000 | [diff] [blame^] | 36 | __block int k; |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 37 | __block int (^j)(int); |
Mike Stump | 45031c0 | 2009-03-06 02:29:21 +0000 | [diff] [blame^] | 38 | ^{j=0; k=0;}(); |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Mike Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 41 | int main() { |
Mike Stump | 58a8514 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 42 | test1(); |
| 43 | test2(); |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 44 | test3(); |
Mike Stump | 58a8514 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 45 | return 0; |
Mike Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 46 | } |