Skip to content

Commit

Permalink
fixes #23894; succ/pred shouldn't raise OverflowDefect for unsigned i…
Browse files Browse the repository at this point in the history
…ntegers (#23895)

fixes #23894

keeps it consistent with `inc`
  • Loading branch information
ringabout authored Jul 26, 2024
1 parent 469a604 commit bd06311
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/system/tsystem_misc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bd06311

Please sign in to comment.