Skip to content

Commit 21b025f

Browse files
committed
Auto merge of #30733 - ubsan:wrapping_op_assign, r=eddyb
Fix a breaking change in #30523 While this does fix a breaking change, it is also, technically, a [breaking-change] to go back to our original way
2 parents d5ac1a1 + 14e1e2a commit 21b025f

File tree

3 files changed

+51
-49
lines changed

3 files changed

+51
-49
lines changed

src/libcore/num/wrapping.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ macro_rules! sh_impl_signed {
4242
#[inline(always)]
4343
fn shl(self, other: $f) -> Wrapping<$t> {
4444
if other < 0 {
45-
Wrapping(self.0 >> (-other & self::shift_max::$t as $f))
45+
Wrapping(self.0.wrapping_shr((-other & self::shift_max::$t as $f) as u32))
4646
} else {
47-
Wrapping(self.0 << (other & self::shift_max::$t as $f))
47+
Wrapping(self.0.wrapping_shl((other & self::shift_max::$t as $f) as u32))
4848
}
4949
}
5050
}
@@ -64,9 +64,9 @@ macro_rules! sh_impl_signed {
6464
#[inline(always)]
6565
fn shr(self, other: $f) -> Wrapping<$t> {
6666
if other < 0 {
67-
Wrapping(self.0 << (-other & self::shift_max::$t as $f))
67+
Wrapping(self.0.wrapping_shl((-other & self::shift_max::$t as $f) as u32))
6868
} else {
69-
Wrapping(self.0 >> (other & self::shift_max::$t as $f))
69+
Wrapping(self.0.wrapping_shr((other & self::shift_max::$t as $f) as u32))
7070
}
7171
}
7272
}
@@ -89,7 +89,7 @@ macro_rules! sh_impl_unsigned {
8989

9090
#[inline(always)]
9191
fn shl(self, other: $f) -> Wrapping<$t> {
92-
Wrapping(self.0 << (other & self::shift_max::$t as $f))
92+
Wrapping(self.0.wrapping_shl((other & self::shift_max::$t as $f) as u32))
9393
}
9494
}
9595

@@ -107,7 +107,7 @@ macro_rules! sh_impl_unsigned {
107107

108108
#[inline(always)]
109109
fn shr(self, other: $f) -> Wrapping<$t> {
110-
Wrapping(self.0 >> (other & self::shift_max::$t as $f))
110+
Wrapping(self.0.wrapping_shr((other & self::shift_max::$t as $f) as u32))
111111
}
112112
}
113113

@@ -124,17 +124,17 @@ macro_rules! sh_impl_unsigned {
124124
// FIXME (#23545): uncomment the remaining impls
125125
macro_rules! sh_impl_all {
126126
($($t:ident)*) => ($(
127-
sh_impl_unsigned! { $t, u8 }
128-
sh_impl_unsigned! { $t, u16 }
129-
sh_impl_unsigned! { $t, u32 }
130-
sh_impl_unsigned! { $t, u64 }
127+
//sh_impl_unsigned! { $t, u8 }
128+
//sh_impl_unsigned! { $t, u16 }
129+
//sh_impl_unsigned! { $t, u32 }
130+
//sh_impl_unsigned! { $t, u64 }
131131
sh_impl_unsigned! { $t, usize }
132132

133-
sh_impl_signed! { $t, i8 }
134-
sh_impl_signed! { $t, i16 }
135-
sh_impl_signed! { $t, i32 }
136-
sh_impl_signed! { $t, i64 }
137-
sh_impl_signed! { $t, isize }
133+
//sh_impl_signed! { $t, i8 }
134+
//sh_impl_signed! { $t, i16 }
135+
//sh_impl_signed! { $t, i32 }
136+
//sh_impl_signed! { $t, i64 }
137+
//sh_impl_signed! { $t, isize }
138138
)*)
139139
}
140140

src/librand/isaac.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl IsaacRng {
170170
const MIDPOINT: usize = RAND_SIZE_USIZE / 2;
171171

172172
macro_rules! ind {
173-
($x:expr) => (self.mem[($x >> 2u32).0 as usize & (RAND_SIZE_USIZE - 1)] )
173+
($x:expr) => (self.mem[($x >> 2).0 as usize & (RAND_SIZE_USIZE - 1)] )
174174
}
175175

176176
let r = [(0, MIDPOINT), (MIDPOINT, 0)];
@@ -452,7 +452,7 @@ impl Isaac64Rng {
452452
const MP_VEC: [(usize, usize); 2] = [(0, MIDPOINT), (MIDPOINT, 0)];
453453
macro_rules! ind {
454454
($x:expr) => {
455-
*self.mem.get_unchecked((($x >> 3u32).0 as usize) & (RAND_SIZE_64 - 1))
455+
*self.mem.get_unchecked((($x >> 3).0 as usize) & (RAND_SIZE_64 - 1))
456456
}
457457
}
458458

@@ -495,10 +495,10 @@ impl Isaac64Rng {
495495
}}
496496
}
497497

498-
rngstepp!(0, 21u32);
499-
rngstepn!(1, 5u32);
500-
rngstepp!(2, 12u32);
501-
rngstepn!(3, 33u32);
498+
rngstepp!(0, 21);
499+
rngstepn!(1, 5);
500+
rngstepp!(2, 12);
501+
rngstepn!(3, 33);
502502
}
503503
}
504504

