[project @ 2001-02-01 13:35:10 by sewardj]
authorsewardj <unknown>
Thu, 1 Feb 2001 13:35:10 +0000 (13:35 +0000)
committersewardj <unknown>
Thu, 1 Feb 2001 13:35:10 +0000 (13:35 +0000)
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
ghc/compiler/nativeGen/MachCode.lhs
ghc/compiler/nativeGen/StixPrim.lhs

index 3e828cf..150d5ea 100644 (file)
@@ -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
 
index c1dd01a..5939f60 100644 (file)
@@ -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}
index bd95692..c043f8d 100644 (file)
@@ -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