Bugs item #752149, was opened at 2003-06-10 22:13
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=752149&group_id=8032

Category: Compiler
Group: 6.0
Status: Open
Resolution: None
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


----------------------------------------------------------------------

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

Reply via email to