[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / CodeGenCXX / lambda-expressions.cpp
blob86a4a9c6a373ca2ca09ea6aa71536da89859d3da
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fblocks -emit-llvm -o - %s -fexceptions -std=c++11 | FileCheck %s
3 // CHECK-NOT: @unused
4 auto unused = [](int i) { return i+1; };
6 // CHECK: @used = internal global
7 auto used = [](int i) { return i+1; };
8 void *use = &used;
10 // CHECK: @cvar ={{.*}} global
11 extern "C" auto cvar = []{};
13 // CHECK-LABEL: define{{.*}} i32 @_Z9ARBSizeOfi(i32
14 int ARBSizeOf(int n) {
15 typedef double(T)[8][n];
16 using TT = double[8][n];
17 return [&]() -> int {
18 typedef double(T1)[8][n];
19 using TT1 = double[8][n];
20 return [&n]() -> int {
21 typedef double(T2)[8][n];
22 using TT2 = double[8][n];
23 return sizeof(T) + sizeof(T1) + sizeof(T2) + sizeof(TT) + sizeof(TT1) + sizeof(TT2);
24 }();
25 }();
28 // CHECK-LABEL: define internal noundef i32 @"_ZZ9ARBSizeOfiENK3$_0clEv"
30 int a() { return []{ return 1; }(); }
31 // CHECK-LABEL: define{{.*}} i32 @_Z1av
32 // CHECK: call noundef i32 @"_ZZ1avENK3$_1clEv"
33 // CHECK-LABEL: define internal noundef i32 @"_ZZ1avENK3$_1clEv"
34 // CHECK: ret i32 1
36 int b(int x) { return [x]{return x;}(); }
37 // CHECK-LABEL: define{{.*}} i32 @_Z1bi
38 // CHECK: store i32
39 // CHECK: load i32, i32*
40 // CHECK: store i32
41 // CHECK: call noundef i32 @"_ZZ1biENK3$_2clEv"
42 // CHECK-LABEL: define internal noundef i32 @"_ZZ1biENK3$_2clEv"
43 // CHECK: load i32, i32*
44 // CHECK: ret i32
46 int c(int x) { return [&x]{return x;}(); }
47 // CHECK-LABEL: define{{.*}} i32 @_Z1ci
48 // CHECK: store i32
49 // CHECK: store i32*
50 // CHECK: call noundef i32 @"_ZZ1ciENK3$_3clEv"
51 // CHECK-LABEL: define internal noundef i32 @"_ZZ1ciENK3$_3clEv"
52 // CHECK: load i32*, i32**
53 // CHECK: load i32, i32*
54 // CHECK: ret i32
56 struct D { D(); D(const D&); int x; };
57 int d(int x) { D y[10]; return [x,y] { return y[x].x; }(); }
59 // CHECK-LABEL: define{{.*}} i32 @_Z1di
60 // CHECK: call void @_ZN1DC1Ev
61 // CHECK: br label
62 // CHECK: call void @_ZN1DC1ERKS_
63 // CHECK: icmp eq i64 %{{.*}}, 10
64 // CHECK: br i1
65 // CHECK: call noundef i32 @"_ZZ1diENK3$_4clEv"
66 // CHECK-LABEL: define internal noundef i32 @"_ZZ1diENK3$_4clEv"
67 // CHECK: load i32, i32*
68 // CHECK: load i32, i32*
69 // CHECK: ret i32
71 struct E { E(); E(const E&); ~E(); int x; };
72 int e(E a, E b, bool cond) { return [a,b,cond](){ return (cond ? a : b).x; }(); }
73 // CHECK-LABEL: define{{.*}} i32 @_Z1e1ES_b
74 // CHECK: call void @_ZN1EC1ERKS_
75 // CHECK: invoke void @_ZN1EC1ERKS_
76 // CHECK: invoke noundef i32 @"_ZZ1e1ES_bENK3$_5clEv"
77 // CHECK: call void @"_ZZ1e1ES_bEN3$_5D1Ev"
78 // CHECK: call void @"_ZZ1e1ES_bEN3$_5D1Ev"
80 // CHECK-LABEL: define internal noundef i32 @"_ZZ1e1ES_bENK3$_5clEv"
81 // CHECK: trunc i8
82 // CHECK: load i32, i32*
83 // CHECK: ret i32
85 void f() {
86 // CHECK-LABEL: define{{.*}} void @_Z1fv()
87 // CHECK: @"_ZZ1fvENK3$_6cvPFiiiEEv"
88 // CHECK-NEXT: store i32 (i32, i32)*
89 // CHECK-NEXT: ret void
90 int (*fp)(int, int) = [](int x, int y){ return x + y; };
93 static int k;
94 int g() {
95 int &r = k;
96 // CHECK-LABEL: define internal noundef i32 @"_ZZ1gvENK3$_7clEv"(
97 // CHECK-NOT: }
98 // CHECK: load i32, i32* @_ZL1k,
99 return [] { return r; } ();
102 // PR14773
103 // CHECK: [[ARRVAL:%[0-9a-zA-Z]*]] = load i32, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @_ZZ14staticarrayrefvE5array, i64 0, i64 0), align 4
104 // CHECK-NEXT: store i32 [[ARRVAL]]
105 void staticarrayref(){
106 static int array[] = {};
107 (void)[](){
108 int (&xxx)[0] = array;
109 int y = xxx[0];
110 }();
113 // CHECK-LABEL: define internal noundef i32* @"_ZZ11PR22071_funvENK3$_9clEv"
114 // CHECK: ret i32* @PR22071_var
115 int PR22071_var;
116 int *PR22071_fun() {
117 constexpr int &y = PR22071_var;
118 return [&] { return &y; }();
121 namespace pr28595 {
122 struct Temp {
123 Temp();
124 ~Temp() noexcept(false);
126 struct A {
127 A();
128 A(const A &a, const Temp &temp = Temp());
129 ~A();
132 void after_init() noexcept;
134 // CHECK-LABEL: define{{.*}} void @_ZN7pr285954testEv()
135 void test() {
136 // CHECK: %[[SRC:.*]] = alloca [3 x [5 x %[[A:.*]]]], align 1
137 A array[3][5];
139 // Skip over the initialization loop.
140 // CHECK: call {{.*}}after_init
141 after_init();
143 // CHECK: %[[DST_0:.*]] = getelementptr {{.*}} [3 x [5 x %[[A]]]]* %[[DST:.*]], i64 0, i64 0
144 // CHECK: br label
145 // CHECK: %[[I:.*]] = phi i64 [ 0, %{{.*}} ], [ %[[I_NEXT:.*]], {{.*}} ]
146 // CHECK: %[[DST_I:.*]] = getelementptr {{.*}} [5 x %[[A]]]* %[[DST_0]], i64 %[[I]]
147 // CHECK: %[[SRC_I:.*]] = getelementptr {{.*}} [3 x [5 x %[[A]]]]* %[[SRC]], i64 0, i64 %[[I]]
149 // CHECK: %[[DST_I_0:.*]] = getelementptr {{.*}} [5 x %[[A]]]* %[[DST_I]], i64 0, i64 0
150 // CHECK: br label
151 // CHECK: %[[J:.*]] = phi i64 [ 0, %{{.*}} ], [ %[[J_NEXT:.*]], {{.*}} ]
152 // CHECK: %[[DST_I_J:.*]] = getelementptr {{.*}} %[[A]]* %[[DST_I_0]], i64 %[[J]]
153 // CHECK: %[[DST_0_0:.*]] = bitcast [5 x %[[A]]]* %[[DST_0]] to %[[A]]*
154 // CHECK: %[[SRC_I_J:.*]] = getelementptr {{.*}} [5 x %[[A]]]* %[[SRC_I]], i64 0, i64 %[[J]]
156 // CHECK: invoke void @_ZN7pr285954TempC1Ev
157 // CHECK: invoke void @_ZN7pr285951AC1ERKS0_RKNS_4TempE
158 // CHECK: invoke void @_ZN7pr285954TempD1Ev
160 // CHECK: add nuw i64 %[[J]], 1
161 // CHECK: icmp eq
162 // CHECK: br i1
164 // CHECK: add nuw i64 %[[I]], 1
165 // CHECK: icmp eq
166 // CHECK: br i1
168 // CHECK: ret void
170 // CHECK: landingpad
171 // CHECK: landingpad
172 // CHECK: br label %[[CLEANUP:.*]]{{$}}
173 // CHECK: landingpad
174 // CHECK: invoke void @_ZN7pr285954TempD1Ev
175 // CHECK: br label %[[CLEANUP]]
177 // CHECK: [[CLEANUP]]:
178 // CHECK: icmp eq %[[A]]* %[[DST_0_0]], %[[DST_I_J]]
179 // CHECK: %[[T0:.*]] = phi %[[A]]*
180 // CHECK: %[[T1:.*]] = getelementptr inbounds %[[A]], %[[A]]* %[[T0]], i64 -1
181 // CHECK: call void @_ZN7pr285951AD1Ev(%[[A]]* {{[^,]*}} %[[T1]])
182 // CHECK: icmp eq %[[A]]* %[[T1]], %[[DST_0_0]]
183 (void) [array]{};
187 // CHECK-LABEL: define internal void @"_ZZ1e1ES_bEN3$_5D2Ev"
189 // CHECK-LABEL: define internal noundef i32 @"_ZZ1fvEN3$_68__invokeEii"
190 // CHECK: store i32
191 // CHECK-NEXT: store i32
192 // CHECK-NEXT: load i32, i32*
193 // CHECK-NEXT: load i32, i32*
194 // CHECK-NEXT: call noundef i32 @"_ZZ1fvENK3$_6clEii"
195 // CHECK-NEXT: ret i32
197 // CHECK-LABEL: define internal void @"_ZZ1hvEN4$_118__invokeEv"(%struct.A* noalias sret(%struct.A) align 1 %agg.result) {{.*}} {
198 // CHECK: call void @"_ZZ1hvENK4$_11clEv"(%struct.A* sret(%struct.A) align 1 %agg.result,
199 // CHECK-NEXT: ret void
200 struct A { ~A(); };
201 void h() {
202 A (*h)() = [] { return A(); };
205 // <rdar://problem/12778708>
206 struct XXX {};
207 void nestedCapture () {
208 XXX localKey;
209 ^() {
210 [&]() {
211 ^{ XXX k = localKey; };
216 // Ensure we don't assert here.
217 struct CaptureArrayAndThis {
218 CaptureArrayAndThis() {
219 char array[] = "floop";
220 [array, this] {};
222 } capture_array_and_this;