1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s -fexceptions -std=c++11 -fblocks -fobjc-arc -fobjc-runtime-has-weak -DWEAK_SUPPORTED | 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
5 fp f() { auto x = []{ return 3; }; return x; }
7 // ARC: %[[LAMBDACLASS:.*]] = type { i32 }
9 // MRC: @OBJC_METH_VAR_NAME{{.*}} = private unnamed_addr constant [5 x i8] c"copy\00"
10 // MRC: @OBJC_METH_VAR_NAME{{.*}} = private unnamed_addr constant [12 x i8] c"autorelease\00"
11 // MRC-LABEL: define{{.*}} ptr @_Z1fv(
12 // MRC-LABEL: define internal noundef ptr @"_ZZ1fvENK3$_0cvU13block_pointerFivEEv"
13 // MRC: store ptr @_NSConcreteStackBlock
14 // MRC: store ptr @"___ZZ1fvENK3$_0cvU13block_pointerFivEEv_block_invoke"
15 // MRC: call noundef ptr @objc_msgSend
16 // MRC: call noundef ptr @objc_msgSend
19 // ARC-LABEL: define{{.*}} ptr @_Z1fv(
20 // ARC-LABEL: define internal noundef ptr @"_ZZ1fvENK3$_0cvU13block_pointerFivEEv"
21 // ARC: store ptr @_NSConcreteStackBlock
22 // ARC: store ptr @"___ZZ1fvENK3$_0cvU13block_pointerFivEEv_block_invoke"
23 // ARC: call ptr @llvm.objc.retainBlock
24 // ARC: call ptr @llvm.objc.autoreleaseReturnValue
28 void f2() { global = []{ return 3; }; }
30 // MRC: define{{.*}} void @_Z2f2v() [[NUW:#[0-9]+]] {
31 // MRC: store ptr @___Z2f2v_block_invoke,
34 // ("global" contains a dangling pointer after this function runs.)
36 // ARC: define{{.*}} void @_Z2f2v() [[NUW:#[0-9]+]] {
37 // ARC: store ptr @___Z2f2v_block_invoke,
38 // ARC: call ptr @llvm.objc.retainBlock
39 // ARC: call void @llvm.objc.release
40 // ARC-LABEL: define internal noundef i32 @___Z2f2v_block_invoke
41 // ARC: call noundef i32 @"_ZZ2f2vENK3$_0clEv
43 template <class T> void take_lambda(T &&lambda) { lambda(); }
44 void take_block(void (^block)()) { block(); }
64 // ARC: define{{.*}} void @_ZN13LambdaCapture4foo1ERi(ptr noundef nonnull align 4 dereferenceable(4) %{{.*}})
65 // ARC: %[[CAPTURE0:.*]] = getelementptr inbounds %[[LAMBDACLASS]], ptr %{{.*}}, i32 0, i32 0
66 // ARC: store i32 %{{.*}}, ptr %[[CAPTURE0]]
68 // ARC: define internal void @"_ZZN13LambdaCapture4foo1ERiENK3$_0clEv"(ptr {{[^,]*}} %{{.*}})
69 // ARC: %[[BLOCK:.*]] = alloca <{ ptr, i32, i32, ptr, ptr, i32 }>
70 // ARC: %[[CAPTURE1:.*]] = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, i32 }>, ptr %[[BLOCK]], i32 0, i32 5
71 // ARC: store i32 %{{.*}}, ptr %[[CAPTURE1]]
73 // ARC-LABEL: define internal void @"_ZZ10-[Foo foo]ENK3$_4clEv"(
74 // ARC-NOT: @llvm.objc.storeStrong(
77 // ARC: define internal void @"___ZZN13LambdaCapture4foo1ERiENK3$_0clEv_block_invoke"
78 // ARC: %[[CAPTURE2:.*]] = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, i32 }>, ptr %{{.*}}, i32 0, i32 5
79 // ARC: store i32 %{{.*}}, ptr %[[CAPTURE2]]
81 // ARC: define internal void @"___ZZN13LambdaCapture4foo1ERiENK3$_0clEv_block_invoke_2"(ptr noundef %{{.*}})
82 // ARC: %[[CAPTURE3:.*]] = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, i32 }>, ptr %{{.*}}, i32 0, i32 5
83 // ARC: %[[V1:.*]] = load i32, ptr %[[CAPTURE3]]
84 // ARC: store i32 %[[V1]], ptr @_ZN13LambdaCapture1iE
86 namespace LambdaCapture {
102 // ARC-LABEL: define linkonce_odr noundef ptr @_ZZNK13StaticMembersIfE1fMUlvE_clEvENKUlvE_cvU13block_pointerFivEEv
104 // Check lines for BlockInLambda test below
105 // ARC-LABEL: define internal noundef i32 @___ZZN13BlockInLambda1X1fEvENKUlvE_clEv_block_invoke
106 // ARC: [[Y:%.*]] = getelementptr inbounds %"struct.BlockInLambda::X", ptr {{.*}}, i32 0, i32 1
107 // ARC-NEXT: [[YVAL:%.*]] = load i32, ptr [[Y]], align 4
108 // ARC-NEXT: ret i32 [[YVAL]]
110 typedef int (^fptr)();
111 template<typename T> struct StaticMembers {
115 fptr StaticMembers<T>::f = [] { auto f = []{return 5;}; return fptr(f); }();
116 template fptr StaticMembers<float>::f;
118 namespace BlockInLambda {
122 [this]{return ^{return y;}();}();
130 @interface NSObject @end
131 @interface Foo : NSObject @end
140 // Check that the delegating invoke function doesn't destruct the Weak object
143 // ARC-LABEL: define internal void @"_ZZN14LambdaDelegate4testEvEN3$_08__invokeENS_4WeakE"(
144 // ARC: call void @"_ZZN14LambdaDelegate4testEvENK3$_0clENS_4WeakE"(
145 // ARC-NEXT: ret void
147 // ARC-LABEL: define internal void @"_ZZN14LambdaDelegate4testEvENK3$_0clENS_4WeakE"(
148 // ARC: call void @_ZN14LambdaDelegate4WeakD1Ev(
150 #ifdef WEAK_SUPPORTED
152 namespace LambdaDelegate {
159 void (*p)(Weak) = [](Weak a) { };
166 // ARC: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} }
167 // MRC: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} }