diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2024-07-26 20:50:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-26 14:50:59 +0200 |
commit | bd063113ec3c00d80fc32a5581ac9552682f6b43 (patch) | |
tree | de8d3197588c8dcb081f0dbadc402f0b338fd77a | |
parent | 469a6044c00ce657d2f543f292678b3c71e0b037 (diff) | |
download | Nim-bd063113ec3c00d80fc32a5581ac9552682f6b43.tar.gz |
fixes #23894; succ/pred shouldn't raise OverflowDefect for unsigned integers (#23895)
fixes #23894 keeps it consistent with `inc`
-rw-r--r-- | compiler/ccgexprs.nim | 2 | ||||
-rw-r--r-- | tests/system/tsystem_misc.nim | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index af3c8bf66..17f215949 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 c8e2b2a9d..1debb7c48 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 |