src/test/run-pass/num-wrapping.rs

+30-28
Original file line numberDiff line numberDiff line change
@@ -309,22 +309,23 @@ fn test_sh_ops() {
309309
sh_test!(shl(usize::MAX, -((usize::BITS + 1) as $t)) == usize::MAX / 2);
310310
}
311311
}
312-
sh_test_all!(i8);
313-
sh_test_all!(u8);
314-
sh_test_all!(i16);
315-
sh_test_all!(u16);
316-
sh_test_all!(i32);
317-
sh_test_all!(u32);
318-
sh_test_all!(i64);
319-
sh_test_all!(u64);
320-
sh_test_all!(isize);
312+
// FIXME(#23545): Uncomment the remaining tests
313+
//sh_test_all!(i8);
314+
//sh_test_all!(u8);
315+
//sh_test_all!(i16);
316+
//sh_test_all!(u16);
317+
//sh_test_all!(i32);
318+
//sh_test_all!(u32);
319+
//sh_test_all!(i64);
320+
//sh_test_all!(u64);
321+
//sh_test_all!(isize);
321322
sh_test_all!(usize);
322323

323-
sh_test_negative_all!(i8);
324-
sh_test_negative_all!(i16);
325-
sh_test_negative_all!(i32);
326-
sh_test_negative_all!(i64);
327-
sh_test_negative_all!(isize);
324+
//sh_test_negative_all!(i8);
325+
//sh_test_negative_all!(i16);
326+
//sh_test_negative_all!(i32);
327+
//sh_test_negative_all!(i64);
328+
//sh_test_negative_all!(isize);
328329
}
329330

330331
fn test_sh_op_assigns() {
@@ -393,20 +394,21 @@ fn test_sh_op_assigns() {
393394
}
394395
}
395396

396-
sh_assign_test_all!(i8);
397-
sh_assign_test_all!(u8);
398-
sh_assign_test_all!(i16);
399-
sh_assign_test_all!(u16);
400-
sh_assign_test_all!(i32);
401-
sh_assign_test_all!(u32);
402-
sh_assign_test_all!(i64);
403-
sh_assign_test_all!(u64);
404-
sh_assign_test_all!(isize);
397+
// FIXME(#23545): Uncomment the remaining tests
398+
//sh_assign_test_all!(i8);
399+
//sh_assign_test_all!(u8);
400+
//sh_assign_test_all!(i16);
401+
//sh_assign_test_all!(u16);
402+
//sh_assign_test_all!(i32);
403+
//sh_assign_test_all!(u32);
404+
//sh_assign_test_all!(i64);
405+
//sh_assign_test_all!(u64);
406+
//sh_assign_test_all!(isize);
405407
sh_assign_test_all!(usize);
406408

407-
sh_assign_test_negative_all!(i8);
408-
sh_assign_test_negative_all!(i16);
409-
sh_assign_test_negative_all!(i32);
410-
sh_assign_test_negative_all!(i64);
411-
sh_assign_test_negative_all!(isize);
409+
//sh_assign_test_negative_all!(i8);
410+
//sh_assign_test_negative_all!(i16);
411+
//sh_assign_test_negative_all!(i32);
412+
//sh_assign_test_negative_all!(i64);
413+
//sh_assign_test_negative_all!(isize);
412414
}

0 commit comments

Comments
 (0)