Computing the sum of all the primes below two million leads to a runtime system crash
The following program is meant to be a solution to Problem 10 from Project Euler (http://projecteuler.net/problem=10):
manzyuk@pandora:~/tmp$ cat euler-10.hs
sumOfPrimes n = sieve [2..n] 0
where
sieve [] s = s
sieve (x:xs) s = sieve [y | y <- xs, y `mod` x /= 0] (x+s)
main = print (sumOfPrimes 2000000)
Compiling and running this program on my 64-bit Linux machine results either in a segmentation fault:
manzyuk@pandora:~/tmp$ uname -a
Linux pandora 2.6.32-5-amd64 #1 SMP Fri Sep 9 20:23:16 UTC 2011 x86_64 GNU/Linux
manzyuk@pandora:~/tmp$ ghc --make -O euler-10.hs
[1 of 1] Compiling Main ( euler-10.hs, euler-10.o )
Linking euler-10 ...
manzyuk@pandora:~/tmp$ time ./euler-10
Segmentation fault
real 0m44.073s
user 0m44.031s
sys 0m0.028s
or in the following error message:
manzyuk@pandora:~/tmp$ time ./euler-10
euler-10: internal error: scavenge_stack: weird activation record found on stack: -1958211512
(GHC version 7.0.3 for x86_64_unknown_linux)
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
Aborted
real 0m54.780s
user 0m54.723s
sys 0m0.040s
The expected behavior is to output a number (142913828922, if I am not mistaken).
The version of gcc
I am running:
manzyuk@pandora:~/tmp$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
I am attaching the output of GHC when compiling the program with the -v
flag. Compiling the program with the -dcore-lint
flag didn't reveal anything interesting:
manzyuk@pandora:~/tmp$ ghc --make -O euler-10.hs -dcore-lint -fforce-recomp
[1 of 1] Compiling Main ( euler-10.hs, euler-10.o )
Linking euler-10 ...
Trac metadata
Trac field | Value |
---|---|
Version | 7.0.3 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Runtime System |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |