Ticket #4090 (closed bug: invalid)

Opened 3 years ago

Last modified 3 years ago

Impossible compilation with primitive operations (possibly unsafeCoerce#)

Reported by: malosh Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.12.1
Keywords: Cc:
Operating System: MacOS X Architecture: x86
Type of failure: Compile-time crash Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

On the following code :

ulp#::Double#->Double# ulp# d=

let w=unsafeCoerce# d
Word64# e=(unsafeCoerce# (uncheckedShiftRL64# w 52#)) and# 0x7ff## in if e gtWord# 0x034## then unsafeCoerce# (unsafeCoerce# (e minusWord# (0x034##)) uncheckedShiftL64# 52#) else unsafeCoerce# (1## uncheckedShiftL# ((unsafeCoerce# e) -# 1#))

GHC 6.12.1 returns :

ghc: panic! (the 'impossible' happened)

(GHC version 6.12.1 for i386-apple-darwin):

getRegister(x86) I64+ 72?

Change History

in reply to: ↑ description   Changed 3 years ago by malosh

The code is :

ulp#::Double#->Double#
ulp# d=
   let w=unsafeCoerce# d :: Word64#
       e=(unsafeCoerce# (uncheckedShiftRL64# w 52#)) `and#` 0x7ff##
   in
    if e `gtWord#` 0x034## then
      unsafeCoerce# (unsafeCoerce# (e `minusWord#` (0x034##)) `uncheckedShiftL64#` 52#)
    else
      unsafeCoerce# (1## `uncheckedShiftL#` ((unsafeCoerce# e) -# 1#))

And the compiler answers :

GHC 6.12.1 returns :

ghc: panic! (the 'impossible' happened)
  (GHC version 6.12.1 for i386-apple-darwin):
        getRegister(x86) I64[BaseReg + 72]

(Sorry for the wrong trac formatting).

  Changed 3 years ago by simonmar

  • status changed from new to closed
  • resolution set to invalid

unsafeCoerce# isn't guaranteed to work between integral types and floating point types, see the documentation: http://www.haskell.org/ghc/docs/6.12.2/html/libraries/ghc-prim-0.2.0.0/GHC-Prim.html#v%3AunsafeCoerce%23.

There should really be a primitive to let you do this - feel free to open a separate feature request.

  Changed 3 years ago by malosh

Done ! Thank you Simon for such a quick answer, and please excuse my mistake.

Note: See TracTickets for help on using tickets.