#2156: compilation math/truncate bug with optimization enabled
------------------------+---------------------------------------------------
Reporter: trevorm | Owner:
Type: bug | Status: new
Priority: normal | Component: Compiler
Version: 6.8.2 | Severity: critical
Keywords: | Testcase:
Architecture: x86 | Os: Linux
------------------------+---------------------------------------------------
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
{{{
[EMAIL PROTECTED]:~/haskell$ ghc --make test
[1 of 1] Compiling Main ( test.hs, test.o )
Linking test ...
[EMAIL PROTECTED]:~/haskell$ ./test
3
[EMAIL PROTECTED]:~/haskell$ rm test.o
[EMAIL PROTECTED]:~/haskell$ ghc -O2 --make test
[1 of 1] Compiling Main ( test.hs, test.o )
Linking test ...
[EMAIL PROTECTED]:~/haskell$ ./test
2
}}}
Output of compilation phase with -v is attached (test.unoptimized.output &
test.optimized.output)
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2156>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs