diff options
author | Ben Gamari <ben@well-typed.com> | 2022-06-23 12:41:12 -0400 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2022-07-05 11:14:19 +0100 |
commit | 401d983beebed72cd43c5597b5d1bc52979feb46 (patch) | |
tree | a2c140e1b953e99025ba3e4c8385f44b300f1363 | |
parent | 5582203d5ad81fabda5662c88e813375e1b06c7e (diff) | |
download | haskell-401d983beebed72cd43c5597b5d1bc52979feb46.tar.gz |
CmmToAsm/AArch64: Sign-extend narrow C arguments
The AArch64/Darwin ABI requires that function arguments narrower
than 32-bits must be sign-extended by the caller. We neglected to
do this, resulting in #20735.
Fixes #20735.
(cherry picked from commit 696d64c347364ce75e23d37884ec0bd2543b0a6a)
-rw-r--r-- | compiler/GHC/CmmToAsm/AArch64/CodeGen.hs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/compiler/GHC/CmmToAsm/AArch64/CodeGen.hs b/compiler/GHC/CmmToAsm/AArch64/CodeGen.hs index 246f767b87..f77d3b2d84 100644 --- a/compiler/GHC/CmmToAsm/AArch64/CodeGen.hs +++ b/compiler/GHC/CmmToAsm/AArch64/CodeGen.hs @@ -1580,9 +1580,21 @@ genCCall target dest_regs arg_regs bid = do -- size we want to pack. Failure to get this right can result in pretty -- subtle bugs, e.g. #20137. - passArguments pack (gpReg:gpRegs) fpRegs ((r, format, _hint, code_r):args) stackSpace accumRegs accumCode | isIntFormat format = do + passArguments pack (gpReg:gpRegs) fpRegs ((r, format, hint, code_r):args) stackSpace accumRegs accumCode | isIntFormat format = do + platform <- getPlatform let w = formatToWidth format - mov = MOV (OpReg w gpReg) (OpReg w r) + mov + -- Specifically, Darwin/AArch64's ABI requires that the caller + -- sign-extend arguments which are smaller than 32-bits. + | w < W32 + , platformCConvNeedsExtension platform + , SignedHint <- hint + = case w of + W8 -> SXTB (OpReg W64 gpReg) (OpReg w r) + W16 -> SXTH (OpReg W64 gpReg) (OpReg w r) + _ -> panic "impossible" + | otherwise + = MOV (OpReg w gpReg) (OpReg w r) accumCode' = accumCode `appOL` code_r `snocOL` ann (text "Pass gp argument: " <> ppr r) mov |