Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -fblocks -o - -triple x86_64-apple-darwin10 %s | FileCheck %s |
| 2 | |
| 3 | // CHECK: @_ZGVN3foo20__foo_block_invoke_05valueE = internal global i64 0 |
| 4 | |
| 5 | int f(); |
| 6 | |
| 7 | void foo() { |
| 8 | // CHECK: define internal i32 @__foo_block_invoke_0 |
| 9 | // CHECK: call i32 @__cxa_guard_acquire(i64* @_ZGVN3foo20__foo_block_invoke_05value |
| 10 | (void)^(int x) { |
| 11 | static int value = f(); |
| 12 | return x + value; |
| 13 | }; |
| 14 | } |
| 15 | |
| 16 | // CHECK: define internal i32 @__block_global_0 |
| 17 | int i = ^(int x) { return x;}(i); |
| 18 | |
| 19 | @interface A |
| 20 | - (void)method; |
| 21 | @end |
| 22 | |
| 23 | @implementation A |
| 24 | - (void)method { |
| 25 | // CHECK: define internal signext i8 @"__11-[A method]_block_invoke_0" |
| 26 | (void)^(int x) { |
| 27 | // CHECK: @"_ZN11-[A method]30__11-[A method]_block_invoke_04nameE" |
| 28 | static const char *name = "hello"; |
| 29 | return name[x]; |
| 30 | }; |
| 31 | } |
| 32 | @end |
| 33 | |
| 34 | void foo(int) { |
| 35 | (void)^(int x) { |
| 36 | static const char *name = "hello"; |
| 37 | return name[x]; |
| 38 | }; |
| 39 | } |
| 40 | |
| 41 | namespace N { |
| 42 | // CHECK: define internal signext i8 @__bar_block_invoke_0 |
| 43 | void bar() { |
| 44 | (void)^(int x) { |
| 45 | // CHECK: @_ZN1N3bar20__bar_block_invoke_04nameE |
| 46 | static const char *name = "hello"; |
| 47 | return name[x]; |
| 48 | }; |
| 49 | } |
| 50 | } |