blob: c73e1727d6377575680c8fc93cd880d0c3c7e875 [file] [log] [blame]
Eli Friedmancd7a0992012-02-28 03:32:48 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s -fexceptions -std=c++11 -fblocks -fobjc-arc | FileCheck -check-prefix=ARC %s
2// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s -fexceptions -std=c++11 -fblocks | FileCheck -check-prefix=MRC %s
3
4typedef int (^fp)();
5fp f() { auto x = []{ return 3; }; return x; }
6
Eli Friedman8c72a7d2012-03-01 22:52:28 +00007// MRC: @"\01L_OBJC_METH_VAR_NAME{{.*}}" = internal global [5 x i8] c"copy\00"
8// MRC: @"\01L_OBJC_METH_VAR_NAME{{.*}}" = internal global [12 x i8] c"autorelease\00"
Eli Friedman23f02672012-03-01 04:01:32 +00009// MRC: define i32 ()* @_Z1fv(
Eli Friedmancd7a0992012-02-28 03:32:48 +000010// MRC: define internal i32 ()* @"_ZZ1fvENK3$_0cvU13block_pointerFivEEv"
11// MRC: store i8* bitcast (i8** @_NSConcreteStackBlock to i8*)
Fariborz Jahanian4904bf42012-06-26 16:06:38 +000012// MRC: store i8* bitcast (i32 (i8*)* @"___ZZ1fvENK3$_0cvU13block_pointerFivEEv_block_invoke" to i8*)
Eli Friedmancd7a0992012-02-28 03:32:48 +000013// MRC: call i32 ()* (i8*, i8*)* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i32 ()* (i8*, i8*)*)
14// MRC: call i32 ()* (i8*, i8*)* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i32 ()* (i8*, i8*)*)
15// MRC: ret i32 ()*
16
Eli Friedman23f02672012-03-01 04:01:32 +000017// ARC: define i32 ()* @_Z1fv(
Eli Friedmancd7a0992012-02-28 03:32:48 +000018// ARC: define internal i32 ()* @"_ZZ1fvENK3$_0cvU13block_pointerFivEEv"
19// ARC: store i8* bitcast (i8** @_NSConcreteStackBlock to i8*)
Fariborz Jahanian4904bf42012-06-26 16:06:38 +000020// ARC: store i8* bitcast (i32 (i8*)* @"___ZZ1fvENK3$_0cvU13block_pointerFivEEv_block_invoke" to i8*)
Eli Friedmancd7a0992012-02-28 03:32:48 +000021// ARC: call i8* @objc_retainBlock
22// ARC: call i8* @objc_autoreleaseReturnValue
Eli Friedman23f02672012-03-01 04:01:32 +000023
24typedef int (^fp)();
25fp global;
26void f2() { global = []{ return 3; }; }
27
Bill Wendling89924572013-02-27 00:06:04 +000028// MRC: define void @_Z2f2v() [[NUW:#[0-9]+]] {
Fariborz Jahanian4904bf42012-06-26 16:06:38 +000029// MRC: store i8* bitcast (i32 (i8*)* @___Z2f2v_block_invoke to i8*),
Eli Friedman23f02672012-03-01 04:01:32 +000030// MRC-NOT: call
31// MRC: ret void
32// ("global" contains a dangling pointer after this function runs.)
33
Bill Wendling89924572013-02-27 00:06:04 +000034// ARC: define void @_Z2f2v() [[NUW:#[0-9]+]] {
Fariborz Jahanian4904bf42012-06-26 16:06:38 +000035// ARC: store i8* bitcast (i32 (i8*)* @___Z2f2v_block_invoke to i8*),
Eli Friedman23f02672012-03-01 04:01:32 +000036// ARC: call i8* @objc_retainBlock
37// ARC: call void @objc_release
Fariborz Jahanian4904bf42012-06-26 16:06:38 +000038// ARC: define internal i32 @___Z2f2v_block_invoke
Eli Friedman23f02672012-03-01 04:01:32 +000039// ARC: call i32 @"_ZZ2f2vENK3$_1clEv
Bill Wendlingf7a9da02013-02-20 07:22:19 +000040
John McCallf5ebf9b2013-05-03 07:33:41 +000041template <class T> void take_lambda(T &&lambda) { lambda(); }
42void take_block(void (^block)()) { block(); }
43
44// rdar://13800041
45@interface A
46- (void) test;
47@end
48@interface B : A @end
49@implementation B
50- (void) test {
51 take_block(^{
52 take_lambda([=]{
53 take_block(^{
54 take_lambda([=] {
55 [super test];
56 });
57 });
58 });
59 });
60}
61@end
62
Bill Wendling89924572013-02-27 00:06:04 +000063// ARC: attributes [[NUW]] = { nounwind{{.*}} }
Bill Wendlingf7a9da02013-02-20 07:22:19 +000064
Bill Wendling89924572013-02-27 00:06:04 +000065// MRC: attributes [[NUW]] = { nounwind{{.*}} }