blob: 9630c475bdb9cb86fd3586bcc1e7074c68d7d162 [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
Eli Friedman95f50122013-07-02 17:52:28 +00003// CHECK: @_ZGVZZ3foovEUb_E5value = internal global i64 0
4// CHECK: @_ZZ26externally_visible_statics1S1xMUb_E1j = linkonce_odr global i32 0
5// CHECK: @_ZZZN26externally_visible_statics10inlinefuncEvEUb_E1i = linkonce_odr global i32 0
Douglas Gregoraab11ed2010-05-25 17:46:21 +00006
7int f();
8
9void foo() {
Fariborz Jahanian63628032012-06-26 16:06:38 +000010 // CHECK: define internal i32 @___Z3foov_block_invoke
Eli Friedman95f50122013-07-02 17:52:28 +000011 // CHECK: call i32 @__cxa_guard_acquire(i64* @_ZGVZZ3foovEUb_E5value
Douglas Gregoraab11ed2010-05-25 17:46:21 +000012 (void)^(int x) {
13 static int value = f();
14 return x + value;
15 };
16}
17
Fariborz Jahanian63628032012-06-26 16:06:38 +000018// CHECK: define internal i32 @i_block_invoke
Douglas Gregoraab11ed2010-05-25 17:46:21 +000019int i = ^(int x) { return x;}(i);
20
21@interface A
22- (void)method;
23@end
24
25@implementation A
26- (void)method {
Fariborz Jahanian63628032012-06-26 16:06:38 +000027 // CHECK: define internal signext i8 @"__11-[A method]_block_invoke"
Douglas Gregoraab11ed2010-05-25 17:46:21 +000028 (void)^(int x) {
Eli Friedman95f50122013-07-02 17:52:28 +000029 // CHECK: @"_ZZZ11-[A method]EUb0_E4name"
Douglas Gregoraab11ed2010-05-25 17:46:21 +000030 static const char *name = "hello";
31 return name[x];
32 };
33}
34@end
35
36void foo(int) {
37 (void)^(int x) {
38 static const char *name = "hello";
39 return name[x];
40 };
41}
42
43namespace N {
Fariborz Jahanian63628032012-06-26 16:06:38 +000044 // CHECK: define internal signext i8 @___Z3fooi_block_invoke
Douglas Gregoraab11ed2010-05-25 17:46:21 +000045 void bar() {
46 (void)^(int x) {
Eli Friedman95f50122013-07-02 17:52:28 +000047 // CHECK: @_ZZZN1N3barEvEUb2_E4name
Douglas Gregoraab11ed2010-05-25 17:46:21 +000048 static const char *name = "hello";
49 return name[x];
50 };
51 }
52}
Eli Friedmand0ee1292013-06-24 20:24:19 +000053
54class C {
55 C();
56};
57C::C() {
58 (void)^(int x) {
Eli Friedman95f50122013-07-02 17:52:28 +000059 // CHECK: @_ZZZN1CC1EvEUb3_E5nameb
Eli Friedmand0ee1292013-06-24 20:24:19 +000060 static const char *nameb = "hello";
61 return nameb[x];
62 };
63}
Eli Friedman7e346a82013-07-01 20:22:57 +000064
65int f();
66namespace externally_visible_statics {
67 inline void inlinefunc() {
68 ^{
69 static int i = f();
70 }();
71 }
72 struct S {
73 int x = ^{
74 static int j = f();
75 return j;
76 }();
77 void foo(int y = ^{ static int k = f(); return k; }()) {}
78 };
79 void g() {
80 inlinefunc();
81 S s;
82#if 0
83 // FIXME: We know how to mangle k, but crash trying to mangle the
84 // block itself.
85 s.foo();
86#endif
87 }
88}