[Git][ghc/ghc][master] CgUtils.fixStgRegStmt respect register width

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Thu Oct 12 14:32:16 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
dafc4709 by Moritz Angermann at 2023-10-12T10:31:49-04:00
CgUtils.fixStgRegStmt respect register width

This change ensure that the reg + offset computation is always of the
same size.  Before this we could end up with a 64bit register, and then
add a 32bit offset (on 32bit platforms).  This not only would fail type
sanity checking, but also incorrectly truncate 64bit values into 32bit
values silently on 32bit architectures.

- - - - -


1 changed file:

- compiler/GHC/StgToCmm/CgUtils.hs


Changes:

=====================================
compiler/GHC/StgToCmm/CgUtils.hs
=====================================
@@ -177,16 +177,18 @@ fixStgRegStmt platform stmt = fixAssign $ mapExpDeep fixExpr stmt
                                      (globalRegSpillType platform reg)
                                      NaturallyAligned
 
-        CmmRegOff (CmmGlobal reg_use) offset ->
+        CmmRegOff greg@(CmmGlobal reg) offset ->
             -- RegOf leaves are just a shorthand form. If the reg maps
             -- to a real reg, we keep the shorthand, otherwise, we just
             -- expand it and defer to the above code.
-            let reg = globalRegUseGlobalReg reg_use in
-            case reg `elem` activeStgRegs platform of
+            -- NB: to ensure type correctness we need to ensure the Add
+            --     as well as the Int need to be of the same size as the
+            --     register.
+            case globalRegUseGlobalReg reg `elem` activeStgRegs platform of
                 True  -> expr
-                False -> CmmMachOp (MO_Add (wordWidth platform)) [
-                                    fixExpr (CmmReg (CmmGlobal reg_use)),
+                False -> CmmMachOp (MO_Add (cmmRegWidth greg)) [
+                                    fixExpr (CmmReg greg),
                                     CmmLit (CmmInt (fromIntegral offset)
-                                                   (wordWidth platform))]
+                                                   (cmmRegWidth greg))]
 
         other_expr -> other_expr



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dafc47091c9107dcf81e1e80a105f59211927c89
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/20231012/04df509e/attachment-0001.html>


More information about the ghc-commits mailing list