From fe789978453bfd4e5ff456a6be57fc8041664d75 Mon Sep 17 00:00:00 2001
From: Sylvain Henry <sylvain@haskus.fr>
Date: Tue, 2 Feb 2021 14:41:41 +0100
Subject: IntVar: fix allocation size

As found by @phadej in https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4740/diffs#note_327510

Also fix FastMutInt which allocating the size in bits instead of bytes.
---
 libraries/base/GHC/Event/IntVar.hs | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

(limited to 'libraries/base/GHC')

diff --git a/libraries/base/GHC/Event/IntVar.hs b/libraries/base/GHC/Event/IntVar.hs
index f52deebd00..f973a34bfb 100644
--- a/libraries/base/GHC/Event/IntVar.hs
+++ b/libraries/base/GHC/Event/IntVar.hs
@@ -1,4 +1,5 @@
 {-# LANGUAGE Trustworthy #-}
+{-# LANGUAGE BangPatterns #-}
 {-# LANGUAGE CPP, MagicHash, NoImplicitPrelude, UnboxedTuples #-}
 
 module GHC.Event.IntVar
@@ -9,13 +10,15 @@ module GHC.Event.IntVar
     ) where
 
 import GHC.Base
+import GHC.Bits
 
 data IntVar = IntVar (MutableByteArray# RealWorld)
 
 newIntVar :: Int -> IO IntVar
 newIntVar n = do
+  let !(I# size) = finiteBitSize (0 :: Int) `unsafeShiftR` 3
   iv <- IO $ \s ->
-    case newByteArray# 1# s of
+    case newByteArray# size s of
       (# s', mba #) -> (# s', IntVar mba #)
   writeIntVar iv n
   return iv
-- 
cgit v1.2.1