Commit cf4f1e2f authored by Ben Gamari's avatar Ben Gamari 🐢 Committed by Marge Bot

rts/CNF: Fix fixup comparison function

Previously we would implicitly convert the difference between two words
to an int, resulting in an integer overflow on 64-bit machines.

Fixes #16992
parent b352d63c
import Data.Bifunctor
import Foreign.Ptr
import qualified Data.ByteString as BS
import qualified Data.ByteString.Unsafe as BS
import qualified GHC.Compact as Compact
import qualified GHC.Compact.Serialized as CompactSerialize
-- | Minimal test case for reproducing compactFixupPointers# bug for large compact regions.
-- See Issue #16992.
main :: IO ()
main = do
let
large = 1024 * 1024 * 128
largeString = replicate large 'A'
region <- Compact.compact largeString
Just deserialized <- CompactSerialize.withSerializedCompact region $ \s -> do
blks <- mapM (BS.unsafePackCStringLen . bimap castPtr fromIntegral) (CompactSerialize.serializedCompactBlockList s)
CompactSerialize.importCompactByteStrings s blks
print (Compact.getCompact deserialized == largeString)
......@@ -22,3 +22,8 @@ test('compact_share', omit_ways(['ghci', 'profasm', 'profthreaded']),
test('compact_bench', [ ignore_stdout, extra_run_opts('100') ],
compile_and_run, [''])
test('T17044', normal, compile_and_run, [''])
# N.B. Sanity check times out due to large list.
test('T16992', [when(wordsize(32), skip), # Resource limit exceeded on 32-bit
high_memory_usage,
run_timeout_multiplier(5),
omit_ways(['sanity'])], compile_and_run, [''])
......@@ -1020,8 +1020,9 @@ cmp_fixup_table_item (const void *e1, const void *e2)
{
const StgWord *w1 = e1;
const StgWord *w2 = e2;
return *w1 - *w2;
if (*w1 > *w2) return +1;
else if (*w1 < *w2) return -1;
else return 0;
}
static StgWord *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment