xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/microsoft-abi-cdecl-method-sret.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple i386-pc-win32 -emit-llvm %s -o - | FileCheck %s
2*0a6a1f1dSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc // PR15768
4*0a6a1f1dSLionel Sambuc 
5*0a6a1f1dSLionel Sambuc // A trivial 12 byte struct is returned indirectly.
6*0a6a1f1dSLionel Sambuc struct S {
7*0a6a1f1dSLionel Sambuc   S();
8*0a6a1f1dSLionel Sambuc   int a, b, c;
9*0a6a1f1dSLionel Sambuc };
10*0a6a1f1dSLionel Sambuc 
11*0a6a1f1dSLionel Sambuc struct C {
12*0a6a1f1dSLionel Sambuc   S variadic_sret(const char *f, ...);
13*0a6a1f1dSLionel Sambuc   S __cdecl cdecl_sret();
14*0a6a1f1dSLionel Sambuc   S __cdecl byval_and_sret(S a);
15*0a6a1f1dSLionel Sambuc   int c;
16*0a6a1f1dSLionel Sambuc };
17*0a6a1f1dSLionel Sambuc 
variadic_sret(const char * f,...)18*0a6a1f1dSLionel Sambuc S C::variadic_sret(const char *f, ...) { return S(); }
cdecl_sret()19*0a6a1f1dSLionel Sambuc S C::cdecl_sret() { return S(); }
byval_and_sret(S a)20*0a6a1f1dSLionel Sambuc S C::byval_and_sret(S a) { return S(); }
21*0a6a1f1dSLionel Sambuc 
22*0a6a1f1dSLionel Sambuc // CHECK: define void @"\01?variadic_sret@C@@QAA?AUS@@PBDZZ"(%struct.C* %this, %struct.S* noalias sret %agg.result, i8* %f, ...)
23*0a6a1f1dSLionel Sambuc // CHECK: define void @"\01?cdecl_sret@C@@QAA?AUS@@XZ"(%struct.C* %this, %struct.S* noalias sret %agg.result)
24*0a6a1f1dSLionel Sambuc // CHECK: define void @"\01?byval_and_sret@C@@QAA?AUS@@U2@@Z"(%struct.C* %this, %struct.S* noalias sret %agg.result, %struct.S* byval align 4 %a)
25*0a6a1f1dSLionel Sambuc 
main()26*0a6a1f1dSLionel Sambuc int main() {
27*0a6a1f1dSLionel Sambuc   C c;
28*0a6a1f1dSLionel Sambuc   c.variadic_sret("asdf");
29*0a6a1f1dSLionel Sambuc   c.cdecl_sret();
30*0a6a1f1dSLionel Sambuc   c.byval_and_sret(S());
31*0a6a1f1dSLionel Sambuc }
32*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define i32 @main()
33*0a6a1f1dSLionel Sambuc // CHECK: call void {{.*}} @"\01?variadic_sret@C@@QAA?AUS@@PBDZZ"
34*0a6a1f1dSLionel Sambuc // CHECK: call void @"\01?cdecl_sret@C@@QAA?AUS@@XZ"
35*0a6a1f1dSLionel Sambuc // CHECK: call void @"\01?byval_and_sret@C@@QAA?AUS@@U2@@Z"
36*0a6a1f1dSLionel Sambuc 
37*0a6a1f1dSLionel Sambuc // __fastcall has similar issues.
38*0a6a1f1dSLionel Sambuc struct A {
39*0a6a1f1dSLionel Sambuc   S __fastcall f(int x);
40*0a6a1f1dSLionel Sambuc };
f(int x)41*0a6a1f1dSLionel Sambuc S A::f(int x) {
42*0a6a1f1dSLionel Sambuc   return S();
43*0a6a1f1dSLionel Sambuc }
44*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define x86_fastcallcc void @"\01?f@A@@QAI?AUS@@H@Z"(%struct.A* inreg %this, %struct.S* inreg noalias sret %agg.result, i32 %x)
45