[Git][ghc/ghc][master] ghc-heap: remove wrong Addr# coercion (#23181)

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Mon Apr 3 12:15:45 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
ab9cd52d by Sylvain Henry at 2023-04-03T08:15:21-04:00
ghc-heap: remove wrong Addr# coercion (#23181)

Conversion from Addr# to I# isn't correct with the JS backend.

- - - - -


3 changed files:

- libraries/ghc-heap/GHC/Exts/Heap.hs
- libraries/ghc-heap/GHC/Exts/Heap/Closures.hs
- libraries/ghc-heap/tests/heap_all.hs


Changes:

=====================================
libraries/ghc-heap/GHC/Exts/Heap.hs
=====================================
@@ -120,7 +120,7 @@ instance Word64# ~ a => HasHeapRep (a :: TYPE 'Word64Rep) where
 
 instance Addr# ~ a => HasHeapRep (a :: TYPE 'AddrRep) where
     getClosureData x = return $
-        AddrClosure { ptipe = PAddr, addrVal = I# (unsafeCoerce# x) }
+        AddrClosure { ptipe = PAddr, addrVal = Ptr x }
 
 instance Float# ~ a => HasHeapRep (a :: TYPE 'FloatRep) where
     getClosureData x = return $


=====================================
libraries/ghc-heap/GHC/Exts/Heap/Closures.hs
=====================================
@@ -329,7 +329,7 @@ data GenClosure b
     -- | Primitive Addr
   | AddrClosure
         { ptipe      :: PrimType
-        , addrVal    :: !Int }
+        , addrVal    :: !(Ptr ()) }
 
     -- | Primitive Float
   | FloatClosure


=====================================
libraries/ghc-heap/tests/heap_all.hs
=====================================
@@ -12,6 +12,7 @@ import GHC.Int
 import GHC.IO
 import GHC.IORef
 import GHC.MVar
+import GHC.Ptr
 import GHC.Stack
 import GHC.STRef
 import GHC.Weak
@@ -176,7 +177,7 @@ exWord64Closure = Word64Closure
 
 exAddrClosure :: Closure
 exAddrClosure = AddrClosure
-    { ptipe = PAddr, addrVal = 42 }
+    { ptipe = PAddr, addrVal = nullPtr `plusPtr` 42 }
 
 exFloatClosure :: Closure
 exFloatClosure = FloatClosure
@@ -328,7 +329,7 @@ main = do
     --     assertClosuresEq exWord64Closure
 
     -- Primitive Addr
-    let v = unsafeCoerce# 42# :: Addr#
+    let (Ptr v) = nullPtr `plusPtr` 42
     getClosureData v >>=
         assertClosuresEq exAddrClosure
 



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ab9cd52d4fac34a2b37ce07bc9e9e2943c92d181

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ab9cd52d4fac34a2b37ce07bc9e9e2943c92d181
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230403/b124685f/attachment-0001.html>


More information about the ghc-commits mailing list