fixes #25254; fixes #10395; Invalid pred in when swallowed (#25385)

fixes #25254
fixes #10395
This commit is contained in:
ringabout
2025-12-25 07:04:18 +08:00
committed by GitHub
parent 2dbdf08fc7
commit 5e53a70e62
4 changed files with 29 additions and 1 deletions

View File

@@ -1723,6 +1723,12 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
let max = (1.BiggestInt shl (rb-1))-1
if regs[ra].intVal < min or regs[ra].intVal > max:
stackTrace(c, tos, pc, "unhandled exception: value out of range")
of opcNarrowR:
decodeBC(rkInt)
let min = regs[rb].intVal
let max = regs[rc].intVal
if regs[ra].intVal < min or regs[ra].intVal > max:
stackTrace(c, tos, pc, "unhandled exception: value out of range")
of opcNarrowU:
decodeB(rkInt)
regs[ra].intVal = regs[ra].intVal and ((1'i64 shl rb)-1)

View File

@@ -105,7 +105,7 @@ type
opcIsNil, opcOf, opcIs,
opcParseFloat, opcConv, opcCast,
opcQuit, opcInvalidField,
opcNarrowS, opcNarrowU,
opcNarrowS, opcNarrowU, opcNarrowR
opcSignExtend,
opcAddStrCh,

View File

@@ -798,6 +798,11 @@ proc genNarrow(c: PCtx; n: PNode; dest: TDest) =
c.gABC(n, opcNarrowU, dest, TRegister(size*8))
elif t.kind in {tyInt8..tyInt32} or (t.kind == tyInt and size < 8):
c.gABC(n, opcNarrowS, dest, TRegister(size*8))
elif t.kind in {tyEnum, tyRange}:
let intType = getSysType(c.graph, n.info, tyInt)
let first = c.genx(newIntTypeNode(firstOrd(c.config, t), intType))
let last = c.genx(newIntTypeNode(lastOrd(c.config, t), intType))
c.gABC(n, opcNarrowR, dest, first, last)
proc genNarrowU(c: PCtx; n: PNode; dest: TDest) =
let t = skipTypes(n.typ, abstractVar-{tyTypeDesc})

View File

@@ -0,0 +1,17 @@
discard """
action: reject
nimout: '''
stack trace: (most recent call last)
tvmranges.nim(14, 10)
tvmranges.nim(14, 10) Error: unhandled exception: value out of range
'''
"""
type X = enum
a
b
when pred(a) == b:
echo "a"
else:
echo "b"