| 1 |
// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -o - %s 2>&1 | FileCheck %s |
| 2 |
|
| 3 |
struct A { |
| 4 |
A(); |
| 5 |
A(const A &); |
| 6 |
int x; |
| 7 |
}; |
| 8 |
void decayToFp(int (*f)(A)); |
| 9 |
void test() { |
| 10 |
auto ld = [](A a) { |
| 11 |
static int calls = 0; |
| 12 |
++calls; |
| 13 |
return a.x + calls; |
| 14 |
}; |
| 15 |
decayToFp(ld); |
| 16 |
ld(A{}); |
| 17 |
} |
| 18 |
|
| 19 |
// CHECK: define internal x86_thiscallcc noundef i32 |
| 20 |
// CHECK-SAME: @"??R<lambda_0>@?0??test@@YAXXZ@QBE?A?<auto>@@UA@@@Z" |
| 21 |
// CHECK-SAME: (ptr noundef %this, ptr inalloca(<{ %struct.A }>) %[[ARG:.*]]) |
| 22 |
// CHECK: %[[V:.*]] = getelementptr inbounds nuw <{ %struct.A }>, ptr %[[ARG]], i32 0, i32 0 |
| 23 |
// CHECK: %call = call x86_thiscallcc noundef i32 |
| 24 |
// CHECK-SAME: @"?__impl@<lambda_0>@?0??test@@YAXXZ@QBE?A?<auto>@@UA@@@Z" |
| 25 |
// CHECK-SAME: (ptr noundef %this, ptr dead_on_return noundef %[[V]]) |
| 26 |
|
| 27 |
// CHECK: define internal noundef i32 |
| 28 |
// CHECK-SAME: @"?__invoke@<lambda_0>@?0??test@@YAXXZ@CA?A?<auto>@@UA@@@Z" |
| 29 |
// CHECK-SAME: (ptr inalloca(<{ %struct.A }>) %[[ARG:.*]]) |
| 30 |
// CHECK: %unused.capture = alloca %class.anon, align 1 |
| 31 |
// CHECK: %[[VAR:.*]] = getelementptr inbounds nuw <{ %struct.A }>, ptr %[[ARG]], i32 0, i32 0 |
| 32 |
// CHECK: %call = call x86_thiscallcc noundef i32 |
| 33 |
// CHECK-SAME: @"?__impl@<lambda_0>@?0??test@@YAXXZ@QBE?A?<auto>@@UA@@@Z" |
| 34 |
// CHECK-SAME: (ptr noundef %unused.capture, ptr dead_on_return noundef %[[VAR]]) |
| 35 |
// CHECK: ret i32 %call |
| 36 |
|
| 37 |
// CHECK: define internal x86_thiscallcc noundef i32 |
| 38 |
// CHECK-SAME: @"?__impl@<lambda_0>@?0??test@@YAXXZ@QBE?A?<auto>@@UA@@@Z" |
| 39 |
// CHECK-SAME: (ptr noundef %this, ptr dead_on_return noundef %[[ARG:.*]]) |
| 40 |
// CHECK: %this.addr = alloca ptr, align 4 |
| 41 |
// CHECK: store ptr %this, ptr %this.addr, align 4 |
| 42 |
// CHECK: %this1 = load ptr, ptr %this.addr, align 4 |
| 43 |
// CHECK: %{{.*}} = load i32, ptr @"?calls@?1???R<lambda_0> |
| 44 |
// CHECK: %inc = add nsw i32 %{{.*}}, 1 |
| 45 |
// CHECK: store i32 %inc, ptr @"?calls@?1???R<lambda_0> |
| 46 |
// CHECK: %{{.*}} = getelementptr inbounds nuw %struct.A, ptr %{{.*}}, i32 0, i32 0 |
| 47 |
// CHECK: %{{.*}} = load i32, ptr %{{.*}}, align 4 |
| 48 |
// CHECK: %{{.*}} = load i32, ptr @"?calls@?1???R<lambda_0> |
| 49 |
// CHECK: %add = add nsw i32 %{{.*}}, %{{.*}} |
| 50 |
// CHECK: ret i32 %add |
| 51 |
|
| 52 |
// Make sure we don't try to copy an uncopyable type. |
| 53 |
struct B { |
| 54 |
B(); |
| 55 |
B(B &); |
| 56 |
void operator=(B); |
| 57 |
long long x; |
| 58 |
} b; |
| 59 |
|
| 60 |
void f() { |
| 61 |
[](B) {}(b); |
| 62 |
} |
| 63 |
|