[Git][ghc/ghc][wip/supersven/riscv64-ncg] Truncate C return values to their expected width

Sven Tennie (@supersven) gitlab at gitlab.haskell.org
Fri Aug 18 16:57:20 UTC 2023



Sven Tennie pushed to branch wip/supersven/riscv64-ncg at Glasgow Haskell Compiler / GHC


Commits:
ce2612c1 by Sven Tennie at 2023-08-18T18:55:54+02:00
Truncate C return values to their expected width

Otherwise, values that may be too big are floating around.

- - - - -


1 changed file:

- compiler/GHC/CmmToAsm/RV64/CodeGen.hs


Changes:

=====================================
compiler/GHC/CmmToAsm/RV64/CodeGen.hs
=====================================
@@ -1823,7 +1823,11 @@ genCCall target dest_regs arg_regs bid = do
           r_dst = getRegisterReg platform (CmmLocal dst)
       if isFloatFormat format
         then readResults (gpReg:gpRegs) fpRegs dsts (fpReg:accumRegs) (accumCode `snocOL` MOV (OpReg w r_dst) (OpReg w fpReg))
-        else readResults gpRegs (fpReg:fpRegs) dsts (gpReg:accumRegs) (accumCode `snocOL` MOV (OpReg w r_dst) (OpReg w gpReg))
+        else readResults gpRegs (fpReg:fpRegs) dsts (gpReg:accumRegs) $
+          accumCode `snocOL`
+          MOV (OpReg w r_dst) (OpReg w gpReg) `appOL`
+          -- truncate, otherwise an unexpectedly big value might be used in upfollowing calculations
+          truncateReg W64 w r_dst
 
     unaryFloatOp w op arg_reg dest_reg = do
       platform <- getPlatform



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ce2612c1726f5e0d5ba212eac0fbd5bb549d4cf6

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ce2612c1726f5e0d5ba212eac0fbd5bb549d4cf6
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230818/de35e9e1/attachment-0001.html>


More information about the ghc-commits mailing list