-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Native macos arm compilers (4.10.2, 4.12.0) miscompile small recursive function #10339
Description
A little recursive function in Jape, which gets cached font information from Jape's Java interface, has a bizarre behaviour when compiled for ARM. It has worked for decades under previous compilers. It still works under 4.9.0 and 4.10.1 (producing x86 code), but fails under 4.10.2 and 4.12.0 (producing ARM code). I've managed (phew!) to produce a small example and show how a small modification to the function makes it work. The offending function is
let rec getfontname n =
try Array.get !fontnames n
with Invalid_argument _ ->
(if Array.length !fontnames = 0 then (* we never initialised it *) (
let fs = inputfonts() in
setFontNames fs; getfontname n )
else
raise (Catastrophe_ ["Japeserver.getfontname can't decode fontnumber ";
string_of_int n])
)
-- it is called with a small integer argument (0, 1 or 2) and if the array !fontnames is empty, initialises it and calls itself recursively. In the ARM compilation the recursive call uses what looks like a random large integer as argument (e.g. 2551454424 -- but it's not repeatable). The initialisation of the array happens, because subsequent calls to the function work as they should.
BUT if the function starts with an output command
let rec getfontname n =
output_string stderr "hello";
try Array.get !fontnames n
...
then it doesn't fail. I haven't found another way to block the bug.
I've built working and failing versions of a file which calls getfontname, using ocamlbuild, and attach them as zip files.