John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -fblocks -o - -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 %s | FileCheck %s |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 2 | |
Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 3 | // CHECK: @_ZGVN3foo22___Z3foov_block_invoke5valueE = internal global i64 0 |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 4 | |
| 5 | int f(); |
| 6 | |
| 7 | void foo() { |
Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 8 | // CHECK: define internal i32 @___Z3foov_block_invoke |
| 9 | // CHECK: call i32 @__cxa_guard_acquire(i64* @_ZGVN3foo22___Z3foov_block_invoke5valueE |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 10 | (void)^(int x) { |
| 11 | static int value = f(); |
| 12 | return x + value; |
| 13 | }; |
| 14 | } |
| 15 | |
Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 16 | // CHECK: define internal i32 @i_block_invoke |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 17 | int i = ^(int x) { return x;}(i); |
| 18 | |
| 19 | @interface A |
| 20 | - (void)method; |
| 21 | @end |
| 22 | |
| 23 | @implementation A |
| 24 | - (void)method { |
Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 25 | // CHECK: define internal signext i8 @"__11-[A method]_block_invoke" |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 26 | (void)^(int x) { |
Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 27 | // CHECK: @"_ZN11-[A method]28__11-[A method]_block_invoke4nameE" |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 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 { |
Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 42 | // CHECK: define internal signext i8 @___Z3fooi_block_invoke |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 43 | void bar() { |
| 44 | (void)^(int x) { |
Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 45 | // CHECK: @_ZN1N3bar26___ZN1N3barEv_block_invoke4nameE |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 46 | static const char *name = "hello"; |
| 47 | return name[x]; |
| 48 | }; |
| 49 | } |
| 50 | } |