Eli Friedman | cd7a099 | 2012-02-28 03:32:48 +0000 | [diff] [blame] | 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 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 7 | // MRC: @OBJC_METH_VAR_NAME{{.*}} = private global [5 x i8] c"copy\00" |
| 8 | // MRC: @OBJC_METH_VAR_NAME{{.*}} = private global [12 x i8] c"autorelease\00" |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 9 | // MRC-LABEL: define i32 ()* @_Z1fv( |
| 10 | // MRC-LABEL: define internal i32 ()* @"_ZZ1fvENK3$_0cvU13block_pointerFivEEv" |
Eli Friedman | cd7a099 | 2012-02-28 03:32:48 +0000 | [diff] [blame] | 11 | // MRC: store i8* bitcast (i8** @_NSConcreteStackBlock to i8*) |
Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 12 | // MRC: store i8* bitcast (i32 (i8*)* @"___ZZ1fvENK3$_0cvU13block_pointerFivEEv_block_invoke" to i8*) |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame] | 13 | // MRC: call i32 ()* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i32 ()* (i8*, i8*)*) |
| 14 | // MRC: call i32 ()* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i32 ()* (i8*, i8*)*) |
Eli Friedman | cd7a099 | 2012-02-28 03:32:48 +0000 | [diff] [blame] | 15 | // MRC: ret i32 ()* |
| 16 | |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 17 | // ARC-LABEL: define i32 ()* @_Z1fv( |
| 18 | // ARC-LABEL: define internal i32 ()* @"_ZZ1fvENK3$_0cvU13block_pointerFivEEv" |
Eli Friedman | cd7a099 | 2012-02-28 03:32:48 +0000 | [diff] [blame] | 19 | // ARC: store i8* bitcast (i8** @_NSConcreteStackBlock to i8*) |
Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 20 | // ARC: store i8* bitcast (i32 (i8*)* @"___ZZ1fvENK3$_0cvU13block_pointerFivEEv_block_invoke" to i8*) |
Eli Friedman | cd7a099 | 2012-02-28 03:32:48 +0000 | [diff] [blame] | 21 | // ARC: call i8* @objc_retainBlock |
| 22 | // ARC: call i8* @objc_autoreleaseReturnValue |
Eli Friedman | 23f0267 | 2012-03-01 04:01:32 +0000 | [diff] [blame] | 23 | |
| 24 | typedef int (^fp)(); |
| 25 | fp global; |
| 26 | void f2() { global = []{ return 3; }; } |
| 27 | |
Bill Wendling | 8992457 | 2013-02-27 00:06:04 +0000 | [diff] [blame] | 28 | // MRC: define void @_Z2f2v() [[NUW:#[0-9]+]] { |
Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 29 | // MRC: store i8* bitcast (i32 (i8*)* @___Z2f2v_block_invoke to i8*), |
Eli Friedman | 23f0267 | 2012-03-01 04:01:32 +0000 | [diff] [blame] | 30 | // MRC-NOT: call |
| 31 | // MRC: ret void |
| 32 | // ("global" contains a dangling pointer after this function runs.) |
| 33 | |
Bill Wendling | 8992457 | 2013-02-27 00:06:04 +0000 | [diff] [blame] | 34 | // ARC: define void @_Z2f2v() [[NUW:#[0-9]+]] { |
Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 35 | // ARC: store i8* bitcast (i32 (i8*)* @___Z2f2v_block_invoke to i8*), |
Eli Friedman | 23f0267 | 2012-03-01 04:01:32 +0000 | [diff] [blame] | 36 | // ARC: call i8* @objc_retainBlock |
| 37 | // ARC: call void @objc_release |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 38 | // ARC-LABEL: define internal i32 @___Z2f2v_block_invoke |
Eli Friedman | 23f0267 | 2012-03-01 04:01:32 +0000 | [diff] [blame] | 39 | // ARC: call i32 @"_ZZ2f2vENK3$_1clEv |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame] | 40 | |
John McCall | f5ebf9b | 2013-05-03 07:33:41 +0000 | [diff] [blame] | 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 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 63 | // ARC-LABEL: define linkonce_odr i32 ()* @_ZZNK13StaticMembersIfE1fMUlvE_clEvENKUlvE_cvU13block_pointerFivEEv |
| 64 | |
Eli Friedman | c1b8d09 | 2013-07-12 22:05:26 +0000 | [diff] [blame] | 65 | // Check lines for BlockInLambda test below |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 66 | // ARC-LABEL: define internal i32 @___ZZN13BlockInLambda1X1fEvENKUlvE_clEv_block_invoke |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 67 | // ARC: [[Y:%.*]] = getelementptr inbounds %"struct.BlockInLambda::X", %"struct.BlockInLambda::X"* {{.*}}, i32 0, i32 1 |
| 68 | // ARC-NEXT: [[YVAL:%.*]] = load i32, i32* [[Y]], align 4 |
Eli Friedman | c1b8d09 | 2013-07-12 22:05:26 +0000 | [diff] [blame] | 69 | // ARC-NEXT: ret i32 [[YVAL]] |
| 70 | |
Eli Friedman | 95099ef | 2013-06-13 20:56:27 +0000 | [diff] [blame] | 71 | typedef int (^fptr)(); |
| 72 | template<typename T> struct StaticMembers { |
| 73 | static fptr f; |
| 74 | }; |
| 75 | template<typename T> |
| 76 | fptr StaticMembers<T>::f = [] { auto f = []{return 5;}; return fptr(f); }(); |
| 77 | template fptr StaticMembers<float>::f; |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame] | 78 | |
Eli Friedman | c1b8d09 | 2013-07-12 22:05:26 +0000 | [diff] [blame] | 79 | namespace BlockInLambda { |
| 80 | struct X { |
| 81 | int x,y; |
| 82 | void f() { |
| 83 | [this]{return ^{return y;}();}(); |
| 84 | }; |
| 85 | }; |
| 86 | void g(X& x) { |
| 87 | x.f(); |
| 88 | }; |
| 89 | } |
| 90 | |
Eli Friedman | 95099ef | 2013-06-13 20:56:27 +0000 | [diff] [blame] | 91 | |
| 92 | // ARC: attributes [[NUW]] = { nounwind{{.*}} } |
Bill Wendling | 8992457 | 2013-02-27 00:06:04 +0000 | [diff] [blame] | 93 | // MRC: attributes [[NUW]] = { nounwind{{.*}} } |