fixes #23894; succ/pred shouldn't raise OverflowDefect for unsigned integers (#23895)

fixes #23894

keeps it consistent with `inc`

(cherry picked from commit bd063113ec)
This commit is contained in:
ringabout
2024-07-26 20:50:59 +08:00
committed by narimiran
parent 06d00dfcf6
commit b7041b250c
2 changed files with 7 additions and 1 deletions

View File

@@ -602,7 +602,7 @@ proc binaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
# skipping 'range' is correct here as we'll generate a proper range check
# later via 'chckRange'
let t = e.typ.skipTypes(abstractRange)
if optOverflowCheck notin p.options:
if optOverflowCheck notin p.options or (m in {mSucc, mPred} and t.kind in {tyUInt..tyUInt64}):
let res = "($1)($2 $3 $4)" % [getTypeDesc(p.module, e.typ), rdLoc(a), rope(opr[m]), rdLoc(b)]
putIntoDest(p, d, e, res)
else:

View File

@@ -219,3 +219,9 @@ proc bug23223 = # bug #23223
doAssert stuff == "hello"
bug23223()
block: # bug #23894
let v = high(uint) div 2
let s = v + 1 # 9223372036854775808
let m = succ v
doAssert s == m