mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-11 22:08:54 +00:00
@@ -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)
|
||||
|
||||
@@ -105,7 +105,7 @@ type
|
||||
opcIsNil, opcOf, opcIs,
|
||||
opcParseFloat, opcConv, opcCast,
|
||||
opcQuit, opcInvalidField,
|
||||
opcNarrowS, opcNarrowU,
|
||||
opcNarrowS, opcNarrowU, opcNarrowR
|
||||
opcSignExtend,
|
||||
|
||||
opcAddStrCh,
|
||||
|
||||
@@ -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})
|
||||
|
||||
17
tests/errmsgs/tvmranges.nim
Normal file
17
tests/errmsgs/tvmranges.nim
Normal 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"
|
||||
Reference in New Issue
Block a user