llvm-project/clang/test/CodeGenCXX/microsoft-abi-byval-vararg.cpp
Reid Kleckner 314ef7bafd [ms-cxxabi] Use inalloca on win32 when passing non-trivial C++ objects
When a non-trivial parameter is present, clang now gathers up all the
parameters that lack inreg and puts them into a packed struct.  MSVC
always aligns each parameter to 4 bytes and no more, so this is a pretty
simple struct to lay out.

On win64, non-trivial records are passed indirectly.  Prior to this
change, clang was incorrectly using byval on win64.

I'm able to self-host a working clang with this change and additional
LLVM patches.

Reviewers: rsmith

Differential Revision: http://llvm-reviews.chandlerc.com/D2636

llvm-svn: 200597
2014-02-01 00:04:45 +00:00

28 lines
663 B
C++

// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i686-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck %s
#include <stdarg.h>
struct A {
A(int a) : a(a) {}
A(const A &o) : a(o.a) {}
~A() {}
int a;
};
int foo(A a, ...) {
va_list ap;
va_start(ap, a);
int sum = 0;
for (int i = 0; i < a.a; ++i)
sum += va_arg(ap, int);
va_end(ap);
return sum;
}
int main() {
return foo(A(3), 1, 2, 3);
}
// CHECK-LABEL: define i32 @main()
// CHECK: %[[argmem_cast:[^ ]*]] = bitcast <{ %struct.A, i32, i32, i32 }>* %argmem to <{ %struct.A }>*
// CHECK: call i32 (<{ %struct.A }>*, ...)* @"\01?foo@@YAHUA@@ZZ"(<{ %struct.A }>* inalloca %[[argmem_cast]])