mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-19 11:35:51 -04:00

MSVC 2013 would refuse to pass highly aligned things (typically vectors and aggregates) by value. Users would receive this error: t.cpp(11) : error C2719: 'w': formal parameter with __declspec(align('32')) won't be aligned t.cpp(11) : error C2719: 'q': formal parameter with __declspec(align('32')) won't be aligned However, in MSVC 2015, this behavior was changed, and highly aligned things are now passed indirectly. To avoid breaking backwards incompatibility, objects that do not have a *required* high alignment (i.e. double) are still passed directly, even though they are not naturally aligned. This change implements the new behavior of passing things indirectly. The new behavior is: - up to three vector parameters can be passed in [XYZ]MM0-2 - remaining arguments with required alignment greater than 4 bytes are passed indirectly Previously, MSVC never passed things truly indirectly, meaning clang would always apply the byval attribute to indirect arguments. We had to go to the trouble of adding inalloca so that non-trivially copyable C++ types could be passed in place without copying the object representation. When inalloca was added, we asserted that all arguments passed indirectly must use byval. With this change, that assert no longer holds, and I had to update inalloca to handle that case. The implicit sret pointer parameter was already handled this way, and this change generalizes some of that logic to arguments. There are two cases that this change leaves unfixed: 1. objects that are non-trivially copyable *and* overaligned 2. vectorcall + inalloca + vectors For case 1, I need to touch C++ ABI code in MicrosoftCXXABI.cpp, so I want to do it in a follow-up. For case 2, my fix is one line, but it will require updating IR tests to use lots of inreg, so I wanted to separate it out. Related to D71915 and D72110 Fixes most of PR44395 Reviewed By: rjmccall, craig.topper, erichkeane Differential Revision: https://reviews.llvm.org/D72114
53 lines
2.0 KiB
C++
53 lines
2.0 KiB
C++
// RUN: %clang_cc1 -fms-extensions -w -triple i386-pc-win32 -emit-llvm -o - %s | FileCheck %s
|
|
|
|
// PR44395
|
|
// MSVC passes overaligned types indirectly since MSVC 2015. Make sure that
|
|
// works with inalloca.
|
|
|
|
// FIXME: Pass non-trivial *and* overaligned types indirectly. Right now the C++
|
|
// ABI rules say to use inalloca, and they take precedence, so it's not easy to
|
|
// implement this.
|
|
|
|
|
|
struct NonTrivial {
|
|
NonTrivial();
|
|
NonTrivial(const NonTrivial &o);
|
|
int x;
|
|
};
|
|
|
|
struct __declspec(align(64)) OverAligned {
|
|
OverAligned();
|
|
int buf[16];
|
|
};
|
|
|
|
extern int gvi32;
|
|
|
|
int receive_inalloca_overaligned(NonTrivial nt, OverAligned o) {
|
|
return nt.x + o.buf[0];
|
|
}
|
|
|
|
// CHECK-LABEL: define dso_local i32 @"?receive_inalloca_overaligned@@Y{{.*}}"
|
|
// CHECK-SAME: (<{ %struct.NonTrivial, %struct.OverAligned* }>* inalloca %0)
|
|
|
|
int pass_inalloca_overaligned() {
|
|
gvi32 = receive_inalloca_overaligned(NonTrivial(), OverAligned());
|
|
return gvi32;
|
|
}
|
|
|
|
// CHECK-LABEL: define dso_local i32 @"?pass_inalloca_overaligned@@Y{{.*}}"
|
|
// CHECK: [[TMP:%[^ ]*]] = alloca %struct.OverAligned, align 64
|
|
// CHECK: call i8* @llvm.stacksave()
|
|
// CHECK: alloca inalloca <{ %struct.NonTrivial, %struct.OverAligned* }>
|
|
|
|
// Construct OverAligned into TMP.
|
|
// CHECK: call x86_thiscallcc %struct.OverAligned* @"??0OverAligned@@QAE@XZ"(%struct.OverAligned* [[TMP]])
|
|
|
|
// Construct NonTrivial into the GEP.
|
|
// CHECK: [[GEP:%[^ ]*]] = getelementptr inbounds <{ %struct.NonTrivial, %struct.OverAligned* }>, <{ %struct.NonTrivial, %struct.OverAligned* }>* %{{.*}}, i32 0, i32 0
|
|
// CHECK: call x86_thiscallcc %struct.NonTrivial* @"??0NonTrivial@@QAE@XZ"(%struct.NonTrivial* [[GEP]])
|
|
|
|
// Store the address of an OverAligned temporary into the struct.
|
|
// CHECK: getelementptr inbounds <{ %struct.NonTrivial, %struct.OverAligned* }>, <{ %struct.NonTrivial, %struct.OverAligned* }>* %{{.*}}, i32 0, i32 1
|
|
// CHECK: store %struct.OverAligned* [[TMP]], %struct.OverAligned** %{{.*}}, align 4
|
|
// CHECK: call i32 @"?receive_inalloca_overaligned@@Y{{.*}}"(<{ %struct.NonTrivial, %struct.OverAligned* }>* inalloca %argmem)
|