Incorrect behavior on arm64 with optimisations
I compiled ghc manually on a chromebook running ubuntu on aarch64 (arm64). I used
perf-llvm build during compilation. This might be related to https://ghc.haskell.org/trac/ghc/ticket/11578, but I am not sure how.
While working with stack and cabal I experienced unusually long compilation times or seemingly random build failures from time to time. Luckily, at some point I got very interesting error in package
Prelude> import qualified Data.Text as T Prelude T> T.splitOn (T.pack " ") (T.pack "Hello world!") ["Hello","world!\54497\44724?\NUL\54521\44724?\NUL\NUL\NUL\NUL\NUL\34560...BIG BLOB OF BYTES HERE...\NUL"]
By default this package compiles with
-O2, so I tried various options to determine when the result is correct and when is not.
To test this I used bare GHC installation and
cabal sandbox init && cabal install text --ghc-options="...").
Here is what I tried so far:
-O2 -fllvm -optlc-O3
-O1 -fllvm -optlc-O3
-O1 -fllvm -fliberate-case -fregs-graph -fspec-constr -optlc-O3
That is: when
text package is compiled with
-O2 the result of
Text.splitOn function is garbaged with random data; when it is compiled with
-O1, the result is correct.
text is represented using
ByteArray# internally, I would suggest something is wrong with
ByteArray#'s length attribute, but I am not sure.