Skip to content

Commit 2f9ecde

Browse files
committed
Auto merge of #1992 - RalfJung:sdiv, r=RalfJung
adjust for div/rem overflow being UB This is the Miri side of rust-lang/rust#94512. Just some error messages change.
2 parents 2b23786 + c0f7251 commit 2f9ecde

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f0c4da49983aa699f715caf681e3154b445fb60b
1+
45660949132222ba7ec0905649b2affd68e0e13c
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(core_intrinsics)]
22
fn main() {
33
// divison of MIN by -1
4-
unsafe { std::intrinsics::exact_div(i64::MIN, -1); } //~ ERROR result of dividing MIN by -1 cannot be represented
4+
unsafe { std::intrinsics::exact_div(i64::MIN, -1); } //~ ERROR overflow in signed remainder (dividing MIN by -1)
55
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(platform_intrinsics, repr_simd)]
2+
3+
extern "platform-intrinsic" {
4+
pub(crate) fn simd_div<T>(x: T, y: T) -> T;
5+
}
6+
7+
#[repr(simd)]
8+
#[allow(non_camel_case_types)]
9+
struct i32x2(i32, i32);
10+
11+
fn main() { unsafe {
12+
let x = i32x2(1, i32::MIN);
13+
let y = i32x2(1, -1);
14+
simd_div(x, y); //~ERROR Undefined Behavior: overflow in signed division
15+
} }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(core_intrinsics)]
22
fn main() {
33
// MIN/-1 cannot be represented
4-
unsafe { std::intrinsics::unchecked_div(i16::MIN, -1); } //~ ERROR overflow executing `unchecked_div`
4+
unsafe { std::intrinsics::unchecked_div(i16::MIN, -1); } //~ ERROR overflow in signed division (dividing MIN by -1)
55
}

tests/run-pass/integer-ops.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ pub fn main() {
116116
assert_eq!(100i8.wrapping_rem(10), 0);
117117
assert_eq!((-128i8).wrapping_rem(-1), 0);
118118

119+
assert_eq!(i32::MIN.wrapping_div(-1), i32::MIN);
120+
assert_eq!(i32::MIN.wrapping_rem(-1), 0);
121+
119122
assert_eq!(100i8.wrapping_neg(), -100);
120123
assert_eq!((-128i8).wrapping_neg(), -128);
121124

0 commit comments

Comments
 (0)