From 9587726f53e51e429bdb8d8ca11f9de4d0902b77 Mon Sep 17 00:00:00 2001
From: Ben Gamari <ben@smart-cactus.org>
Date: Wed, 2 Mar 2022 14:26:40 -0500
Subject: [PATCH] testsuite: Add testcase for #21141

---
 testsuite/tests/codeGen/should_run/T21141.hs | 26 ++++++++++++++++++++
 testsuite/tests/codeGen/should_run/all.T     |  1 +
 2 files changed, 27 insertions(+)
 create mode 100644 testsuite/tests/codeGen/should_run/T21141.hs

diff --git a/testsuite/tests/codeGen/should_run/T21141.hs b/testsuite/tests/codeGen/should_run/T21141.hs
new file mode 100644
index 000000000000..f972eca4774b
--- /dev/null
+++ b/testsuite/tests/codeGen/should_run/T21141.hs
@@ -0,0 +1,26 @@
+{-# LANGUAGE BlockArguments #-}
+{-# LANGUAGE LambdaCase #-}
+
+module Main where
+
+import GHC.Prim.Exception
+import GHC.Exception.Type
+import Control.Exception
+import System.Mem
+
+main ::IO ()
+main = do
+  -- evaluate the CAF
+  evaluate raiseUnderflow
+    `catch` \case
+      Underflow -> pure ()
+      e         -> putStrLn "Unexpected exception"
+
+  -- free it with buggy compiler
+  performGC
+
+  -- reuse it
+  evaluate raiseUnderflow
+    `catch` \case
+      Underflow -> pure ()
+      e         -> putStrLn "Unexpected exception"
diff --git a/testsuite/tests/codeGen/should_run/all.T b/testsuite/tests/codeGen/should_run/all.T
index 654db78d43e1..af3a91d02645 100644
--- a/testsuite/tests/codeGen/should_run/all.T
+++ b/testsuite/tests/codeGen/should_run/all.T
@@ -216,6 +216,7 @@ test('CallConv', [when(unregisterised(), skip),
                   when(arch('x86_64'), extra_hc_opts('CallConv_x86_64.s')),
                   when(arch('aarch64'), extra_hc_opts('CallConv_aarch64.s'))],
      compile_and_run, [''])
+test('T21141', normal, compile_and_run, [''])
 test('T21186', normal, compile_and_run, [''])
 test('T20640a', normal, compile_and_run, [''])
 test('T20640b', normal, compile_and_run, [''])
-- 
GitLab