Skip to content
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

signed division has undefined behaviour on overflow #8460

Closed
thestinger opened this issue Aug 11, 2013 · 3 comments
Closed

signed division has undefined behaviour on overflow #8460

thestinger opened this issue Aug 11, 2013 · 3 comments

Comments

@thestinger
Copy link
Contributor

Division by zero leads to undefined behavior. Overflow also leads to undefined behavior; this is a rare case, but can occur, for example, by doing a 32-bit division of -2147483648 by -1.

http://llvm.org/docs/LangRef.html#sdiv-instruction

Note that this is undefined behaviour, not just an unspecified result like a shift by too many bits. We need to add a check for this.

@emberian
Copy link
Member

@thestinger what needs to be done for this? Check for certain numbers when dividing and fail!() if it would trigger UB?

@thestinger
Copy link
Contributor Author

@cmr: signed division should check x / y for x == INT_MIN && y == -1 in addition to y == 0.

@emberian
Copy link
Member

So this check happens in trans, fail_if_zero in base.rs. It needs to add an extra comparison in the ty_int branch. What that comparison is, and how to effect it, I do not know.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jun 6, 2014
Division and remainder by 0 are undefined behavior, and are detected at runtime.
This commit adds support for ensuring that MIN / -1 is also checked for at
runtime, as this would cause signed overflow, or undefined behvaior.

Closes rust-lang#8460
mcpherrinm pushed a commit to mcpherrinm/rust that referenced this issue Jun 10, 2014
Division and remainder by 0 are undefined behavior, and are detected at runtime.
This commit adds support for ensuring that MIN / -1 is also checked for at
runtime, as this would cause signed overflow, or undefined behvaior.

Closes rust-lang#8460
flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 24, 2022
…nishearth

False positive redundant_closure when using ref pattern in closure params

fixes rust-lang#8460
Fixed [redundant_closure] so that closures of which params bound as `ref` or `ref mut ` doesn't trigger the lint.
(e.g. `|ref x| some_expr` doesn't trigger the lint.)
changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants