-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
miri: improve and simplify overflow detection #69002
Conversation
if r == -1 && l == (1 << (size.bits() - 1)) { | ||
return Ok((Scalar::from_uint(l, size), true, left_layout.ty)); | ||
return Ok((Scalar::from_int(0, size), true, left_layout.ty)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what this used to do for Rem
is plain wrong -- it returned the wrong result. However, even in release builds, remainder is checked for overflow. So, during normal execution in CTFE/Miri, the overflowing case here is unreachable. It is reachable in const-prop, which however does not care about the return value, just about whether there is an overflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With control flow const prop we could stop propping in arms that are only reachable by a failing assert terminator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also declare int_min / -1
and int_min % -1
to be UB. This is consistent with MIR building always checking that, and it should resolve the rem/div part of #69020.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though OTOH, it is probably more consistent to handle all overflow the same way... so maybe not. I hope to play with this next weekend.
Let's do a perf run just to be sure there's no regressions and then we can land this. @bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit d6c5a04 with merge 5bf0888774eedd0302d15303b594839d4c70873e... |
Awaiting bors try build completion |
⌛ Trying commit d6c5a04 with merge 0f7a6fbaf793dfb724765f4d67fe0fa0addb53fb... |
☀️ Try build successful - checks-azure |
@rust-timer build 0f7a6fbaf793dfb724765f4d67fe0fa0addb53fb |
Queued 0f7a6fbaf793dfb724765f4d67fe0fa0addb53fb with parent 4d1241f, future comparison URL. |
Looks like the auto-queueing thing doesn't work any more? |
It's been buggy lately but I think it got confused when I edited my comment. Perf looks unaffected. @bors r=oli-obk,wesleywiser |
📌 Commit c561d23 has been approved by |
Is there a bug report for this? I can't find any at https://github.com/rust-lang-nursery/rustc-perf/issues |
…k,wesleywiser miri: improve and simplify overflow detection This simplifies the overflow detection for signed binary operators, and adds overflow detection to unary operators so that const-prop doesn't have to crudely hand-roll that. It also fixes some bugs in the operator implementation that however, I think, were not observable. r? @oli-obk @wesleywiser
Rollup of 7 pull requests Successful merges: - #67954 (Support new LLVM pass manager) - #68981 ( Account for type params on method without parentheses) - #69002 (miri: improve and simplify overflow detection) - #69038 (Add initial debug fmt for Backtrace) - #69040 (Cleanup SGX entry code) - #69086 (Update compiler-builtins to 0.1.25) - #69095 (Minified theme check) Failed merges: r? @ghost
miri: fix exact_div Turns out `exact_div` was relying on the broken behavior of `Rem` for `int_min % -1` that was fixed in rust-lang#69002. This PR fixes `exact_div`. Inside rustc, `exact_div` is only used in a single place where the divisor is always positive (in `ptr_offset_from`), so we cannot test the fix in rustc. The Miri test suite covers this through the `exact_div` intrinsic, though (and it is how I found out). One step to rust-lang#69117 (then we also need to address build failures introduced by rust-lang#68969) r? @oli-obk
This simplifies the overflow detection for signed binary operators, and adds overflow detection to unary operators so that const-prop doesn't have to crudely hand-roll that.
It also fixes some bugs in the operator implementation that however, I think, were not observable.
r? @oli-obk @wesleywiser