1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fblocks -emit-llvm -o - %s -fexceptions -std=c++11 | FileCheck %s
2
3 // CHECK-NOT: @unused
__anon43fd22510102(int i) 4 auto unused = [](int i) { return i+1; };
5
6 // CHECK: @used = internal global
__anon43fd22510202(int i) 7 auto used = [](int i) { return i+1; };
8 void *use = &used;
9
10 // CHECK: @cvar = global
__anon43fd22510302null11 extern "C" auto cvar = []{};
12
a()13 int a() { return []{ return 1; }(); }
14 // CHECK-LABEL: define i32 @_Z1av
15 // CHECK: call i32 @"_ZZ1avENK3$_0clEv"
16 // CHECK-LABEL: define internal i32 @"_ZZ1avENK3$_0clEv"
17 // CHECK: ret i32 1
18
b(int x)19 int b(int x) { return [x]{return x;}(); }
20 // CHECK-LABEL: define i32 @_Z1bi
21 // CHECK: store i32
22 // CHECK: load i32*
23 // CHECK: store i32
24 // CHECK: call i32 @"_ZZ1biENK3$_1clEv"
25 // CHECK-LABEL: define internal i32 @"_ZZ1biENK3$_1clEv"
26 // CHECK: load i32*
27 // CHECK: ret i32
28
c(int x)29 int c(int x) { return [&x]{return x;}(); }
30 // CHECK-LABEL: define i32 @_Z1ci
31 // CHECK: store i32
32 // CHECK: store i32*
33 // CHECK: call i32 @"_ZZ1ciENK3$_2clEv"
34 // CHECK-LABEL: define internal i32 @"_ZZ1ciENK3$_2clEv"
35 // CHECK: load i32**
36 // CHECK: load i32*
37 // CHECK: ret i32
38
39 struct D { D(); D(const D&); int x; };
d(int x)40 int d(int x) { D y[10]; [x,y] { return y[x].x; }(); }
41
42 // CHECK-LABEL: define i32 @_Z1di
43 // CHECK: call void @_ZN1DC1Ev
44 // CHECK: icmp ult i64 %{{.*}}, 10
45 // CHECK: call void @_ZN1DC1ERKS_
46 // CHECK: call i32 @"_ZZ1diENK3$_3clEv"
47 // CHECK-LABEL: define internal i32 @"_ZZ1diENK3$_3clEv"
48 // CHECK: load i32*
49 // CHECK: load i32*
50 // CHECK: ret i32
51
52 struct E { E(); E(const E&); ~E(); int x; };
e(E a,E b,bool cond)53 int e(E a, E b, bool cond) { [a,b,cond](){ return (cond ? a : b).x; }(); }
54 // CHECK-LABEL: define i32 @_Z1e1ES_b
55 // CHECK: call void @_ZN1EC1ERKS_
56 // CHECK: invoke void @_ZN1EC1ERKS_
57 // CHECK: invoke i32 @"_ZZ1e1ES_bENK3$_4clEv"
58 // CHECK: call void @"_ZZ1e1ES_bEN3$_4D1Ev"
59 // CHECK: call void @"_ZZ1e1ES_bEN3$_4D1Ev"
60
61 // CHECK-LABEL: define internal i32 @"_ZZ1e1ES_bENK3$_4clEv"
62 // CHECK: trunc i8
63 // CHECK: load i32*
64 // CHECK: ret i32
65
f()66 void f() {
67 // CHECK-LABEL: define void @_Z1fv()
68 // CHECK: @"_ZZ1fvENK3$_5cvPFiiiEEv"
69 // CHECK-NEXT: store i32 (i32, i32)*
70 // CHECK-NEXT: ret void
71 int (*fp)(int, int) = [](int x, int y){ return x + y; };
72 }
73
74 static int k;
g()75 int g() {
76 int &r = k;
77 // CHECK-LABEL: define internal i32 @"_ZZ1gvENK3$_6clEv"(
78 // CHECK-NOT: }
79 // CHECK: load i32* @_ZL1k,
80 return [] { return r; } ();
81 };
82
83 // PR14773
84 // CHECK: [[ARRVAL:%[0-9a-zA-Z]*]] = load i32* getelementptr inbounds ([0 x i32]* bitcast (<{}>* @_ZZ14staticarrayrefvE5array to [0 x i32]*), i32 0, i64 0), align 4
85 // CHECK-NEXT: store i32 [[ARRVAL]]
staticarrayref()86 void staticarrayref(){
87 static int array[] = {};
88 (void)[](){
89 int (&xxx)[0] = array;
90 int y = xxx[0];
91 }();
92 }
93
94 // CHECK: define internal void @"_ZZ1hvEN3$_88__invokeEv"(%struct.A* noalias sret %agg.result) {{.*}} {
95 // CHECK-NOT: =
96 // CHECK: call void @"_ZZ1hvENK3$_8clEv"(%struct.A* sret %agg.result,
97 // CHECK-NEXT: ret void
98 struct A { ~A(); };
h()99 void h() {
100 A (*h)() = [] { return A(); };
101 }
102
103 // CHECK-LABEL: define internal i32 @"_ZZ1fvEN3$_58__invokeEii"
104 // CHECK: store i32
105 // CHECK-NEXT: store i32
106 // CHECK-NEXT: load i32*
107 // CHECK-NEXT: load i32*
108 // CHECK-NEXT: call i32 @"_ZZ1fvENK3$_5clEii"
109 // CHECK-NEXT: ret i32
110
111 // CHECK-LABEL: define internal void @"_ZZ1e1ES_bEN3$_4D2Ev"
112
113 // <rdar://problem/12778708>
114 struct XXX {};
nestedCapture()115 void nestedCapture () {
116 XXX localKey;
117 ^() {
118 [&]() {
119 ^{ XXX k = localKey; };
120 };
121 };
122 }
123