Skip to content
Snippets Groups Projects
Commit 6abc5456 authored by Ben Gamari's avatar Ben Gamari
Browse files

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

(cherry picked from commit c00c81a5)
parent 49a68ebf
No related branches found
No related tags found
No related merge requests found
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)
True
...@@ -22,3 +22,8 @@ test('compact_share', omit_ways(['ghci', 'profasm', 'profthreaded']), ...@@ -22,3 +22,8 @@ test('compact_share', omit_ways(['ghci', 'profasm', 'profthreaded']),
test('compact_bench', [ ignore_stdout, extra_run_opts('100') ], test('compact_bench', [ ignore_stdout, extra_run_opts('100') ],
compile_and_run, ['']) compile_and_run, [''])
test('T17044', normal, 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, [''])
...@@ -1016,8 +1016,9 @@ cmp_fixup_table_item (const void *e1, const void *e2) ...@@ -1016,8 +1016,9 @@ cmp_fixup_table_item (const void *e1, const void *e2)
{ {
const StgWord *w1 = e1; const StgWord *w1 = e1;
const StgWord *w2 = e2; const StgWord *w2 = e2;
if (*w1 > *w2) return +1;
return *w1 - *w2; else if (*w1 < *w2) return -1;
else return 0;
} }
static StgWord * static StgWord *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment