blob: bbe5c1f77f4d1cc2ba0da55a1e734f34d067da36 [file] [log] [blame]
John McCall5fb5df92012-06-20 06:18:46 +00001// RUN: %clang_cc1 -emit-llvm -fblocks -o - -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 %s | FileCheck %s
Douglas Gregoraab11ed2010-05-25 17:46:21 +00002
Richard Smith48b35d92017-09-07 05:41:24 +00003// CHECK-DAG: @_ZZZN26externally_visible_statics1S3fooEiEd_Ub_E1k = linkonce_odr global i32 0
4// CHECK-DAG: @_ZZZN26externally_visible_statics10inlinefuncEvEUb_E1i = linkonce_odr global i32 0
5// CHECK-DAG: @_ZZZN26externally_visible_statics10inlinefuncEvEUb0_E1j = linkonce_odr global i32 0
6// CHECK-DAG: @_ZZ26externally_visible_statics1S1xMUb_E1j = linkonce_odr global i32 0
Douglas Gregoraab11ed2010-05-25 17:46:21 +00007
8int f();
9
10void foo() {
Stephen Lin43622612013-08-15 06:47:53 +000011 // CHECK-LABEL: define internal i32 @___Z3foov_block_invoke
Eli Friedman95f50122013-07-02 17:52:28 +000012 // CHECK: call i32 @__cxa_guard_acquire(i64* @_ZGVZZ3foovEUb_E5value
Douglas Gregoraab11ed2010-05-25 17:46:21 +000013 (void)^(int x) {
14 static int value = f();
15 return x + value;
16 };
17}
18
Stephen Lin43622612013-08-15 06:47:53 +000019// CHECK-LABEL: define internal i32 @i_block_invoke
Douglas Gregoraab11ed2010-05-25 17:46:21 +000020int i = ^(int x) { return x;}(i);
21
22@interface A
23- (void)method;
24@end
25
26@implementation A
27- (void)method {
Fariborz Jahanian63628032012-06-26 16:06:38 +000028 // CHECK: define internal signext i8 @"__11-[A method]_block_invoke"
Douglas Gregoraab11ed2010-05-25 17:46:21 +000029 (void)^(int x) {
David Majnemer11d24272014-08-04 06:16:50 +000030 // CHECK: @"_ZZZ11-[A method]EUb1_E4name"
Douglas Gregoraab11ed2010-05-25 17:46:21 +000031 static const char *name = "hello";
32 return name[x];
33 };
34}
35@end
36
37void foo(int) {
38 (void)^(int x) {
39 static const char *name = "hello";
40 return name[x];
41 };
42}
43
44namespace N {
Stephen Lin43622612013-08-15 06:47:53 +000045 // CHECK-LABEL: define internal signext i8 @___Z3fooi_block_invoke
Douglas Gregoraab11ed2010-05-25 17:46:21 +000046 void bar() {
47 (void)^(int x) {
David Majnemer11d24272014-08-04 06:16:50 +000048 // CHECK: @_ZZZN1N3barEvEUb3_E4name
Douglas Gregoraab11ed2010-05-25 17:46:21 +000049 static const char *name = "hello";
50 return name[x];
51 };
52 }
53}
Eli Friedmand0ee1292013-06-24 20:24:19 +000054
55class C {
56 C();
57};
58C::C() {
59 (void)^(int x) {
David Majnemer11d24272014-08-04 06:16:50 +000060 // CHECK: @_ZZZN1CC1EvEUb4_E5nameb
Eli Friedmand0ee1292013-06-24 20:24:19 +000061 static const char *nameb = "hello";
62 return nameb[x];
63 };
64}
Eli Friedman7e346a82013-07-01 20:22:57 +000065
66int f();
67namespace externally_visible_statics {
68 inline void inlinefunc() {
69 ^{
70 static int i = f();
71 }();
Richard Smith48b35d92017-09-07 05:41:24 +000072 ^{
73 static int j = f();
74 }();
Eli Friedman7e346a82013-07-01 20:22:57 +000075 }
76 struct S {
77 int x = ^{
78 static int j = f();
79 return j;
80 }();
81 void foo(int y = ^{ static int k = f(); return k; }()) {}
82 };
83 void g() {
84 inlinefunc();
85 S s;
Eli Friedman7e346a82013-07-01 20:22:57 +000086 s.foo();
Eli Friedman7e346a82013-07-01 20:22:57 +000087 }
88}