Magnus pushed to branch wip/mangoiv/9.12.5-rc3-fixes at Glasgow Haskell Compiler / GHC
Commits:
-
71481e34
by Cheng Shao at 2026-07-01T15:21:19+02:00
6 changed files:
- + changelog.d/fix-layout-stack-fcall
- compiler/GHC/Cmm/LayoutStack.hs
- + testsuite/tests/cmm/should_run/T27447.hs
- + testsuite/tests/cmm/should_run/T27447.stdout
- + testsuite/tests/cmm/should_run/T27447_cmm.cmm
- testsuite/tests/cmm/should_run/all.T
Changes:
| 1 | +section: compiler
|
|
| 2 | +synopsis: Fix invalid cmm basic block output when proc-point splitting is enabled (wasm/llvm/unregisterised)
|
|
| 3 | +issues: #27447
|
|
| 4 | +mrs: !16271 |
| ... | ... | @@ -407,6 +407,8 @@ procMiddle stackmaps node sm |
| 407 | 407 | where loc = getStackLoc area off stackmaps
|
| 408 | 408 | CmmAssign (CmmLocal r) _other
|
| 409 | 409 | -> sm { sm_regs = delFromUFM (sm_regs sm) r }
|
| 410 | + CmmUnsafeForeignCall _ results _
|
|
| 411 | + -> sm { sm_regs = delListFromUFM (sm_regs sm) results }
|
|
| 410 | 412 | _other
|
| 411 | 413 | -> sm
|
| 412 | 414 |
| 1 | +{-# LANGUAGE GHCForeignImportPrim #-}
|
|
| 2 | +{-# LANGUAGE MagicHash #-}
|
|
| 3 | +{-# LANGUAGE UnboxedTuples #-}
|
|
| 4 | +{-# LANGUAGE UnliftedFFITypes #-}
|
|
| 5 | + |
|
| 6 | +import Foreign
|
|
| 7 | +import GHC.Exts
|
|
| 8 | +import GHC.IO
|
|
| 9 | +import GHC.Word
|
|
| 10 | +import Text.Printf
|
|
| 11 | + |
|
| 12 | +foreign import prim "t27447_repro"
|
|
| 13 | + t27447_repro# :: Addr# -> State# RealWorld -> (# State# RealWorld, Word64# #)
|
|
| 14 | + |
|
| 15 | +expected :: Word64
|
|
| 16 | +expected = 0x2222222222222222
|
|
| 17 | + |
|
| 18 | +stale :: Word64
|
|
| 19 | +stale = 0x1111111111111111
|
|
| 20 | + |
|
| 21 | +runCmm :: Ptr a -> IO Word64
|
|
| 22 | +runCmm (Ptr p#) = IO $ \s ->
|
|
| 23 | + case t27447_repro# p# s of
|
|
| 24 | + (# s', w# #) -> (# s', W64# w# #)
|
|
| 25 | + |
|
| 26 | +main :: IO ()
|
|
| 27 | +main = allocaBytesAligned 48 8 $ \raw -> do
|
|
| 28 | + let node0 = raw
|
|
| 29 | + node1 = raw `plusPtr` 24
|
|
| 30 | + |
|
| 31 | + pokeByteOff node0 0 (1 :: Word64)
|
|
| 32 | + pokeByteOff node0 8 node1
|
|
| 33 | + pokeByteOff node0 16 stale
|
|
| 34 | + |
|
| 35 | + pokeByteOff node1 0 (0 :: Word64)
|
|
| 36 | + pokeByteOff node1 8 node1
|
|
| 37 | + pokeByteOff node1 16 expected
|
|
| 38 | + |
|
| 39 | + got <- runCmm node0
|
|
| 40 | + printf "0x%016x\n" got |
| 1 | +0x2222222222222222 |
| 1 | +#include "Cmm.h"
|
|
| 2 | + |
|
| 3 | +t27447_repro (W_ x) {
|
|
| 4 | + I64 ty;
|
|
| 5 | + W_ old;
|
|
| 6 | + |
|
| 7 | +again:
|
|
| 8 | + ty = I64[x];
|
|
| 9 | + switch [0 .. 2] (ty) {
|
|
| 10 | + case 0: {
|
|
| 11 | + return (I64[x + 16]);
|
|
| 12 | + }
|
|
| 13 | + case 1: {
|
|
| 14 | + old = x;
|
|
| 15 | + x = %acquire W_[x + 8];
|
|
| 16 | + I64[old] = 0;
|
|
| 17 | + goto again;
|
|
| 18 | + }
|
|
| 19 | + case 2: {
|
|
| 20 | + STK_CHK_GEN();
|
|
| 21 | + goto again;
|
|
| 22 | + }
|
|
| 23 | + }
|
|
| 24 | +} |
| ... | ... | @@ -33,7 +33,7 @@ test('T22871', |
| 33 | 33 | |
| 34 | 34 | test('JumpTableNoStackDealloc',
|
| 35 | 35 | [ extra_run_opts('"' + config.libdir + '"')
|
| 36 | - , req_cmm
|
|
| 36 | + , req_cmm
|
|
| 37 | 37 | , when(arch('wasm32'), skip) # wasm32 doesn't support the printf() calls
|
| 38 | 38 | , when(arch('i386'), skip) # i386 doesn't support `MO_U_Rem W64` (`_c1::I64 % 10 :: W64`)
|
| 39 | 39 | ],
|
| ... | ... | @@ -52,3 +52,11 @@ test('T25601', |
| 52 | 52 | [req_cmm],
|
| 53 | 53 | multi_compile_and_run,
|
| 54 | 54 | ['T25601', [('T25601a.cmm', '')], ''])
|
| 55 | + |
|
| 56 | +test('T27447',
|
|
| 57 | + [ req_cmm
|
|
| 58 | + , extra_ways(['optasm'])
|
|
| 59 | + , when(have_llvm(), extra_ways(['optasm', 'optllvm']))
|
|
| 60 | + ],
|
|
| 61 | + multi_compile_and_run,
|
|
| 62 | + ['T27447', [('T27447_cmm.cmm', '')], '']) |