From d5ab93c4a8e45da2dab8924c2165000bf78f84e6 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Tue, 23 Feb 2021 03:31:00 -0800 Subject: [PATCH] Fix ArgIterator::GetNextOffset for macOS arm64 (#48632) * Fix ArgIterator::GetNextOffset for macOS arm64 The ArgIterator::GetNextOffset method was not aligning offsets it returns for reference types and some others. That was causing coreclr test failures with GCStress mode 3. This change fixes it by properly aligning the returned offsets. * Fix indentation --- src/coreclr/vm/callingconvention.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/callingconvention.h b/src/coreclr/vm/callingconvention.h index 8a1e934d3d78d..deab21ca97efe 100644 --- a/src/coreclr/vm/callingconvention.h +++ b/src/coreclr/vm/callingconvention.h @@ -1437,7 +1437,8 @@ int ArgIteratorTemplate::GetNextOffset() break; } const bool isValueType = (argType == ELEMENT_TYPE_VALUETYPE); - const int cbArg = StackElemSize(argSize, isValueType, thValueType.IsFloatHfa()); + const bool isFloatHfa = thValueType.IsFloatHfa(); + const int cbArg = StackElemSize(argSize, isValueType, isFloatHfa); if (cFPRegs>0 && !this->IsVarArg()) { if (cFPRegs + m_idxFPReg <= 8) @@ -1495,6 +1496,24 @@ int ArgIteratorTemplate::GetNextOffset() } } +#ifdef OSX_ARM64_ABI + int alignment; + if (!isValueType) + { + _ASSERTE((cbArg & (cbArg - 1)) == 0); + alignment = cbArg; + } + else if (isFloatHfa) + { + alignment = 4; + } + else + { + alignment = 8; + } + m_ofsStack = (int)ALIGN_UP(m_ofsStack, alignment); +#endif // OSX_ARM64_ABI + int argOfs = TransitionBlock::GetOffsetOfArgs() + m_ofsStack; m_ofsStack += cbArg; return argOfs;