From 637ae302bf89bd601da0afb62b31ef1f79a38d71 Mon Sep 17 00:00:00 2001 From: Stefan Schulze Frielinghaus Date: Sat, 16 Jan 2021 10:20:33 +0100 Subject: CmmToC: Fix translation of Cmm literals to word sized literals For big-endian machines remove the byte swap in the non-recursive call of goSubWord since the integer is already in proper format. --- compiler/GHC/CmmToC.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/compiler/GHC/CmmToC.hs b/compiler/GHC/CmmToC.hs index 0733369679..d7596f0aac 100644 --- a/compiler/GHC/CmmToC.hs +++ b/compiler/GHC/CmmToC.hs @@ -525,13 +525,15 @@ staticLitsToWords platform = go . foldMap decomposeMultiWord goSubWord rem_bytes accum (lit : rest) | Just (bytes, w) <- isSubWordLit lit , rem_bytes >= widthInBytes w - = let accum' = - case platformByteOrder platform of - BigEndian -> (accum `shiftL` widthInBits w) .|. bytes - LittleEndian -> (accum `shiftL` widthInBits w) .|. byteSwap w bytes + = let accum' = (accum `shiftL` widthInBits w) .|. fixEndian w bytes in goSubWord (rem_bytes - widthInBytes w) accum' rest goSubWord rem_bytes accum rest - = pprWord (byteSwap (wordWidth platform) $ accum `shiftL` (8*rem_bytes)) : go rest + = pprWord (fixEndian (wordWidth platform) $ accum `shiftL` (8*rem_bytes)) : go rest + + fixEndian :: Width -> Integer -> Integer + fixEndian w = case platformByteOrder platform of + BigEndian -> id + LittleEndian -> byteSwap w -- Decompose multi-word or floating-point literals into multiple -- single-word (or smaller) literals. -- cgit v1.2.1