Ticket #2156 (closed bug: wontfix)
compilation math/truncate bug with optimization enabled
Description
The following code produces different results depending on whether it is compiled with optimization (-O1/-O2) or not. The unoptimized program when run outputs the correct value (3), the optimized one outputs an incorrect value (2)
module Main where
import IO
lg8base2 :: Int
lg8base2 = truncate (log 8 / log 2)
main :: IO()
main = do
hPutStrLn stdout $ show lg8base2
Output of gcc -v
Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix gcc version 4.2.3 20071123 (prerelease) (Debian 4.2.2-4)
Sequence of compiles / runs
trevor@tmlinux:~/haskell$ ghc --make test [1 of 1] Compiling Main ( test.hs, test.o ) Linking test ... trevor@tmlinux:~/haskell$ ./test 3 trevor@tmlinux:~/haskell$ rm test.o trevor@tmlinux:~/haskell$ ghc -O2 --make test [1 of 1] Compiling Main ( test.hs, test.o ) Linking test ... trevor@tmlinux:~/haskell$ ./test 2
Output of compilation phase with -v is attached (test.unoptimized.output & test.optimized.output)
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

