Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 %s -emit-llvm -o %t -fblocks |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 2 | // RUN: grep "_Block_object_dispose" %t | count 17 |
| 3 | // RUN: grep "__copy_helper_block_" %t | count 16 |
| 4 | // RUN: grep "__destroy_helper_block_" %t | count 16 |
| 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 |
Mike Stump | b7477cf | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 8 | // RUN: grep "_Block_object_assign" %t | count 10 |
Mike Stump | 80bd206 | 2009-03-06 06:35:21 +0000 | [diff] [blame] | 9 | |
Daniel Dunbar | 23afaad | 2009-11-17 08:57:36 +0000 | [diff] [blame] | 10 | int printf(const char *, ...); |
Mike Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 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 | |
Mike Stump | 58a8514 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 23 | void test2() { |
| 24 | __block int a; |
| 25 | a=1; |
| 26 | printf("a is %d\n", a); |
| 27 | ^{ |
| 28 | ^{ |
| 29 | a = 10; |
| 30 | }(); |
| 31 | }(); |
| 32 | printf("a is %d\n", a); |
| 33 | a = 1; |
| 34 | printf("a is %d\n", a); |
| 35 | } |
| 36 | |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 37 | void test3() { |
Mike Stump | 45031c0 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 38 | __block int k; |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 39 | __block int (^j)(int); |
Mike Stump | 45031c0 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 40 | ^{j=0; k=0;}(); |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Mike Stump | 7f28a9c | 2009-03-13 23:34:28 +0000 | [diff] [blame] | 43 | int test4() { |
| 44 | extern int g; |
| 45 | static int i = 1; |
| 46 | ^(int j){ i = j; g = 0; }(0); |
| 47 | return i + g; |
| 48 | } |
| 49 | |
| 50 | int g; |
| 51 | |
Mike Stump | f8575aa | 2009-03-18 15:54:29 +0000 | [diff] [blame] | 52 | void test5() { |
| 53 | __block struct { int i; } i; |
| 54 | ^{ (void)i; }(); |
| 55 | } |
| 56 | |
Mike Stump | a8b60c9 | 2009-03-21 21:00:35 +0000 | [diff] [blame] | 57 | void test6() { |
| 58 | __block int i; |
| 59 | ^{ i=1; }(); |
Mike Stump | b7477cf | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 60 | ^{}(); |
| 61 | } |
| 62 | |
| 63 | void test7() { |
| 64 | ^{ |
| 65 | __block int i; |
| 66 | ^{ i = 1; }(); |
| 67 | }(); |
Mike Stump | a8b60c9 | 2009-03-21 21:00:35 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Mike Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 70 | int main() { |
Mike Stump | 7f28a9c | 2009-03-13 23:34:28 +0000 | [diff] [blame] | 71 | int rv = 0; |
Mike Stump | 58a8514 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 72 | test1(); |
| 73 | test2(); |
Mike Stump | a4f668f | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 74 | test3(); |
Mike Stump | 7f28a9c | 2009-03-13 23:34:28 +0000 | [diff] [blame] | 75 | rv += test4(); |
Mike Stump | f8575aa | 2009-03-18 15:54:29 +0000 | [diff] [blame] | 76 | test5(); |
Mike Stump | 7f28a9c | 2009-03-13 23:34:28 +0000 | [diff] [blame] | 77 | return rv; |
Mike Stump | 58919e1 | 2009-03-04 13:17:22 +0000 | [diff] [blame] | 78 | } |