xref: /llvm-project/clang/test/CodeGenCXX/default_calling_conv.cpp (revision fd4f96290ac99bf8b9284d3b32743cac0bb135ea)
1 // RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fdefault-calling-conv=cdecl -emit-llvm -o - %s | FileCheck %s --check-prefix=CDECL --check-prefix=X86 --check-prefix=ALL
2 // RUN: %clang_cc1 -triple i786-unknown-linux-gnu -target-feature +sse4.2 -fdefault-calling-conv=fastcall -emit-llvm -o - %s | FileCheck %s --check-prefix=FASTCALL --check-prefix=X86 --check-prefix=ALL
3 // RUN: %clang_cc1 -triple i486-unknown-linux-gnu -fdefault-calling-conv=stdcall -emit-llvm -o - %s | FileCheck %s --check-prefix=STDCALL --check-prefix=X86 --check-prefix=ALL
4 // RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s | FileCheck %s --check-prefix=STDCALL --check-prefix=X86 --check-prefix=ALL
5 // RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=vectorcall -emit-llvm -o - %s | FileCheck %s --check-prefix=VECTORCALL --check-prefix=X86 --check-prefix=ALL
6 // RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=regcall -emit-llvm -o - %s | FileCheck %s --check-prefix=REGCALL --check-prefix=X86 --check-prefix=ALL
7 // RUN: %clang_cc1 -triple i686-pc-win32 -fdefault-calling-conv=vectorcall -emit-llvm -o - %s -DWINDOWS | FileCheck %s --check-prefix=WIN32
8 // RUN: %clang_cc1 -triple x86_64-windows-msvc -fdefault-calling-conv=vectorcall -emit-llvm -o - %s -DWINDOWS | FileCheck %s --check-prefix=WIN64
9 // RUN: %clang_cc1 -triple i686-pc-win32 -emit-llvm -o - %s -DEXPLICITCC | FileCheck %s --check-prefix=EXPLICITCC
10 // RUN: %clang_cc1 -triple m68k-unknown-linux-gnu -mrtd -emit-llvm -o - %s | FileCheck %s --check-prefix=RTDCALL --check-prefix=ALL
11 // RUN: %clang_cc1 -triple m68k-unknown-linux-gnu -fdefault-calling-conv=rtdcall -emit-llvm -o - %s | FileCheck %s --check-prefix=RTDCALL --check-prefix=ALL
12 
13 // CDECL: define{{.*}} void @_Z5test1v
14 // FASTCALL: define{{.*}} x86_fastcallcc void @_Z5test1v
15 // STDCALL: define{{.*}} x86_stdcallcc void @_Z5test1v
16 // VECTORCALL: define{{.*}} x86_vectorcallcc void @_Z5test1v
17 // REGCALL: define{{.*}} x86_regcallcc void @_Z17__regcall3__test1v
18 // RTDCALL: define{{.*}} m68k_rtdcc void @_Z5test1v
test1()19 void test1() {}
20 
21 // fastcall, stdcall, vectorcall, regcall and m68k_rtd do not support variadic functions.
22 // CDECL: define{{.*}} void @_Z12testVariadicz
23 // FASTCALL: define{{.*}} void @_Z12testVariadicz
24 // STDCALL: define{{.*}} void @_Z12testVariadicz
25 // VECTORCALL: define{{.*}} void @_Z12testVariadicz
26 // REGCALL: define{{.*}} void @_Z12testVariadicz
27 // RTDCALL: define{{.*}} void @_Z12testVariadicz
testVariadic(...)28 void testVariadic(...){}
29 
30 // X86: define{{.*}} void @_Z5test2v
test2()31 void __attribute__((cdecl)) test2() {}
32 
33 // X86: define{{.*}} x86_fastcallcc void @_Z5test3v
test3()34 void __attribute__((fastcall)) test3() {}
35 
36 // X86: define{{.*}} x86_stdcallcc void @_Z5test4v
test4()37 void __attribute__((stdcall)) test4() {}
38 
39 // X86: define{{.*}} x86_vectorcallcc void @_Z5test5v
test5()40 void __attribute__((vectorcall)) test5() {}
41 
42 // X86: define{{.*}} x86_regcallcc void @_Z17__regcall3__test6v
test6()43 void __attribute__((regcall)) test6() {}
44 
45 // RTDCALL: define{{.*}} m68k_rtdcc void @_Z5test7v
test7()46 void __attribute__((m68k_rtd)) test7() {}
47 
48 // ALL: define linkonce_odr void @_ZN1A11test_memberEv
49 class A {
50 public:
test_member()51   void test_member() {}
52 };
53 
test()54 void test() {
55   A a;
56   a.test_member();
57 
58 // ALL: define internal void @"_ZZ{{.*}}testvENK3$_0clEi"
59   auto f = [](int b) {};
60   f(87);
61 }
62 
63 // ALL: define{{.*}} i32 @main
main()64 int main() {
65   return 1;
66 }
67 
68 #ifdef WINDOWS
69 // WIN32: define dso_local noundef i32 @wmain
70 // WIN64: define dso_local noundef i32 @wmain
wmain()71 int wmain() {
72   return 1;
73 }
74 // WIN32: define dso_local x86_stdcallcc noundef i32 @WinMain
75 // WIN64: define dso_local noundef i32 @WinMain
WinMain()76 int WinMain() {
77   return 1;
78 }
79 // WIN32: define dso_local x86_stdcallcc noundef i32 @wWinMain
80 // WIN64: define dso_local noundef i32 @wWinMain
wWinMain()81 int wWinMain() {
82   return 1;
83 }
84 // WIN32: define dso_local x86_stdcallcc noundef i32 @DllMain
85 // WIN64: define dso_local noundef i32 @DllMain
DllMain()86 int DllMain() {
87   return 1;
88 }
89 #endif // Windows
90 
91 #ifdef EXPLICITCC
92 // EXPLICITCC: define dso_local x86_fastcallcc noundef i32 @wmain
wmain()93 int __fastcall wmain() {
94   return 1;
95 }
96 // EXPLICITCC: define dso_local x86_fastcallcc noundef i32 @WinMain
WinMain()97 int __fastcall WinMain() {
98   return 1;
99 }
100 // EXPLICITCC: define dso_local x86_fastcallcc noundef i32 @wWinMain
wWinMain()101 int __fastcall wWinMain() {
102   return 1;
103 }
104 // EXPLICITCC: define dso_local x86_fastcallcc noundef i32 @DllMain
DllMain()105 int __fastcall DllMain() {
106   return 1;
107 }
108 #endif // ExplicitCC
109