2022-04-07 18:03:55 +08:00
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -fblocks -o - -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 %s | FileCheck %s
|
2010-05-26 01:46:21 +08:00
|
|
|
|
2017-09-07 13:41:24 +08:00
|
|
|
// CHECK-DAG: @_ZZZN26externally_visible_statics1S3fooEiEd_Ub_E1k = linkonce_odr global i32 0
|
|
|
|
// CHECK-DAG: @_ZZZN26externally_visible_statics10inlinefuncEvEUb_E1i = linkonce_odr global i32 0
|
|
|
|
// CHECK-DAG: @_ZZZN26externally_visible_statics10inlinefuncEvEUb0_E1j = linkonce_odr global i32 0
|
|
|
|
// CHECK-DAG: @_ZZ26externally_visible_statics1S1xMUb_E1j = linkonce_odr global i32 0
|
2010-05-26 01:46:21 +08:00
|
|
|
|
|
|
|
int f();
|
|
|
|
|
|
|
|
void foo() {
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK-LABEL: define internal noundef i32 @___Z3foov_block_invoke
|
2013-07-03 01:52:28 +08:00
|
|
|
// CHECK: call i32 @__cxa_guard_acquire(i64* @_ZGVZZ3foovEUb_E5value
|
2010-05-26 01:46:21 +08:00
|
|
|
(void)^(int x) {
|
|
|
|
static int value = f();
|
|
|
|
return x + value;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK-LABEL: define internal noundef i32 @i_block_invoke
|
2010-05-26 01:46:21 +08:00
|
|
|
int i = ^(int x) { return x;}(i);
|
|
|
|
|
|
|
|
@interface A
|
|
|
|
- (void)method;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation A
|
|
|
|
- (void)method {
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK: define internal noundef signext i8 @"__11-[A method]_block_invoke"
|
2010-05-26 01:46:21 +08:00
|
|
|
(void)^(int x) {
|
2014-08-04 14:16:50 +08:00
|
|
|
// CHECK: @"_ZZZ11-[A method]EUb1_E4name"
|
2010-05-26 01:46:21 +08:00
|
|
|
static const char *name = "hello";
|
|
|
|
return name[x];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
void foo(int) {
|
|
|
|
(void)^(int x) {
|
|
|
|
static const char *name = "hello";
|
|
|
|
return name[x];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace N {
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK-LABEL: define internal noundef signext i8 @___Z3fooi_block_invoke
|
2010-05-26 01:46:21 +08:00
|
|
|
void bar() {
|
|
|
|
(void)^(int x) {
|
2014-08-04 14:16:50 +08:00
|
|
|
// CHECK: @_ZZZN1N3barEvEUb3_E4name
|
2010-05-26 01:46:21 +08:00
|
|
|
static const char *name = "hello";
|
|
|
|
return name[x];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2013-06-25 04:24:19 +08:00
|
|
|
|
|
|
|
class C {
|
|
|
|
C();
|
|
|
|
};
|
|
|
|
C::C() {
|
|
|
|
(void)^(int x) {
|
2014-08-04 14:16:50 +08:00
|
|
|
// CHECK: @_ZZZN1CC1EvEUb4_E5nameb
|
2013-06-25 04:24:19 +08:00
|
|
|
static const char *nameb = "hello";
|
|
|
|
return nameb[x];
|
|
|
|
};
|
|
|
|
}
|
2013-07-02 04:22:57 +08:00
|
|
|
|
|
|
|
int f();
|
|
|
|
namespace externally_visible_statics {
|
|
|
|
inline void inlinefunc() {
|
|
|
|
^{
|
|
|
|
static int i = f();
|
|
|
|
}();
|
2017-09-07 13:41:24 +08:00
|
|
|
^{
|
|
|
|
static int j = f();
|
|
|
|
}();
|
2013-07-02 04:22:57 +08:00
|
|
|
}
|
|
|
|
struct S {
|
|
|
|
int x = ^{
|
|
|
|
static int j = f();
|
|
|
|
return j;
|
|
|
|
}();
|
|
|
|
void foo(int y = ^{ static int k = f(); return k; }()) {}
|
|
|
|
};
|
|
|
|
void g() {
|
|
|
|
inlinefunc();
|
|
|
|
S s;
|
|
|
|
s.foo();
|
|
|
|
}
|
|
|
|
}
|