David Eichmann pushed to branch wip/27162/ghc-codegen-panic at Glasgow Haskell Compiler / GHC
Commits:
-
27297996
by David Eichmann at 2026-04-16T17:02:06+01:00
8 changed files:
- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/AArch64.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/X86.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/Driver/CodeOutput.hs
- compiler/GHC/Driver/Main.hs
- compiler/GHC/Utils/Panic/Plain.hs
Changes:
| ... | ... | @@ -132,7 +132,7 @@ import System.IO |
| 132 | 132 | import System.Directory ( getCurrentDirectory )
|
| 133 | 133 | |
| 134 | 134 | --------------------
|
| 135 | -nativeCodeGen :: forall a . Logger -> ToolSettings -> NCGConfig -> ModLocation -> Handle
|
|
| 135 | +nativeCodeGen :: forall a . HasCallStack => Logger -> ToolSettings -> NCGConfig -> ModLocation -> Handle
|
|
| 136 | 136 | -> CgStream RawCmmGroup a
|
| 137 | 137 | -> UniqDSMT IO a
|
| 138 | 138 | nativeCodeGen logger ts config modLoc h cmms
|
| ... | ... | @@ -18,8 +18,9 @@ import qualified GHC.CmmToAsm.AArch64.Ppr as AArch64 |
| 18 | 18 | import qualified GHC.CmmToAsm.AArch64.CodeGen as AArch64
|
| 19 | 19 | import qualified GHC.CmmToAsm.AArch64.Regs as AArch64
|
| 20 | 20 | import qualified GHC.CmmToAsm.AArch64.RegInfo as AArch64
|
| 21 | +import GHC.Stack (HasCallStack)
|
|
| 21 | 22 | |
| 22 | -ncgAArch64 :: NCGConfig -> NcgImpl RawCmmStatics AArch64.Instr AArch64.JumpDest
|
|
| 23 | +ncgAArch64 :: HasCallStack => NCGConfig -> NcgImpl RawCmmStatics AArch64.Instr AArch64.JumpDest
|
|
| 23 | 24 | ncgAArch64 config
|
| 24 | 25 | = NcgImpl {
|
| 25 | 26 | ncgConfig = config
|
| ... | ... | @@ -95,7 +95,7 @@ import GHC.Utils.Monad (mapAccumLM) |
| 95 | 95 | -- data GenBasicBlock i = BasicBlock BlockId [i]
|
| 96 | 96 | |
| 97 | 97 | cmmTopCodeGen
|
| 98 | - :: RawCmmDecl
|
|
| 98 | + :: HasCallStack => RawCmmDecl
|
|
| 99 | 99 | -> NatM [NatCmmDecl RawCmmStatics Instr]
|
| 100 | 100 | |
| 101 | 101 | -- Thus we'll have to deal with either CmmProc ...
|
| ... | ... | @@ -123,7 +123,7 @@ cmmTopCodeGen _cmm@(CmmData sec dat) = do |
| 123 | 123 | return [CmmData sec dat] -- no translation, we just use CmmStatic
|
| 124 | 124 | |
| 125 | 125 | basicBlockCodeGen
|
| 126 | - :: Block CmmNode C C
|
|
| 126 | + :: HasCallStack => Block CmmNode C C
|
|
| 127 | 127 | -> NatM ( [NatBasicBlock Instr]
|
| 128 | 128 | , [NatCmmDecl RawCmmStatics Instr])
|
| 129 | 129 |
| ... | ... | @@ -24,7 +24,7 @@ ncgX86 :: NCGConfig -> NcgImpl (Alignment, RawCmmStatics) X86.Instr X86.JumpDest |
| 24 | 24 | ncgX86 = ncgX86_64
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | -ncgX86_64 :: NCGConfig -> NcgImpl (Alignment, RawCmmStatics) X86.Instr X86.JumpDest
|
|
| 27 | +ncgX86_64 :: HasCallStack => NCGConfig -> NcgImpl (Alignment, RawCmmStatics) X86.Instr X86.JumpDest
|
|
| 28 | 28 | ncgX86_64 config = NcgImpl
|
| 29 | 29 | { ncgConfig = config
|
| 30 | 30 | , cmmTopCodeGen = X86.cmmTopCodeGen
|
| ... | ... | @@ -142,7 +142,7 @@ avx512dqEnabled :: NatM Bool |
| 142 | 142 | avx512dqEnabled = ncgAvx512dqEnabled <$> getConfig
|
| 143 | 143 | |
| 144 | 144 | cmmTopCodeGen
|
| 145 | - :: RawCmmDecl
|
|
| 145 | + :: HasCallStack => RawCmmDecl
|
|
| 146 | 146 | -> NatM [NatCmmDecl (Alignment, RawCmmStatics) Instr]
|
| 147 | 147 | |
| 148 | 148 | cmmTopCodeGen (CmmProc info lab live graph) = do
|
| ... | ... | @@ -212,7 +212,7 @@ verifyBasicBlock platform instrs |
| 212 | 212 | (pprInstr platform i <+> text "in:" $$ vcat (map (pprInstr platform) instrs))
|
| 213 | 213 | |
| 214 | 214 | basicBlockCodeGen
|
| 215 | - :: CmmBlock
|
|
| 215 | + :: HasCallStack => CmmBlock
|
|
| 216 | 216 | -> NatM ( [NatBasicBlock Instr]
|
| 217 | 217 | , [NatCmmDecl (Alignment, RawCmmStatics) Instr])
|
| 218 | 218 | |
| ... | ... | @@ -325,7 +325,7 @@ which *are* known to change the basic block. |
| 325 | 325 | |
| 326 | 326 | -- See Note [Keeping track of the current block] for why
|
| 327 | 327 | -- we pass the BlockId.
|
| 328 | -stmtsToInstrs :: BlockId -- ^ Basic block these statement will start to be placed in.
|
|
| 328 | +stmtsToInstrs :: HasCallStack => BlockId -- ^ Basic block these statement will start to be placed in.
|
|
| 329 | 329 | -> [CmmNode O O] -- ^ Cmm Statement
|
| 330 | 330 | -> NatM (InstrBlock, BlockId) -- ^ Resulting instruction
|
| 331 | 331 | stmtsToInstrs bid stmts =
|
| ... | ... | @@ -341,7 +341,8 @@ stmtsToInstrs bid stmts = |
| 341 | 341 | -- | `bid` refers to the current block and is used to update the CFG
|
| 342 | 342 | -- if new blocks are inserted in the control flow.
|
| 343 | 343 | -- See Note [Keeping track of the current block] for more details.
|
| 344 | -stmtToInstrs :: BlockId -- ^ Basic block this statement will start to be placed in.
|
|
| 344 | +stmtToInstrs :: HasCallStack
|
|
| 345 | + => BlockId -- ^ Basic block this statement will start to be placed in.
|
|
| 345 | 346 | -> CmmNode e x
|
| 346 | 347 | -> NatM (InstrBlock, Maybe BlockId)
|
| 347 | 348 | -- ^ Instructions, and bid of new block if successive
|
| ... | ... | @@ -546,7 +547,7 @@ assignReg_I64Code (CmmLocal dst) valueTree = do |
| 546 | 547 | assignReg_I64Code _ _
|
| 547 | 548 | = panic "assignReg_I64Code(i386): invalid lvalue"
|
| 548 | 549 | |
| 549 | -iselExpr64 :: HasDebugCallStack => CmmExpr -> NatM (RegCode64 InstrBlock)
|
|
| 550 | +iselExpr64 :: HasCallStack => CmmExpr -> NatM (RegCode64 InstrBlock)
|
|
| 550 | 551 | iselExpr64 (CmmLit (CmmInt i _)) = do
|
| 551 | 552 | Reg64 rhi rlo <- getNewReg64
|
| 552 | 553 | let
|
| ... | ... | @@ -855,12 +856,12 @@ iselExpr64ParallelBin op e1 e2 = do |
| 855 | 856 | |
| 856 | 857 | --------------------------------------------------------------------------------
|
| 857 | 858 | |
| 858 | -getRegister :: HasDebugCallStack => CmmExpr -> NatM Register
|
|
| 859 | +getRegister :: HasCallStack => CmmExpr -> NatM Register
|
|
| 859 | 860 | getRegister e = do platform <- getPlatform
|
| 860 | 861 | is32Bit <- is32BitPlatform
|
| 861 | 862 | getRegister' platform is32Bit e
|
| 862 | 863 | |
| 863 | -getRegister' :: HasDebugCallStack => Platform -> Bool -> CmmExpr -> NatM Register
|
|
| 864 | +getRegister' :: HasCallStack => Platform -> Bool -> CmmExpr -> NatM Register
|
|
| 864 | 865 | |
| 865 | 866 | getRegister' platform is32Bit (CmmReg reg)
|
| 866 | 867 | = case reg of
|
| ... | ... | @@ -3412,12 +3413,12 @@ intLoadCode instr mem = do |
| 3412 | 3413 | |
| 3413 | 3414 | -- Compute an expression into *any* register, adding the appropriate
|
| 3414 | 3415 | -- move instruction if necessary.
|
| 3415 | -getAnyReg :: HasDebugCallStack => CmmExpr -> NatM (Reg -> InstrBlock)
|
|
| 3416 | +getAnyReg :: HasCallStack => CmmExpr -> NatM (Reg -> InstrBlock)
|
|
| 3416 | 3417 | getAnyReg expr = do
|
| 3417 | 3418 | r <- getRegister expr
|
| 3418 | 3419 | anyReg r
|
| 3419 | 3420 | |
| 3420 | -anyReg :: HasDebugCallStack => Register -> NatM (Reg -> InstrBlock)
|
|
| 3421 | +anyReg :: HasCallStack => Register -> NatM (Reg -> InstrBlock)
|
|
| 3421 | 3422 | anyReg (Any _ code) = return code
|
| 3422 | 3423 | anyReg (Fixed rep reg fcode) = do
|
| 3423 | 3424 | config <- getConfig
|
| ... | ... | @@ -3426,7 +3427,7 @@ anyReg (Fixed rep reg fcode) = do |
| 3426 | 3427 | -- A bit like getSomeReg, but we want a reg that can be byte-addressed.
|
| 3427 | 3428 | -- Fixed registers might not be byte-addressable, so we make sure we've
|
| 3428 | 3429 | -- got a temporary, inserting an extra reg copy if necessary.
|
| 3429 | -getByteReg :: HasDebugCallStack => CmmExpr -> NatM (Reg, InstrBlock)
|
|
| 3430 | +getByteReg :: HasCallStack => CmmExpr -> NatM (Reg, InstrBlock)
|
|
| 3430 | 3431 | getByteReg expr = do
|
| 3431 | 3432 | config <- getConfig
|
| 3432 | 3433 | is32Bit <- is32BitPlatform
|
| ... | ... | @@ -3448,7 +3449,7 @@ getByteReg expr = do |
| 3448 | 3449 | |
| 3449 | 3450 | -- Another variant: this time we want the result in a register that cannot
|
| 3450 | 3451 | -- be modified by code to evaluate an arbitrary expression.
|
| 3451 | -getNonClobberedReg :: HasDebugCallStack => CmmExpr -> NatM (Reg, InstrBlock)
|
|
| 3452 | +getNonClobberedReg :: HasCallStack => CmmExpr -> NatM (Reg, InstrBlock)
|
|
| 3452 | 3453 | getNonClobberedReg expr = do
|
| 3453 | 3454 | r <- getRegister expr
|
| 3454 | 3455 | config <- getConfig
|
| ... | ... | @@ -4324,7 +4325,8 @@ genCondBranch' _ bid id false bool = do |
| 4324 | 4325 | -- to take/return a block id.
|
| 4325 | 4326 | |
| 4326 | 4327 | genForeignCall
|
| 4327 | - :: ForeignTarget -- ^ function to call
|
|
| 4328 | + :: HasCallStack
|
|
| 4329 | + => ForeignTarget -- ^ function to call
|
|
| 4328 | 4330 | -> [CmmFormal] -- ^ where to put the result
|
| 4329 | 4331 | -> [CmmActual] -- ^ arguments (of mixed type)
|
| 4330 | 4332 | -> BlockId -- ^ The block we are in
|
| ... | ... | @@ -4559,7 +4561,7 @@ loadIntoRegMightClobberOtherReg _ = True |
| 4559 | 4561 | |
| 4560 | 4562 | -- | Generate C call to the given function in ghc-prim
|
| 4561 | 4563 | genPrimCCall
|
| 4562 | - :: BlockId
|
|
| 4564 | + :: HasCallStack => BlockId
|
|
| 4563 | 4565 | -> FastString
|
| 4564 | 4566 | -> [CmmFormal]
|
| 4565 | 4567 | -> [CmmActual]
|
| ... | ... | @@ -4574,7 +4576,7 @@ genPrimCCall bid lbl_txt dsts args = do |
| 4574 | 4576 | |
| 4575 | 4577 | -- | Generate C call to the given function in libc
|
| 4576 | 4578 | genLibCCall
|
| 4577 | - :: BlockId
|
|
| 4579 | + :: HasCallStack => BlockId
|
|
| 4578 | 4580 | -> FastString
|
| 4579 | 4581 | -> [CmmFormal]
|
| 4580 | 4582 | -> [CmmActual]
|
| ... | ... | @@ -4592,7 +4594,7 @@ genLibCCall bid lbl_txt dsts args = do |
| 4592 | 4594 | |
| 4593 | 4595 | -- | Generate C call to the given function in the RTS
|
| 4594 | 4596 | genRTSCCall
|
| 4595 | - :: BlockId
|
|
| 4597 | + :: HasCallStack => BlockId
|
|
| 4596 | 4598 | -> FastString
|
| 4597 | 4599 | -> [CmmFormal]
|
| 4598 | 4600 | -> [CmmActual]
|
| ... | ... | @@ -4608,7 +4610,7 @@ genRTSCCall bid lbl_txt dsts args = do |
| 4608 | 4610 | |
| 4609 | 4611 | -- | Generate a real C call to the given address with the given convention
|
| 4610 | 4612 | genCCall
|
| 4611 | - :: BlockId
|
|
| 4613 | + :: HasCallStack => BlockId
|
|
| 4612 | 4614 | -> CmmExpr
|
| 4613 | 4615 | -> ForeignConvention
|
| 4614 | 4616 | -> [CmmFormal]
|
| ... | ... | @@ -4786,7 +4788,7 @@ genCCall32 addr _conv dest_regs args = do |
| 4786 | 4788 | call `appOL`
|
| 4787 | 4789 | assign_code dest_regs)
|
| 4788 | 4790 | |
| 4789 | -genCCall64 :: CmmExpr -- ^ address of function to call
|
|
| 4791 | +genCCall64 :: HasCallStack => CmmExpr -- ^ address of function to call
|
|
| 4790 | 4792 | -> ForeignConvention -- ^ calling convention
|
| 4791 | 4793 | -> [CmmFormal] -- ^ where to put the result
|
| 4792 | 4794 | -> [CmmActual] -- ^ arguments (of mixed type)
|
| ... | ... | @@ -63,6 +63,7 @@ import GHC.Types.Unique.Supply ( UniqueTag(..) ) |
| 63 | 63 | import System.IO
|
| 64 | 64 | import Data.Set (Set)
|
| 65 | 65 | import qualified Data.Set as Set
|
| 66 | +import GHC.Stack (HasCallStack)
|
|
| 66 | 67 | |
| 67 | 68 | {-
|
| 68 | 69 | ************************************************************************
|
| ... | ... | @@ -74,7 +75,7 @@ import qualified Data.Set as Set |
| 74 | 75 | |
| 75 | 76 | codeOutput
|
| 76 | 77 | :: forall a.
|
| 77 | - Logger
|
|
| 78 | + HasCallStack => Logger
|
|
| 78 | 79 | -> TmpFs
|
| 79 | 80 | -> LlvmConfigCache
|
| 80 | 81 | -> DynFlags
|
| ... | ... | @@ -192,7 +193,7 @@ outputC logger dflags filenm dus cmm_stream unit_deps = |
| 192 | 193 | ************************************************************************
|
| 193 | 194 | -}
|
| 194 | 195 | |
| 195 | -outputAsm :: Logger
|
|
| 196 | +outputAsm :: HasCallStack => Logger
|
|
| 196 | 197 | -> DynFlags
|
| 197 | 198 | -> Module
|
| 198 | 199 | -> ModLocation
|
| ... | ... | @@ -1941,7 +1941,7 @@ hscSimpleIface' mb_core_program tc_result summary = do |
| 1941 | 1941 | --------------------------------------------------------------
|
| 1942 | 1942 | |
| 1943 | 1943 | -- | Compile to hard-code.
|
| 1944 | -hscGenHardCode :: HscEnv -> CgGuts -> ModLocation -> FilePath
|
|
| 1944 | +hscGenHardCode :: HasCallStack => HscEnv -> CgGuts -> ModLocation -> FilePath
|
|
| 1945 | 1945 | -> IO (FilePath, Maybe FilePath, [(ForeignSrcLang, FilePath)], Maybe StgCgInfos, Maybe CmmCgInfos )
|
| 1946 | 1946 | -- ^ @Just f@ <=> _stub.c is f
|
| 1947 | 1947 | hscGenHardCode hsc_env cgguts mod_loc output_filename = do
|
| ... | ... | @@ -2246,7 +2246,7 @@ generateFreshByteCodeLinkable hsc_env mod_name cgguts mod_location = do |
| 2246 | 2246 | return $ mkModuleByteCodeLinkable bco_time bco_object
|
| 2247 | 2247 | ------------------------------
|
| 2248 | 2248 | |
| 2249 | -hscCompileCmmFile :: HscEnv -> FilePath -> FilePath -> FilePath -> IO (Maybe FilePath)
|
|
| 2249 | +hscCompileCmmFile :: HasCallStack => HscEnv -> FilePath -> FilePath -> FilePath -> IO (Maybe FilePath)
|
|
| 2250 | 2250 | hscCompileCmmFile hsc_env original_filename filename output_filename = runHsc hsc_env $ do
|
| 2251 | 2251 | let dflags = hsc_dflags hsc_env
|
| 2252 | 2252 | logger = hsc_logger hsc_env
|
| ... | ... | @@ -92,12 +92,12 @@ showPlainGhcException = |
| 92 | 92 | . s . showString "\n\n"
|
| 93 | 93 | . showString "Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug\n"
|
| 94 | 94 | |
| 95 | -throwPlainGhcException :: PlainGhcException -> a
|
|
| 95 | +throwPlainGhcException :: HasCallStack => PlainGhcException -> a
|
|
| 96 | 96 | throwPlainGhcException = Exception.throw
|
| 97 | 97 | |
| 98 | 98 | -- | Panics and asserts.
|
| 99 | 99 | panic, sorry, pgmError :: HasCallStack => String -> a
|
| 100 | -panic x = unsafeDupablePerformIO $ throwPlainGhcException (PlainPanic x)
|
|
| 100 | +panic x = unsafeDupablePerformIO $ throwPlainGhcException (PlainPanic (unlines [x, show callStack]))
|
|
| 101 | 101 | |
| 102 | 102 | sorry x = throwPlainGhcException (PlainSorry x)
|
| 103 | 103 | pgmError x = throwPlainGhcException (PlainProgramError x)
|