From 86aba5eeeee1048ccc5be60c76e35a1ed42d2fe6 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Fri, 7 Dec 2018 08:17:26 +0000 Subject: Fix thunks returning memptrs via sret by emitting also scalar return values directly in sret slot (PR39901) Thunks that return member pointers via sret are broken due to using temporary storage for the return value on the stack and then passing that pointer to a tail call, violating the rule that a tail call can't access allocas in the caller (see bug). Since r90526, we put aggregate return values directly in the sret slot, but this doesn't apply to member pointers which are considered scalar. Unless I'm missing something subtle, we should be able to always use the sret slot directly for indirect return values. Differential revision: https://reviews.llvm.org/D55371 llvm-svn: 348569 --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp') diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 7c7ba9d0c124..da8f327efa7c 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1073,9 +1073,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, // Count the implicit return. if (!endsWithReturn(D)) ++NumReturnExprs; - } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect && - !hasScalarEvaluationKind(CurFnInfo->getReturnType())) { - // Indirect aggregate return; emit returned value directly into sret slot. + } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect) { + // Indirect return; emit returned value directly into sret slot. // This reduces code size, and affects correctness in C++. auto AI = CurFn->arg_begin(); if (CurFnInfo->getReturnInfo().isSRetAfterThis()) -- cgit v1.2.3