From e5d9aaa2b7b717c862651f8eea5e2dc66f0a8028 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Thu, 8 Nov 2007 13:28:42 +0000 Subject: [PATCH] Pad static literals to word size in the code generator --- compiler/cmm/PprC.hs | 7 ++++++- compiler/codeGen/CgHeapery.lhs | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/compiler/cmm/PprC.hs b/compiler/cmm/PprC.hs index 47a2315..c7d0cf1 100644 --- a/compiler/cmm/PprC.hs +++ b/compiler/cmm/PprC.hs @@ -145,7 +145,6 @@ pprTop top@(CmmData _section (CmmDataLabel lbl : lits)) = -- these shouldn't appear? pprTop (CmmData _ _) = panic "PprC.pprTop: can't handle this data" - -- -------------------------------------------------------------------------- -- BasicBlocks are self-contained entities: they always end in a jump. -- @@ -426,7 +425,13 @@ pprLit1 other = pprLit other pprStatics :: [CmmStatic] -> [SDoc] pprStatics [] = [] pprStatics (CmmStaticLit (CmmFloat f F32) : rest) + -- floats are padded to a word, see #1852 + | wORD_SIZE == 8, CmmStaticLit (CmmInt 0 I32) : rest' <- rest + = pprLit1 (floatToWord f) : pprStatics rest' + | wORD_SIZE == 4 = pprLit1 (floatToWord f) : pprStatics rest + | otherwise + = pprPanic "pprStatics: float" (vcat (map (\(CmmStaticLit l) -> ppr (cmmLitRep l)) rest)) pprStatics (CmmStaticLit (CmmFloat f F64) : rest) = map pprLit1 (doubleToWords f) ++ pprStatics rest pprStatics (CmmStaticLit (CmmInt i I64) : rest) diff --git a/compiler/codeGen/CgHeapery.lhs b/compiler/codeGen/CgHeapery.lhs index cef14cf..9cb1bb4 100644 --- a/compiler/codeGen/CgHeapery.lhs +++ b/compiler/codeGen/CgHeapery.lhs @@ -231,7 +231,7 @@ mkStaticClosure :: CLabel -> CostCentreStack -> [CmmLit] mkStaticClosure info_lbl ccs payload padding_wds static_link_field saved_info_field = [CmmLabel info_lbl] ++ variable_header_words - ++ payload + ++ concatMap padLitToWord payload ++ padding_wds ++ static_link_field ++ saved_info_field @@ -241,6 +241,17 @@ mkStaticClosure info_lbl ccs payload padding_wds static_link_field saved_info_fi ++ staticParHdr ++ staticProfHdr ccs ++ staticTickyHdr + +padLitToWord :: CmmLit -> [CmmLit] +padLitToWord lit = lit : padding pad_length + where rep = cmmLitRep lit + pad_length = wORD_SIZE - machRepByteWidth rep :: Int + + padding n | n <= 0 = [] + | n `rem` 2 /= 0 = CmmInt 0 I8 : padding (n-1) + | n `rem` 4 /= 0 = CmmInt 0 I16 : padding (n-2) + | n `rem` 8 /= 0 = CmmInt 0 I32 : padding (n-4) + | otherwise = CmmInt 0 I64 : padding (n-8) \end{code} %************************************************************************ -- 1.7.10.4