Skip to content

Panic iselExpr64(i386)

Summary

While implementing !10568 (closed) I came across a GHC panic.

Steps to reproduce

To reproduce we need two files:

-- Repro.hs
module Repro (repro) where

import Unique

mkPreludeTyConUnique i = mkUnique '3' (2*i)

intTyConKey   = mkPreludeTyConUnique 15
int8TyConKey  = mkPreludeTyConUnique 17
int16TyConKey = mkPreludeTyConUnique 19
int32TyConKey = mkPreludeTyConUnique 21
int64TyConKey = mkPreludeTyConUnique 23

repro :: Unique -> Bool
repro x = x `elem` [ intTyConKey, int8TyConKey, int16TyConKey
                   , int32TyConKey, int64TyConKey
                   , mkUnique '3' 24
                   ]
-- Unique.hs
module Unique where

import Data.Word
import Data.Bits
import Data.Char

newtype Unique = MkUnique Word64 deriving Eq

mkUnique :: Char -> Word64 -> Unique
mkUnique c i
  = MkUnique (tag .|. bits)
  where
    tag  = fromIntegral (ord c) `shiftL` 60
    bits = fromIntegral i .&. ((1 `shiftL` 60) - 1)

Compile with ghc -O2 Repro.hs and observe:

[2 of 2] Compiling Repro            ( Repro.hs, Repro.o ) [Source file changed]

<no location info>: error:
    panic! (the 'impossible' happened)
  GHC version 9.4.3:
	iselExpr64(i386)
  _s1mO::I64 - 24 :: W64
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/GHC/Utils/Panic.hs:182:37 in ghc:GHC.Utils.Panic
        pprPanic, called at compiler/GHC/CmmToAsm/X86/CodeGen.hs:615:7 in ghc:GHC.CmmToAsm.X86.CodeGen

Please report this as a GHC bug:  https://www.haskell.org/ghc/reportabug

To get a 32 bit compiler on a 64 bit system I use this script from ghc-utils:

./ghc-docker-jobs.sh i386-linux-deb9-validate master

Expected behavior

Compile without issues, like GHC 9.2.8 does.

Environment

  • GHC version used: 9.4.1, 9.4.3, 9.6.2

Optional:

  • System Architecture: i386
Edited by Jaro Reinders
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information