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 | 1edf6b6 | 2009-03-07 02:53:18 +0000 | [diff] [blame] | 2 | // RUN: grep "_Block_object_dispose" %t | count 10 && |
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 && |
Mike Stump | 0892099 | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 8 | // RUN: grep "_Block_object_assign" %t | count 6 |
Mike Stump | 80bd206 | 2009-03-06 06:35:21 +0000 | [diff] [blame] | 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 | 7f28a9c | 2009-03-13 23:34:28 +0000 | [diff] [blame^] | 44 | int test4() { |
| 45 | extern int g; |
| 46 | static int i = 1; |
| 47 | ^(int j){ i = j; g = 0; }(0); |
| 48 | return i + g; |
| 49 | } |
| 50 | |
| 51 | int g; |
| 52 | |
Mike Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 53 | int main() { |
Mike Stump | 7f28a9c | 2009-03-13 23:34:28 +0000 | [diff] [blame^] | 54 | int rv = 0; |
Mike Stump | 58a8514 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 55 | test1(); |
| 56 | test2(); |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 57 | test3(); |
Mike Stump | 7f28a9c | 2009-03-13 23:34:28 +0000 | [diff] [blame^] | 58 | rv += test4(); |
| 59 | return rv; |
Mike Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 60 | } |