"Frank A. Christoph" <[EMAIL PROTECTED]> writes:

> While compiling GHC 3.01 using GHC 3.00 on a Sparc running Solaris 2.5.1,
> I encountered the following error:
>
> [ blah blah blah ]
>
> panic! (the `impossible' happened):
>          ERROR: Int  -1 out of range [0 .. 2147483647]
> 
> Please report it as a compiler bug to [EMAIL PROTECTED]

As folk at Glasgow know, this has been my favourite bug over the last
few months :-)

A while back (about 2.09 I think) we decided to change minBound::Int
from -2147483647 (i.e. 0x80000001) to -2147483648 (i.e. 0x80000000).
This has caused no end of strange consequences, one of which you're
seeing above.

It turns out that the GMP library we distribute with GHC has a bug in
mpz_get_si, which is fixed by the following patch (to
ghc/runtime/gmp/mpz_get_si.c): 

*** mpz_get_si.c        1998/02/27 12:08:26     1.2
--- mpz_get_si.c        1996/01/08 20:19:29     1.1
***************
*** 34,40 ****
    if (size > 0)
      return integer->d[0] % ((mp_limb) 1 << (BITS_PER_MP_LIMB - 1));
    else if (size < 0)
!     return ~((integer->d[0] - 1) % ((mp_limb) 1 << (BITS_PER_MP_LIMB - 1)));
    else
      return 0;
  }
--- 34,40 ----
    if (size > 0)
      return integer->d[0] % ((mp_limb) 1 << (BITS_PER_MP_LIMB - 1));
    else if (size < 0)
!     return -(integer->d[0] % ((mp_limb) 1 << (BITS_PER_MP_LIMB - 1)));
    else
      return 0;
  }

The catch is, to properly compile GHC you need to apply this patch to
the compiler you are using to compile GHC.  In other words, you need
to build a fixed libgmp.a and replace the installed one (3.00) with
the fixed one, then compile 3.01 using 3.00.  The gmp sources haven't
changed recently, so you can just compile up the fixed libgmp.a from
the 3.01 tree.

Cheers,
        Simon

-- 
Simon Marlow                                             [EMAIL PROTECTED]
University of Glasgow                       http://www.dcs.gla.ac.uk/~simonm/
finger for PGP public key

Reply via email to