From bd063113ec3c00d80fc32a5581ac9552682f6b43 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 26 Jul 2024 20:50:59 +0800 Subject: [PATCH] fixes #23894; succ/pred shouldn't raise OverflowDefect for unsigned integers (#23895) fixes #23894 keeps it consistent with `inc` --- compiler/ccgexprs.nim | 2 +- tests/system/tsystem_misc.nim | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index af3c8bf66e..17f2159495 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -590,7 +590,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: diff --git a/tests/system/tsystem_misc.nim b/tests/system/tsystem_misc.nim index c8e2b2a9df..1debb7c48c 100644 --- a/tests/system/tsystem_misc.nim +++ b/tests/system/tsystem_misc.nim @@ -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