blob: 892c8afedebfdf87af7733780103960f2a0c61df [file] [log] [blame]
John McCall260611a2012-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 Gregor52d0b592010-05-25 17:46:21 +00002
Fariborz Jahanian4904bf42012-06-26 16:06:38 +00003// CHECK: @_ZGVN3foo22___Z3foov_block_invoke5valueE = internal global i64 0
Douglas Gregor52d0b592010-05-25 17:46:21 +00004
5int f();
6
7void foo() {
Fariborz Jahanian4904bf42012-06-26 16:06:38 +00008 // CHECK: define internal i32 @___Z3foov_block_invoke
9 // CHECK: call i32 @__cxa_guard_acquire(i64* @_ZGVN3foo22___Z3foov_block_invoke5valueE
Douglas Gregor52d0b592010-05-25 17:46:21 +000010 (void)^(int x) {
11 static int value = f();
12 return x + value;
13 };
14}
15
Fariborz Jahanian4904bf42012-06-26 16:06:38 +000016// CHECK: define internal i32 @i_block_invoke
Douglas Gregor52d0b592010-05-25 17:46:21 +000017int i = ^(int x) { return x;}(i);
18
19@interface A
20- (void)method;
21@end
22
23@implementation A
24- (void)method {
Fariborz Jahanian4904bf42012-06-26 16:06:38 +000025 // CHECK: define internal signext i8 @"__11-[A method]_block_invoke"
Douglas Gregor52d0b592010-05-25 17:46:21 +000026 (void)^(int x) {
Fariborz Jahanian4904bf42012-06-26 16:06:38 +000027 // CHECK: @"_ZN11-[A method]28__11-[A method]_block_invoke4nameE"
Douglas Gregor52d0b592010-05-25 17:46:21 +000028 static const char *name = "hello";
29 return name[x];
30 };
31}
32@end
33
34void foo(int) {
35 (void)^(int x) {
36 static const char *name = "hello";
37 return name[x];
38 };
39}
40
41namespace N {
Fariborz Jahanian4904bf42012-06-26 16:06:38 +000042 // CHECK: define internal signext i8 @___Z3fooi_block_invoke
Douglas Gregor52d0b592010-05-25 17:46:21 +000043 void bar() {
44 (void)^(int x) {
Fariborz Jahanian4904bf42012-06-26 16:06:38 +000045 // CHECK: @_ZN1N3bar26___ZN1N3barEv_block_invoke4nameE
Douglas Gregor52d0b592010-05-25 17:46:21 +000046 static const char *name = "hello";
47 return name[x];
48 };
49 }
50}