-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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/CTFE: properly treat overflow in (signed) division/rem as UB #94512
Conversation
Some changes occured to the CTFE / Miri engine cc @rust-lang/miri Some changes occured to the CTFE / Miri engine cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
// see https://github.com/rust-lang/rust/pull/94512. | ||
const _: () = { | ||
assert!(i32::MIN.wrapping_div(-1) == i32::MIN); | ||
assert!(i32::MIN.wrapping_rem(-1) == 0); |
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.
Turns out wrapping_div/rem actually does distinguish between div-by-0 and overflow, but LLVM does not (both are UB). For a second I thought wrapping_div
relies on the old behavior of the interpreter, but turns out that function actually explicitly checks for this case and avoids even calling the MIR operator. So we are good.
But this is subtle enough that it warrants a specific test.
@bors r+ rollup |
📌 Commit 6739299 has been approved by |
Miri/CTFE: properly treat overflow in (signed) division/rem as UB To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine. r? `@oli-obk`
Miri/CTFE: properly treat overflow in (signed) division/rem as UB To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine. r? ``@oli-obk``
Miri/CTFE: properly treat overflow in (signed) division/rem as UB To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine. r? ```@oli-obk```
Miri/CTFE: properly treat overflow in (signed) division/rem as UB To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine. r? ````@oli-obk````
Miri/CTFE: properly treat overflow in (signed) division/rem as UB To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine. r? `````@oli-obk`````
Miri/CTFE: properly treat overflow in (signed) division/rem as UB To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine. r? ``````@oli-obk``````
Miri/CTFE: properly treat overflow in (signed) division/rem as UB To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine. r? ```````@oli-obk```````
@bors rollup=never The rust-log output is misleading, that is Miri failing which is fine. The actual issue (I think) is
Sadly this doesn't even say which tools's test suite this is a part of.^^ But I guess it must be clippy? |
I updated the stderr file by hand (since blessing clippy does not seem easily possible) -- hopefully that means the PR runner will now run Clippy tests. |
@bors r=oli-obk |
📌 Commit 24fc115 has been approved by |
@bors r- I'd prefer to first see if PR CI is green. |
ah oops :D |
@bors r+ |
📌 Commit 24fc115 has been approved by |
☀️ Test successful - checks-actions |
Tested on commit rust-lang/rust@4566094. Direct link to PR: <rust-lang/rust#94512> 💔 miri on windows: test-pass → test-fail (cc @oli-obk @RalfJung @eddyb). 💔 miri on linux: test-pass → test-fail (cc @oli-obk @RalfJung @eddyb).
adjust for div/rem overflow being UB This is the Miri side of rust-lang/rust#94512. Just some error messages change.
Finished benchmarking commit (4566094): comparison url. Summary: This benchmark run did not return any relevant results. 3 results were found to be statistically significant but too small to be relevant. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
Miri/CTFE: properly treat overflow in (signed) division/rem as UB To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine. r? `@oli-obk`
To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR
Div
/Rem
directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine.r? @oli-obk