summaryrefslogtreecommitdiff
path: root/testsuite/tests/codeGen
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-01-22 16:45:59 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-01-31 18:46:47 -0500
commit58eccdbc0d46f37cabcb52c3f93b640ff90b24ed (patch)
tree229484e309dbcd41d7a536fad2995b7e1c21948b /testsuite/tests/codeGen
parent60a54a8f3681869142b0967749a6999b22bad76a (diff)
downloadhaskell-58eccdbc0d46f37cabcb52c3f93b640ff90b24ed.tar.gz
codeGen: Fix two buglets in -fbounds-check logic
@Bodigrim noticed that the `compareByteArray#` bounds-checking logic had flipped arguments and an off-by-one. For the sake of clarity I also refactored occurrences of `cmmOffset` to rather use `cmmOffsetB`. I suspect the former should be retired.
Diffstat (limited to 'testsuite/tests/codeGen')
-rw-r--r--testsuite/tests/codeGen/should_fail/CheckBoundsCompareByteArray.hs19
-rw-r--r--testsuite/tests/codeGen/should_fail/all.T1
2 files changed, 20 insertions, 0 deletions
diff --git a/testsuite/tests/codeGen/should_fail/CheckBoundsCompareByteArray.hs b/testsuite/tests/codeGen/should_fail/CheckBoundsCompareByteArray.hs
new file mode 100644
index 0000000000..e20dcc1647
--- /dev/null
+++ b/testsuite/tests/codeGen/should_fail/CheckBoundsCompareByteArray.hs
@@ -0,0 +1,19 @@
+{-# LANGUAGE NondecreasingIndentation #-}
+{-# LANGUAGE UnboxedTuples #-}
+{-# LANGUAGE MagicHash #-}
+
+module Main where
+
+import GHC.Exts
+import GHC.IO
+
+main :: IO ()
+main = do
+ IO $ \s0 ->
+ case newByteArray# 4# s0 of
+ (# s1, a_marr #) -> case newByteArray# 4# s1 of
+ (# s2, b_marr #) -> case unsafeFreezeByteArray# a_marr s2 of
+ (# s3, a_arr #) -> case unsafeFreezeByteArray# b_marr s2 of
+ (# s4, b_arr #) -> case compareByteArrays# a_arr 0# b_arr 1# 4# of
+ 0# -> (# s4, () #)
+
diff --git a/testsuite/tests/codeGen/should_fail/all.T b/testsuite/tests/codeGen/should_fail/all.T
index 01a4802d09..e23fa03f82 100644
--- a/testsuite/tests/codeGen/should_fail/all.T
+++ b/testsuite/tests/codeGen/should_fail/all.T
@@ -15,4 +15,5 @@ check_bounds_test('CheckBoundsIndexArray')
check_bounds_test('CheckBoundsReadInt8Array')
check_bounds_test('CheckBoundsReadWord8ArrayAsInt32')
check_bounds_test('CheckBoundsCopyByteArray')
+check_bounds_test('CheckBoundsCompareByteArray')