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 | |
Eli Friedman | 8443188 | 2013-07-02 17:52:28 +0000 | [diff] [blame] | 3 | // CHECK: @_ZGVZZ3foovEUb_E5value = internal global i64 0 |
Eli Friedman | e79c987 | 2013-07-10 01:33:19 +0000 | [diff] [blame] | 4 | // CHECK: @_ZZZN26externally_visible_statics1S3fooEiEd_Ub_E1k = linkonce_odr global i32 0 |
Eli Friedman | 8443188 | 2013-07-02 17:52:28 +0000 | [diff] [blame] | 5 | // CHECK: @_ZZ26externally_visible_statics1S1xMUb_E1j = linkonce_odr global i32 0 |
| 6 | // CHECK: @_ZZZN26externally_visible_statics10inlinefuncEvEUb_E1i = linkonce_odr global i32 0 |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 7 | |
| 8 | int f(); |
| 9 | |
| 10 | void foo() { |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 11 | // CHECK-LABEL: define internal i32 @___Z3foov_block_invoke |
Eli Friedman | 8443188 | 2013-07-02 17:52:28 +0000 | [diff] [blame] | 12 | // CHECK: call i32 @__cxa_guard_acquire(i64* @_ZGVZZ3foovEUb_E5value |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 13 | (void)^(int x) { |
| 14 | static int value = f(); |
| 15 | return x + value; |
| 16 | }; |
| 17 | } |
| 18 | |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 19 | // CHECK-LABEL: define internal i32 @i_block_invoke |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 20 | int i = ^(int x) { return x;}(i); |
| 21 | |
| 22 | @interface A |
| 23 | - (void)method; |
| 24 | @end |
| 25 | |
| 26 | @implementation A |
| 27 | - (void)method { |
Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 28 | // CHECK: define internal signext i8 @"__11-[A method]_block_invoke" |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 29 | (void)^(int x) { |
Eli Friedman | 8443188 | 2013-07-02 17:52:28 +0000 | [diff] [blame] | 30 | // CHECK: @"_ZZZ11-[A method]EUb0_E4name" |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 31 | static const char *name = "hello"; |
| 32 | return name[x]; |
| 33 | }; |
| 34 | } |
| 35 | @end |
| 36 | |
| 37 | void foo(int) { |
| 38 | (void)^(int x) { |
| 39 | static const char *name = "hello"; |
| 40 | return name[x]; |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | namespace N { |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 45 | // CHECK-LABEL: define internal signext i8 @___Z3fooi_block_invoke |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 46 | void bar() { |
| 47 | (void)^(int x) { |
Eli Friedman | 8443188 | 2013-07-02 17:52:28 +0000 | [diff] [blame] | 48 | // CHECK: @_ZZZN1N3barEvEUb2_E4name |
Douglas Gregor | 52d0b59 | 2010-05-25 17:46:21 +0000 | [diff] [blame] | 49 | static const char *name = "hello"; |
| 50 | return name[x]; |
| 51 | }; |
| 52 | } |
| 53 | } |
Eli Friedman | bace10c | 2013-06-24 20:24:19 +0000 | [diff] [blame] | 54 | |
| 55 | class C { |
| 56 | C(); |
| 57 | }; |
| 58 | C::C() { |
| 59 | (void)^(int x) { |
Eli Friedman | 8443188 | 2013-07-02 17:52:28 +0000 | [diff] [blame] | 60 | // CHECK: @_ZZZN1CC1EvEUb3_E5nameb |
Eli Friedman | bace10c | 2013-06-24 20:24:19 +0000 | [diff] [blame] | 61 | static const char *nameb = "hello"; |
| 62 | return nameb[x]; |
| 63 | }; |
| 64 | } |
Eli Friedman | 07369dd | 2013-07-01 20:22:57 +0000 | [diff] [blame] | 65 | |
| 66 | int f(); |
| 67 | namespace externally_visible_statics { |
| 68 | inline void inlinefunc() { |
| 69 | ^{ |
| 70 | static int i = f(); |
| 71 | }(); |
| 72 | } |
| 73 | struct S { |
| 74 | int x = ^{ |
| 75 | static int j = f(); |
| 76 | return j; |
| 77 | }(); |
| 78 | void foo(int y = ^{ static int k = f(); return k; }()) {} |
| 79 | }; |
| 80 | void g() { |
| 81 | inlinefunc(); |
| 82 | S s; |
Eli Friedman | 07369dd | 2013-07-01 20:22:57 +0000 | [diff] [blame] | 83 | s.foo(); |
Eli Friedman | 07369dd | 2013-07-01 20:22:57 +0000 | [diff] [blame] | 84 | } |
| 85 | } |