Bugs item #752149, was opened at 2003-06-10 20:13
Message generated for change (Comment added) made by simonpj
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=752149&group_id=8032
Category: Compiler
Group: 6.0
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Remi Turk (remit)
Assigned to: Nobody/Anonymous (nobody)
Summary: Premature Evalutation when using -O
Initial Comment:
Hi all,
the following program crashes (Prelude.head: empty
list) when compiled
with optimizations by both ghc-6.0 and ghc-5.04.3 .
When the out-commented line is activated it runs fine
with 5.04.3,
but still crashes when compiled by 6.0 .
Without -O both run perfectly fine.
Before each command the file is touched:
Without the commented-line:
% ghc-5.04.3 test1.hs && ./a.out
% ghc-5.04.3 -O test1.hs && ./a.out
Fail: Prelude.head: empty list
% ghc-6.0 test1.hs && ./a.out
% ghc-6.0 -O test1.hs && ./a.out
Fail: Prelude.head: empty list
With it:
% ghc-5.04.3 test1.hs && ./a.out
% ghc-5.04.3 -O test1.hs && ./a.out
% ghc-6.0 test1.hs && ./a.out
% ghc-6.0 -O test1.hs && ./a.out
Fail: Prelude.head: empty list
Full test done on:
% ghc --version
The Glorious Glasgow Haskell Compilation System,
version 6.0
% uname -a
Linux localhost 2.4.20 #1 Sat Nov 30 14:46:26 CET
2002 i686 unknown
I also tested the prebuilt binaries for linux-x86 and
win98, but only
with ghc-5.04.3 -O and ghc-6.0 -O (same behaviour).
AFAICS this really seems to be a bug in GHC, as
a) Laziness should prevent `len' to be evaluated
until after program-exit ;o)
b) I fail to see why this behaviour would change
when upgrading my compiler
c) AFAIK -O shouldn't change semantics
(well, not in this way at least)
d) I don't see why the "_ <- return ()" would make any
difference. (Except for messing up the optimizer ;))
If it isn't a bug, please enlighten me.
Happy hacking,
Remi
module Main where
import System
import Monad
main = do
args <- getArgs
when (null args) $
exitWith ExitSuccess
-- _ <- return ()
let len = read (head args) :: Int
print (show len)
print len
----------------------------------------------------------------------
>Comment By: Simon Peyton Jones (simonpj)
Date: 2003-06-24 08:07
Message:
Logged In: YES
user_id=50165
Good bug! This showed up two separate problems with the
way GHC treats exceptions in the IO monad. Now fixed,
thank you.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=752149&group_id=8032
_______________________________________________
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs