-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
succ raise OverflowDefect, succ does not handle unsigned integers correctly #23894
Comments
The following changes seem to fix the issue. #define nimAddInt64(a, b, res) __builtin_add_overflow(a, b, res)
#define nimSubInt64(a, b, res) __builtin_sub_overflow(a, b, res)
#define nimMulInt64(a, b, res) __builtin_mul_overflow(a, b, res)
#define nimAddInt(a, b, res) __builtin_add_overflow(a, b, res)
#define nimSubInt(a, b, res) __builtin_sub_overflow(a, b, res)
#define nimMulInt(a, b, res) __builtin_mul_overflow(a, b, res) the test: discard """
targets: "c cpp"
"""
# Bug #23894
proc checkSucc(tp: typedesc) =
let v = high(tp)
let v2 = tp(uint64(v) div uint64(2))
let v3 = succ v2
discard v3
proc checkSuccOverflow(tp: typedesc) =
let v = high(tp)
try:
let v2 = succ v
discard v2
except OverflowDefect:
return
doAssert false, "unreachable"
block: # overflow
checkSuccOverflow(char)
checkSuccOverflow(cint)
checkSuccOverflow(cuint)
checkSuccOverflow(csize_t)
checkSuccOverflow(uint)
checkSuccOverflow(uint8)
checkSuccOverflow(uint16)
checkSuccOverflow(uint32)
checkSuccOverflow(uint64)
checkSuccOverflow(int)
checkSuccOverflow(int8)
checkSuccOverflow(int16)
checkSuccOverflow(int32)
checkSuccOverflow(int64)
checkSuccOverflow(cint)
checkSuccOverflow(cuint)
checkSuccOverflow(csize_t)
block: # should't overflow
checkSucc(char)
checkSucc(cint)
checkSucc(cuint)
checkSucc(csize_t)
checkSucc(uint)
checkSucc(uint8)
checkSucc(uint16)
checkSucc(uint32)
checkSucc(uint64)
checkSucc(int)
checkSucc(int8)
checkSucc(int16)
checkSucc(int32)
checkSucc(int64)
|
ringabout
added a commit
that referenced
this issue
Jul 26, 2024
narimiran
pushed a commit
that referenced
this issue
Sep 13, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
succ does not handle unsigned integers correctly.
https://play.nim-lang.org/#pasty=XDlRYyZz
Nim Version
Nim Compiler Version 2.1.9 [Linux: amd64]
Compiled at 2024-07-25
Copyright (c) 2006-2024 by Andreas Rumpf
git hash: c1f91c2
active boot switches: -d:release
Current Output
Expected Output
Possible Solution
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: