Skip to content

Commit f697eab

Browse files
hmelderdavidchisnall
authored andcommitted
Use objc_msgSend_stret2_np when returning a non-trivial data type on woa64
1 parent 02660e2 commit f697eab

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,6 +1585,11 @@ bool CodeGenModule::ReturnTypeUsesSRet(const CGFunctionInfo &FI) {
15851585
return RI.isIndirect() || (RI.isInAlloca() && RI.getInAllocaSRet());
15861586
}
15871587

1588+
bool CodeGenModule::ReturnTypeHasInReg(const CGFunctionInfo &FI) {
1589+
const auto &RI = FI.getReturnInfo();
1590+
return RI.getInReg();
1591+
}
1592+
15881593
bool CodeGenModule::ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI) {
15891594
return ReturnTypeUsesSRet(FI) &&
15901595
getTargetCodeGenInfo().doesReturnSlotInterfereWithArgs();

clang/lib/CodeGen/CGObjCGNU.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,12 +2911,25 @@ CGObjCGNU::GenerateMessageSend(CodeGenFunction &CGF,
29112911
"objc_msgSend_fpret")
29122912
.getCallee();
29132913
} else if (CGM.ReturnTypeUsesSRet(MSI.CallInfo)) {
2914+
StringRef name = "objc_msgSend_stret";
2915+
2916+
// The address of the memory block is be passed in x8 for POD type,
2917+
// or in x0 for non-POD type (marked as inreg).
2918+
bool shouldCheckForInReg =
2919+
CGM.getContext()
2920+
.getTargetInfo()
2921+
.getTriple()
2922+
.isWindowsMSVCEnvironment() &&
2923+
CGM.getContext().getTargetInfo().getTriple().isAArch64();
2924+
if (shouldCheckForInReg && CGM.ReturnTypeHasInReg(MSI.CallInfo)) {
2925+
name = "objc_msgSend_stret2_np";
2926+
}
2927+
29142928
// The actual types here don't matter - we're going to bitcast the
29152929
// function anyway
2916-
imp =
2917-
CGM.CreateRuntimeFunction(llvm::FunctionType::get(IdTy, IdTy, true),
2918-
"objc_msgSend_stret")
2919-
.getCallee();
2930+
CGM.CreateRuntimeFunction(llvm::FunctionType::get(IdTy, IdTy, true),
2931+
name)
2932+
.getCallee();
29202933
} else {
29212934
imp = CGM.CreateRuntimeFunction(
29222935
llvm::FunctionType::get(IdTy, IdTy, true), "objc_msgSend")

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,9 @@ class CodeGenModule : public CodeGenTypeCache {
12411241
/// Return true iff the given type uses 'sret' when used as a return type.
12421242
bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
12431243

1244+
/// Return true iff the given type has `inreg` set.
1245+
bool ReturnTypeHasInReg(const CGFunctionInfo &FI);
1246+
12441247
/// Return true iff the given type uses an argument slot when 'sret' is used
12451248
/// as a return type.
12461249
bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI);

0 commit comments

Comments
 (0)