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 | 80bd206 | 2009-03-06 06:35:21 +0000 | [diff] [blame^] | 2 | // RUN: grep "_Block_object_dispose" %t | count 6 && |
Mike Stump | 1851b68 | 2009-03-06 04:53:30 +0000 | [diff] [blame] | 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 | 80bd206 | 2009-03-06 06:35:21 +0000 | [diff] [blame^] | 7 | // RUN: grep "i32 135)" %t | count 2 && |
| 8 | // RUN: grep "_Block_object_assign" %t | count 2 |
| 9 | |
Mike Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | |
Mike Stump | 58a8514 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 12 | void 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 | |
| 24 | void 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 | |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 38 | void test3() { |
Mike Stump | 45031c0 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 39 | __block int k; |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 40 | __block int (^j)(int); |
Mike Stump | 45031c0 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 41 | ^{j=0; k=0;}(); |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Mike Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 44 | int main() { |
Mike Stump | 58a8514 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 45 | test1(); |
| 46 | test2(); |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 47 | test3(); |
Mike Stump | 58a8514 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 48 | return 0; |
Mike Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 49 | } |