Skip to content

Commit 9681358

Browse files
committed
Auto merge of rust-lang#149 - rust-lang-nursery:gh148, r=alexcrichton
fix debug assertion in divdi3 fixes rust-lang#148 r? @alexcrichton
2 parents 8bd620f + c93b32b commit 9681358

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/int/sdiv.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ macro_rules! div {
1010
pub extern "C" fn $intrinsic(a: $ty, b: $ty) -> $tyret {
1111
let s_a = a >> (<$ty>::bits() - 1);
1212
let s_b = b >> (<$ty>::bits() - 1);
13-
let a = (a ^ s_a) - s_a;
14-
let b = (b ^ s_b) - s_b;
13+
// NOTE it's OK to overflow here because of the `as $uty` cast below
14+
// This whole operation is computing the absolute value of the inputs
15+
// So some overflow will happen when dealing with e.g. `i64::MIN`
16+
// where the absolute value is `(-i64::MIN) as u64`
17+
let a = (a ^ s_a).wrapping_sub(s_a);
18+
let b = (b ^ s_b).wrapping_sub(s_b);
1519
let s = s_a ^ s_b;
1620

1721
let r = udiv!(a as $uty, b as $uty);

0 commit comments

Comments
 (0)