#1171: GHC generates incorrect code with -O for Haskell 98 program
----------------------+-----------------------------------------------------
Reporter: neil | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 6.6
Severity: major | Resolution:
Keywords: | Difficulty: Unknown
Testcase: | Architecture: Multiple
Os: Multiple |
----------------------+-----------------------------------------------------
Comment (by thorkilnaur):
A stand-alone file (1171Material.tar.gz) that illustrates this problem on
a PPC Mac OS X 10.4 is attached. It has been produced by reducing the Yhc
code involved in the original report. Here is a session that uses this
file:
{{{
Thorkil-Naurs-Computer:~/tn/GHC/trac/1171 thorkilnaur$ mkdir verify
Thorkil-Naurs-Computer:~/tn/GHC/trac/1171 thorkilnaur$ cd verify
Thorkil-Naurs-Computer:~/tn/GHC/trac/1171/verify thorkilnaur$ cp
../1171Material.tar.gz .
Thorkil-Naurs-Computer:~/tn/GHC/trac/1171/verify thorkilnaur$ gunzip
1171Material.tar.gz
Thorkil-Naurs-Computer:~/tn/GHC/trac/1171/verify thorkilnaur$ tar xvf
1171Material.tar
1171Material/
1171Material/ghc.sh
1171Material/Package.hs
1171Material/T3.hs
Thorkil-Naurs-Computer:~/tn/GHC/trac/1171/verify thorkilnaur$ cd
1171Material
Thorkil-Naurs-Computer:~/tn/GHC/trac/1171/verify/1171Material thorkilnaur$
ls
Package.hs T3.hs ghc.sh
Thorkil-Naurs-Computer:~/tn/GHC/trac/1171/verify/1171Material thorkilnaur$
ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.6.20070220
Thorkil-Naurs-Computer:~/tn/GHC/trac/1171/verify/1171Material thorkilnaur$
cat ghc.sh
ghc --make T3 -o T3 -O
./T3
rm *.o
ghc --make T3 -o T3
./T3
rm *.o
Thorkil-Naurs-Computer:~/tn/GHC/trac/1171/verify/1171Material thorkilnaur$
sh ghc.sh
[1 of 2] Compiling Package ( Package.hs, Package.o )
[2 of 2] Compiling Main ( T3.hs, T3.o )
Linking T3 ...
T3: 2007-Feb-25 01.57
T3: Empty as++bs
[1 of 2] Compiling Package ( Package.hs, Package.o )
[2 of 2] Compiling Main ( T3.hs, T3.o )
Linking T3 ...
T3: 2007-Feb-25 01.57
T3: Error: File not found
Thorkil-Naurs-Computer:~/tn/GHC/trac/1171/verify/1171Material thorkilnaur$
}}}
In this session, T3+Package is compiled and executed twice, first with -O,
then without -O. And, as can be observed, the results are different.
In the wrong case - the one where -O is used - the erroneous result
apparently comes about by selecting the wrong alternative in the case in
Package.hs:
{{{
case (local,res) of
([x], _) -> return x
(_, [x]) -> return x
([], []) -> raiseError $ ErrorFileNone
(as, bs) -> if as++bs == [] then error "Empty as++bs" else
raiseError $ ErrorFileMany file
}}}
As can be seen from the output produced, in spite of as+bs being == [],
the last alternative is selected when the code is compiled with -O.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1171>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs