MS ABI: Pass 'sret' as the second parameter of instance methods

Summary:
MSVC always passes 'sret' after 'this', unlike GCC.  This required
changing a number of places in Clang that assumed the sret parameter was
always first in LLVM IR.

This fixes win64 MSVC ABI compatibility for methods returning structs.

Reviewers: rsmith, majnemer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D3618

llvm-svn: 208458
This commit is contained in:
Reid Kleckner
2014-05-09 22:46:15 +00:00
parent 46e1ecdecc
commit 37abaca3c2
9 changed files with 108 additions and 41 deletions

View File

@@ -622,7 +622,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
!hasScalarEvaluationKind(CurFnInfo->getReturnType())) {
// Indirect aggregate return; emit returned value directly into sret slot.
// This reduces code size, and affects correctness in C++.
ReturnValue = CurFn->arg_begin();
auto AI = CurFn->arg_begin();
if (CurFnInfo->getReturnInfo().isSRetAfterThis())
++AI;
ReturnValue = AI;
} else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca &&
!hasScalarEvaluationKind(CurFnInfo->getReturnType())) {
// Load the sret pointer from the argument struct and return into that.