Skip to content

Commit dfc0340

Browse files
committed
Auto merge of #94512 - RalfJung:sdiv-ub, 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`
2 parents 874f378 + 0c72b02 commit dfc0340

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

core/tests/num/wrapping.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,13 @@ fn wrapping_int_api() {
308308
}
309309
}
310310
}
311+
312+
#[test]
313+
fn wrapping_const() {
314+
// Specifically the wrapping behavior of division and remainder is subtle,
315+
// see https://github.com/rust-lang/rust/pull/94512.
316+
const _: () = {
317+
assert!(i32::MIN.wrapping_div(-1) == i32::MIN);
318+
assert!(i32::MIN.wrapping_rem(-1) == 0);
319+
};
320+
}

0 commit comments

Comments
 (0)