summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2022-05-23 22:59:44 -0400
committerMatthew Pickering <matthewtpickering@gmail.com>2022-07-05 11:01:44 +0100
commitad5901afeaff9f4427787da059414e8004985277 (patch)
tree8a08884ee9f1a7a6c52960642ac2dc349d0539e9
parent2cb9dea45ca5298f959937a00d84a89a75441f6b (diff)
downloadhaskell-ad5901afeaff9f4427787da059414e8004985277.tar.gz
ghc-heap: Add (broken) test for #21622
(cherry picked from commit 229d741f9907f0a07c475291fe3b1dbfcfea7aab)
-rw-r--r--libraries/ghc-heap/tests/T21622.hs25
-rw-r--r--libraries/ghc-heap/tests/T21622.stdout1
-rw-r--r--libraries/ghc-heap/tests/all.T3
3 files changed, 29 insertions, 0 deletions
diff --git a/libraries/ghc-heap/tests/T21622.hs b/libraries/ghc-heap/tests/T21622.hs
new file mode 100644
index 0000000000..db53ad8722
--- /dev/null
+++ b/libraries/ghc-heap/tests/T21622.hs
@@ -0,0 +1,25 @@
+{-# OPTIONS_GHC -O0 #-}
+{-# LANGUAGE MagicHash #-}
+
+import Control.Monad
+import GHC.Exts.Heap
+import System.Mem
+import GHC.Exts
+import GHC.Weak
+
+main :: IO ()
+main = do
+ let x = 42 :: Integer
+ Weak w <- mkWeak x () Nothing
+ weaks <- collectWeaks w
+ performMajorGC
+ print (x, fmap length weaks)
+
+collectWeaks :: Weak# v -> IO [Closure]
+collectWeaks = \w -> getClosureData w >>= go []
+ where
+ go :: [Closure] -> Closure -> IO [Closure]
+ go acc w@(WeakClosure {link})
+ | next <- link = getBoxedClosureData next >>= go (w:acc)
+ | otherwise = return (w:acc)
+
diff --git a/libraries/ghc-heap/tests/T21622.stdout b/libraries/ghc-heap/tests/T21622.stdout
new file mode 100644
index 0000000000..afb09db1ba
--- /dev/null
+++ b/libraries/ghc-heap/tests/T21622.stdout
@@ -0,0 +1 @@
+(42,[4,5])
diff --git a/libraries/ghc-heap/tests/all.T b/libraries/ghc-heap/tests/all.T
index fcafb9fa45..95a5426358 100644
--- a/libraries/ghc-heap/tests/all.T
+++ b/libraries/ghc-heap/tests/all.T
@@ -51,3 +51,6 @@ test('parse_tso_flags',
ignore_stderr
],
compile_and_run, [''])
+test('T21622',
+ [expect_broken(21622), only_ways(['normal'])],
+ compile_and_run, [''])