1*532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm %s -o - -triple=x86_64-linux-gnu | FileCheck %s --check-prefixes=CHECK,LIN64
2*532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm %s -o - -triple=x86_64-linux-gnu -DCC="__attribute__((vectorcall))" | FileCheck %s --check-prefixes=CHECK,VECCALL
3*532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm %s -o - -fms-compatibility -triple=i386-windows-pc -DWIN32 | FileCheck %s --check-prefixes=WIN32
4ec809e4cSErich Keane 
5ec809e4cSErich Keane #ifndef CC
6ec809e4cSErich Keane #define CC
7ec809e4cSErich Keane #endif
8ec809e4cSErich Keane 
usage()9ec809e4cSErich Keane void usage() {
10ec809e4cSErich Keane   auto lambda = [](int i, float f, double d) CC { return i + f + d; };
11ec809e4cSErich Keane 
12ec809e4cSErich Keane   double (*CC fp)(int, float, double) = lambda;
13ec809e4cSErich Keane #ifdef WIN32
14ec809e4cSErich Keane   double (*__attribute__((thiscall)) fp2)(int, float, double) = lambda;
156b104ea4SErich Keane   double (*__attribute__((stdcall)) fp3)(int, float, double) = lambda;
166b104ea4SErich Keane   double (*__attribute__((fastcall)) fp4)(int, float, double) = lambda;
176b104ea4SErich Keane   double (*__attribute__((vectorcall)) fp5)(int, float, double) = lambda;
18ec809e4cSErich Keane #endif // WIN32
196b104ea4SErich Keane   fp(0, 1.1, 2.2);
206b104ea4SErich Keane #ifdef WIN32
216b104ea4SErich Keane   fp2(0, 1.1, 2.2);
226b104ea4SErich Keane   fp3(0, 1.1, 2.2);
236b104ea4SErich Keane   fp4(0, 1.1, 2.2);
246b104ea4SErich Keane   fp5(0, 1.1, 2.2);
256b104ea4SErich Keane #endif // WIN32
266b104ea4SErich Keane 
276b104ea4SErich Keane   auto x = +lambda;
28ec809e4cSErich Keane }
29ec809e4cSErich Keane 
306b104ea4SErich Keane // void usage function, calls conversion operator.
31fd739804SFangrui Song // LIN64: define{{.*}} void @_Z5usagev()
32fd739804SFangrui Song // VECCALL: define{{.*}} void @_Z5usagev()
33ec809e4cSErich Keane // WIN32: define dso_local void @"?usage@@YAXXZ"()
341b1c8d83Shyeongyu kim // CHECK: call noundef double (i32, float, double)* @"_ZZ5usagevENK3$_0cvPFdifdEEv"
351b1c8d83Shyeongyu kim // WIN32: call x86_thiscallcc noundef double (i32, float, double)* @"??B<lambda_0>@?0??usage@@YAXXZ@QBEP6A?A?<auto>@@HMN@ZXZ"
361b1c8d83Shyeongyu kim // WIN32: call x86_thiscallcc noundef double (i32, float, double)* @"??B<lambda_0>@?0??usage@@YAXXZ@QBEP6E?A?<auto>@@HMN@ZXZ"
371b1c8d83Shyeongyu kim // WIN32: call x86_thiscallcc noundef double (i32, float, double)* @"??B<lambda_0>@?0??usage@@YAXXZ@QBEP6G?A?<auto>@@HMN@ZXZ"
381b1c8d83Shyeongyu kim // WIN32: call x86_thiscallcc noundef double (i32, float, double)* @"??B<lambda_0>@?0??usage@@YAXXZ@QBEP6I?A?<auto>@@HMN@ZXZ"
391b1c8d83Shyeongyu kim // WIN32: call x86_thiscallcc noundef double (i32, float, double)* @"??B<lambda_0>@?0??usage@@YAXXZ@QBEP6Q?A?<auto>@@HMN@ZXZ"
406b104ea4SErich Keane // Operator+ calls 'default' calling convention.
411b1c8d83Shyeongyu kim // CHECK: call noundef double (i32, float, double)* @"_ZZ5usagevENK3$_0cvPFdifdEEv"
421b1c8d83Shyeongyu kim // WIN32: call x86_thiscallcc noundef double (i32, float, double)* @"??B<lambda_0>@?0??usage@@YAXXZ@QBEP6A?A?<auto>@@HMN@ZXZ"
43ec809e4cSErich Keane //
44ec809e4cSErich Keane // Conversion operator, returns __invoke.
451b1c8d83Shyeongyu kim // CHECK: define internal noundef double (i32, float, double)* @"_ZZ5usagevENK3$_0cvPFdifdEEv"
46ec809e4cSErich Keane // CHECK: ret double (i32, float, double)* @"_ZZ5usagevEN3$_08__invokeEifd"
471b1c8d83Shyeongyu kim // WIN32: define internal x86_thiscallcc noundef double (i32, float, double)* @"??B<lambda_0>@?0??usage@@YAXXZ@QBEP6A?A?<auto>@@HMN@ZXZ"
48ec809e4cSErich Keane // WIN32: ret double (i32, float, double)* @"?__invoke@<lambda_0>@?0??usage@@YAXXZ@CA?A?<auto>@@HMN@Z"
491b1c8d83Shyeongyu kim // WIN32: define internal x86_thiscallcc noundef double (i32, float, double)* @"??B<lambda_0>@?0??usage@@YAXXZ@QBEP6E?A?<auto>@@HMN@ZXZ"
50ec809e4cSErich Keane // WIN32: ret double (i32, float, double)* @"?__invoke@<lambda_0>@?0??usage@@YAXXZ@CE?A?<auto>@@HMN@Z"
511b1c8d83Shyeongyu kim // WIN32: define internal x86_thiscallcc noundef double (i32, float, double)* @"??B<lambda_0>@?0??usage@@YAXXZ@QBEP6G?A?<auto>@@HMN@ZXZ"
526b104ea4SErich Keane // WIN32: ret double (i32, float, double)* @"?__invoke@<lambda_0>@?0??usage@@YAXXZ@CG?A?<auto>@@HMN@Z"
531b1c8d83Shyeongyu kim // WIN32: define internal x86_thiscallcc noundef double (i32, float, double)* @"??B<lambda_0>@?0??usage@@YAXXZ@QBEP6I?A?<auto>@@HMN@ZXZ"
546b104ea4SErich Keane // WIN32: ret double (i32, float, double)* @"?__invoke@<lambda_0>@?0??usage@@YAXXZ@CI?A?<auto>@@HMN@Z"
551b1c8d83Shyeongyu kim // WIN32: define internal x86_thiscallcc noundef double (i32, float, double)* @"??B<lambda_0>@?0??usage@@YAXXZ@QBEP6Q?A?<auto>@@HMN@ZXZ"
566b104ea4SErich Keane // WIN32: ret double (i32, float, double)* @"?__invoke@<lambda_0>@?0??usage@@YAXXZ@CQ?A?<auto>@@HMN@Z"
57ec809e4cSErich Keane //
58ec809e4cSErich Keane // __invoke function, calls operator(). Win32 should call both.
591b1c8d83Shyeongyu kim // LIN64: define internal noundef double @"_ZZ5usagevEN3$_08__invokeEifd"
601b1c8d83Shyeongyu kim // LIN64: call noundef double @"_ZZ5usagevENK3$_0clEifd"
611b1c8d83Shyeongyu kim // VECCALL: define internal x86_vectorcallcc noundef double @"_ZZ5usagevEN3$_08__invokeEifd"
621b1c8d83Shyeongyu kim // VECCALL: call x86_vectorcallcc noundef double @"_ZZ5usagevENK3$_0clEifd"
631b1c8d83Shyeongyu kim // WIN32: define internal noundef double @"?__invoke@<lambda_0>@?0??usage@@YAXXZ@CA?A?<auto>@@HMN@Z"
641b1c8d83Shyeongyu kim // WIN32: call x86_thiscallcc noundef double @"??R<lambda_0>@?0??usage@@YAXXZ@QBE?A?<auto>@@HMN@Z"
651b1c8d83Shyeongyu kim // WIN32: define internal x86_thiscallcc noundef double @"?__invoke@<lambda_0>@?0??usage@@YAXXZ@CE?A?<auto>@@HMN@Z"
661b1c8d83Shyeongyu kim // WIN32: call x86_thiscallcc noundef double @"??R<lambda_0>@?0??usage@@YAXXZ@QBE?A?<auto>@@HMN@Z"
671b1c8d83Shyeongyu kim // WIN32: define internal x86_stdcallcc noundef double @"?__invoke@<lambda_0>@?0??usage@@YAXXZ@CG?A?<auto>@@HMN@Z"
681b1c8d83Shyeongyu kim // WIN32: call x86_thiscallcc noundef double @"??R<lambda_0>@?0??usage@@YAXXZ@QBE?A?<auto>@@HMN@Z"
691b1c8d83Shyeongyu kim // WIN32: define internal x86_fastcallcc noundef double @"?__invoke@<lambda_0>@?0??usage@@YAXXZ@CI?A?<auto>@@HMN@Z"
701b1c8d83Shyeongyu kim // WIN32: call x86_thiscallcc noundef double @"??R<lambda_0>@?0??usage@@YAXXZ@QBE?A?<auto>@@HMN@Z"
711b1c8d83Shyeongyu kim // WIN32: define internal x86_vectorcallcc noundef double @"?__invoke@<lambda_0>@?0??usage@@YAXXZ@CQ?A?<auto>@@HMN@Z"
721b1c8d83Shyeongyu kim // WIN32: call x86_thiscallcc noundef double @"??R<lambda_0>@?0??usage@@YAXXZ@QBE?A?<auto>@@HMN@Z"
73