]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGenObjCXX/lambda-expressions.mm
Vendor import of clang tags/RELEASE_33/final r183502 (effectively, 3.3
[FreeBSD/FreeBSD.git] / test / CodeGenObjCXX / lambda-expressions.mm
1 // 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
4 typedef int (^fp)();
5 fp f() { auto x = []{ return 3; }; return x; }
6
7 // 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"
9 // MRC: define i32 ()* @_Z1fv(
10 // MRC: define internal i32 ()* @"_ZZ1fvENK3$_0cvU13block_pointerFivEEv"
11 // MRC: store i8* bitcast (i8** @_NSConcreteStackBlock to i8*)
12 // MRC: store i8* bitcast (i32 (i8*)* @"___ZZ1fvENK3$_0cvU13block_pointerFivEEv_block_invoke" to i8*)
13 // 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
17 // ARC: define i32 ()* @_Z1fv(
18 // ARC: define internal i32 ()* @"_ZZ1fvENK3$_0cvU13block_pointerFivEEv"
19 // ARC: store i8* bitcast (i8** @_NSConcreteStackBlock to i8*)
20 // ARC: store i8* bitcast (i32 (i8*)* @"___ZZ1fvENK3$_0cvU13block_pointerFivEEv_block_invoke" to i8*)
21 // ARC: call i8* @objc_retainBlock
22 // ARC: call i8* @objc_autoreleaseReturnValue
23
24 typedef int (^fp)();
25 fp global;
26 void f2() { global = []{ return 3; }; }
27
28 // MRC: define void @_Z2f2v() [[NUW:#[0-9]+]] {
29 // MRC: store i8* bitcast (i32 (i8*)* @___Z2f2v_block_invoke to i8*),
30 // MRC-NOT: call
31 // MRC: ret void
32 // ("global" contains a dangling pointer after this function runs.)
33
34 // ARC: define void @_Z2f2v() [[NUW:#[0-9]+]] {
35 // ARC: store i8* bitcast (i32 (i8*)* @___Z2f2v_block_invoke to i8*),
36 // ARC: call i8* @objc_retainBlock
37 // ARC: call void @objc_release
38 // ARC: define internal i32 @___Z2f2v_block_invoke
39 // ARC: call i32 @"_ZZ2f2vENK3$_1clEv
40
41 template <class T> void take_lambda(T &&lambda) { lambda(); }
42 void 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
63 // ARC: attributes [[NUW]] = { nounwind{{.*}} }
64
65 // MRC: attributes [[NUW]] = { nounwind{{.*}} }