Uh oh!
There was an error while loading. Please reload this page.
Lower unchecked_div/_rem to MIR's BinOp::Div/Rem - #112168
Conversation
rustbot
commented
Jun 1, 2023
r? @oli-obk (rustbot has picked a reviewer for you, use r? to override) |
rustbot
commented
Jun 1, 2023
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
RalfJung
commented
Jun 1, 2023
The MIR comment only mentions 0, not overflow. However the Miri implementation makes div and rem also UB on overflow. We should probably update the MIR comment then. |
rustbot
commented
Jun 2, 2023
This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras |
scottmcm
commented
Jun 2, 2023
Updated the comments on |
oli-obk
commented
Jun 2, 2023
@bors r+ |
bors
commented
Jun 2, 2023
…mpiler-errors Rollup of 6 pull requests Successful merges: - rust-lang#109609 (Separate AnonConst from ConstBlock in HIR.) - rust-lang#112166 (bootstrap: Rename profile = user to profile = dist) - rust-lang#112168 (Lower `unchecked_div`/`_rem` to MIR's `BinOp::Div`/`Rem`) - rust-lang#112183 (Normalize anon consts in new solver) - rust-lang#112211 (pass `--lib` to `x doc`) - rust-lang#112223 (Don't ICE in new solver when auto traits have associated types) r? `@ghost` `@rustbot` modify labels: rollup
…o-mir, r=oli-obk Lower `unchecked_div`/`_rem` to MIR's `BinOp::Div`/`Rem` As described in <https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.BinOp.html#variant.Div>, the ordinary `BinOp`s for these are already UB for division by zero ([or overflow](https://llvm.org/docs/LangRef.html#sdiv-instruction), [demo](https://rust.godbolt.org/z/71e7P7Exh)), as MIR building is responsible for inserting code to panic for those cases regardless of whether the overflow checks are enabled. So we can lower these in the same arm that lowers `wrapping_add` to MIR `BinOp::Add` and such, as all these cases turn into ordinary `Rvalue::BinaryOp`s.
As described in https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.BinOp.html#variant.Div, the ordinary
BinOps for these are already UB for division by zero (or overflow, demo), as MIR building is responsible for inserting code to panic for those cases regardless of whether the overflow checks are enabled.So we can lower these in the same arm that lowers
wrapping_addto MIRBinOp::Addand such, as all these cases turn into ordinaryRvalue::BinaryOps.