Program crashes only when compiled via LLVM
llvm-test.hs:
import System.IO
import Foreign.Storable
import Foreign.Marshal.Alloc
import Data.Word
main = do
hSetBuffering stdout NoBuffering
test 1000
test 5000
where
test n = do
allocaBytes (n * 4) $ \p -> do
sequence_ [
pokeByteOff p (i * 4) (0x12345678 :: Word32)
| i <- [ 0 .. n - 1 ]
]
putStrLn $ show n ++ " fine"
Cygwin shell:
user@pc ~
$ ghc llvm-test.hs && ./llvm-test.exe
[1 of 1] Compiling Main ( llvm-test.hs, llvm-test.o )
Linking llvm-test.exe ...
1000 fine
5000 fine
user@pc ~
$ touch llvm-test.hs
user@pc ~
$ ghc llvm-test.hs -fllvm && ./llvm-test.exe
[1 of 1] Compiling Main ( llvm-test.hs, llvm-test.o )
Linking llvm-test.exe ...
1000 fine
Segmentation fault
<erikd> `Guest00000: try adding -O2 to the compiler command line.
<`Guest00000> erikd: it now segfaults even before printing "1000 fine"
<`Guest00000> wait, one time it printed one character "1" before crashing
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.10.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | None |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |