Commit d151546e authored by Cheng Shao's avatar Cheng Shao Committed by Marge Bot
Browse files

CmmToC: fix CmmRegOff for 64-bit register on a 32-bit target

We used to print the offset value to a platform word sized integer.
This is incorrect when the offset is negative (e.g. output of cmm
constant folding) and the register is 64-bit but on a 32-bit target,
and may lead to incorrect runtime result (e.g. #22607).

The fix is simple: just treat it as a proper MO_Add, with the correct
width info inferred from the register itself.

Metric Increase:
parent 05e6a2d9
Pipeline #62065 failed with stages
in 296 minutes and 40 seconds
......@@ -382,8 +382,8 @@ pprExpr platform e = case e of
CmmRegOff reg 0 -> pprCastReg reg
-- CmmRegOff is an alias of MO_Add
CmmRegOff reg i -> pprCastReg reg <> char '+' <>
pprHexVal platform (fromIntegral i) (wordWidth platform)
CmmRegOff reg i -> pprExpr platform $ CmmMachOp (MO_Add w) [CmmReg reg, CmmLit $ CmmInt (toInteger i) w]
where w = cmmRegWidth platform reg
CmmMachOp mop args -> pprMachOpApp platform mop args
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment