From 9e358c7e473ea6fdf8766b4944bc827adc41e5f0 Mon Sep 17 00:00:00 2001 From: sewardj Date: Thu, 1 Feb 2001 13:35:10 +0000 Subject: [PATCH] [project @ 2001-02-01 13:35:10 by sewardj] Fix a long-standing roaring bogon in mangleIndexTree, to do with not-necessarily-valid assumptions about PrimRep sizes. In future all enquiries about PrimRep sizes should go via MachMisc.primRepToSize and/or MachMisc.sizeOf. The Lord preserve us from random, unportable hacks in the NCG. --- ghc/compiler/nativeGen/AbsCStixGen.lhs | 6 +++--- ghc/compiler/nativeGen/MachCode.lhs | 15 +++++++++------ ghc/compiler/nativeGen/StixPrim.lhs | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ghc/compiler/nativeGen/AbsCStixGen.lhs b/ghc/compiler/nativeGen/AbsCStixGen.lhs index 3e828cf..150d5ea 100644 --- a/ghc/compiler/nativeGen/AbsCStixGen.lhs +++ b/ghc/compiler/nativeGen/AbsCStixGen.lhs @@ -221,9 +221,9 @@ Here we handle top-level things, like @CCodeBlock@s and = StData (promote_to_word (getAmodeRep amode)) [a2stix amode] -- We need to promote any item smaller than a word to a word - promote_to_word Int8Rep = IntRep - promote_to_word CharRep = IntRep - promote_to_word other = other + promote_to_word pk + | sizeOf pk >= sizeOf IntRep = pk + | otherwise = IntRep upd_reqd = closureUpdReqd cl_info diff --git a/ghc/compiler/nativeGen/MachCode.lhs b/ghc/compiler/nativeGen/MachCode.lhs index c1dd01a..5939f60 100644 --- a/ghc/compiler/nativeGen/MachCode.lhs +++ b/ghc/compiler/nativeGen/MachCode.lhs @@ -156,14 +156,17 @@ mangleIndexTree (StIndex pk base off) = StPrim IntAddOp [ base, let s = shift pk - in ASSERT(toInteger s == expectJust "MachCode" (exactLog2 (sizeOf pk))) - if s == 0 then off else StPrim SllOp [off, StInt s] + in if s == 0 then off else StPrim SllOp [off, StInt (toInteger s)] ] where - shift DoubleRep = 3::Integer - shift CharRep = 2::Integer - shift Int8Rep = 0::Integer - shift _ = IF_ARCH_alpha(3,2) + shift :: PrimRep -> Int + shift rep = case (fromInteger (sizeOf rep) :: Int) of + 1 -> 0 + 2 -> 1 + 4 -> 2 + 8 -> 3 + other -> pprPanic "MachCode.mangleIndexTree.shift: unhandled rep size" + (int other) \end{code} \begin{code} diff --git a/ghc/compiler/nativeGen/StixPrim.lhs b/ghc/compiler/nativeGen/StixPrim.lhs index bd95692..c043f8d 100644 --- a/ghc/compiler/nativeGen/StixPrim.lhs +++ b/ghc/compiler/nativeGen/StixPrim.lhs @@ -232,6 +232,7 @@ primCode ls IndexOffForeignObjOp_StablePtr rs = primCode_IndexOffForeignObjOp St primCode ls IndexOffForeignObjOp_Int64 rs = primCode_IndexOffForeignObjOp Int64Rep ls rs primCode ls IndexOffForeignObjOp_Word64 rs = primCode_IndexOffForeignObjOp Word64Rep ls rs +primCode ls WriteOffAddrOp_Word8 rs = primCode_WriteOffAddrOp Word8Rep ls rs primCode ls WriteOffAddrOp_Char rs = primCode_WriteOffAddrOp Word8Rep ls rs primCode ls WriteOffAddrOp_Int rs = primCode_WriteOffAddrOp IntRep ls rs primCode ls WriteOffAddrOp_Word rs = primCode_WriteOffAddrOp WordRep ls rs -- 1.7.10.4