Closed anfelor closed 8 months ago
Weirdly, the asan output suggests that something goes wrong when inserting elements into the heap in the from-list
function. But when I tested the code on the Koka shell, the from-list
function never segfaulted, while the to-list
function segfaulted roughly as often as the heapsort
function. But when I minimized this example to contain only the to-list
function no segfaults appeared.
Also, if you play around with this enough on the Koka shell it will start printing garbage and some of the programs code at some point; which suggests that some overflow happens and raw heap contents are printed into the shell.
I compiled with -O-1 to disable all gcc optimizations and see that this assertion fails:
home_steven_Downloads_binomial_dash_heaps_dash_okasaki: /usr/local/share/koka/v2.1.9/kklib/include/kklib.h:616: kk_block_dropn: Assertion `scan_fsize == kk_block_scan_fsize(b)' failed.
Aborted (core dumped)
Both debug and optimized builds run fine for me now.
You can find a fairly short Koka implementation of heapsort based on Binomial Heaps (as discussed by Okasaki) here: https://gist.github.com/anfelor/f6d6e437d9d47f77534cace1904bbe5e (I couldn't reduce this further; this is a tricky bug!)
When run (Koka v2.1.9, macOS with M1 processor), this will sometimes print the correct answer
[1,2,3]
; but often crash. I modified Koka to call asan without the 'leak' option (which doesn't work on M1 macs) and got:EDIT: The '--fasan' output is the same each run under both gcc and clang and it seems like the program will always crash with this option enabled.