Skip to content

Commit 3837c53

Browse files
committed
Auto merge of #3667 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 65f3e90 + b2ac396 commit 3837c53

File tree

8 files changed

+37
-23
lines changed

8 files changed

+37
-23
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
565cadb514d35e7b851540edbc172af0f606014f
1+
fa1681c9f6a66f0240c46c98bfef6209c9d6df23

src/concurrency/sync.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ macro_rules! declare_id {
4545
// We use 0 as a sentinel value (see the comment above) and,
4646
// therefore, need to shift by one when converting from an index
4747
// into a vector.
48-
let shifted_idx = u32::try_from(idx).unwrap().checked_add(1).unwrap();
48+
let shifted_idx = u32::try_from(idx).unwrap().strict_add(1);
4949
$name(std::num::NonZero::new(shifted_idx).unwrap())
5050
}
5151
fn index(self) -> usize {
@@ -350,7 +350,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
350350
} else {
351351
mutex.owner = Some(thread);
352352
}
353-
mutex.lock_count = mutex.lock_count.checked_add(1).unwrap();
353+
mutex.lock_count = mutex.lock_count.strict_add(1);
354354
if let Some(data_race) = &this.machine.data_race {
355355
data_race.acquire_clock(&mutex.clock, &this.machine.threads);
356356
}
@@ -370,9 +370,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
370370
return Ok(None);
371371
}
372372
let old_lock_count = mutex.lock_count;
373-
mutex.lock_count = old_lock_count
374-
.checked_sub(1)
375-
.expect("invariant violation: lock_count == 0 iff the thread is unlocked");
373+
mutex.lock_count = old_lock_count.strict_sub(1);
376374
if mutex.lock_count == 0 {
377375
mutex.owner = None;
378376
// The mutex is completely unlocked. Try transferring ownership
@@ -450,7 +448,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
450448
trace!("rwlock_reader_lock: {:?} now also held (one more time) by {:?}", id, thread);
451449
let rwlock = &mut this.machine.sync.rwlocks[id];
452450
let count = rwlock.readers.entry(thread).or_insert(0);
453-
*count = count.checked_add(1).expect("the reader counter overflowed");
451+
*count = count.strict_add(1);
454452
if let Some(data_race) = &this.machine.data_race {
455453
data_race.acquire_clock(&rwlock.clock_unlocked, &this.machine.threads);
456454
}

src/intrinsics/simd.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
643643
assert_eq!(index_len as u64, dest_len);
644644

645645
for i in 0..dest_len {
646-
let src_index: u64 = index[usize::try_from(i).unwrap()]
647-
.unwrap_leaf()
648-
.try_to_u32()
649-
.unwrap()
650-
.into();
646+
let src_index: u64 =
647+
index[usize::try_from(i).unwrap()].unwrap_leaf().to_u32().into();
651648
let dest = this.project_index(&dest, i)?;
652649

653650
let val = if src_index < left_len {

src/shims/os_str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
142142
os_str: &OsStr,
143143
memkind: MemoryKind,
144144
) -> InterpResult<'tcx, Pointer> {
145-
let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0` terminator.
145+
let size = u64::try_from(os_str.len()).unwrap().strict_add(1); // Make space for `0` terminator.
146146
let this = self.eval_context_mut();
147147

148148
let arg_type = Ty::new_array(this.tcx.tcx, this.tcx.types.u8, size);
@@ -158,7 +158,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
158158
os_str: &OsStr,
159159
memkind: MemoryKind,
160160
) -> InterpResult<'tcx, Pointer> {
161-
let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0x0000` terminator.
161+
let size = u64::try_from(os_str.len()).unwrap().strict_add(1); // Make space for `0x0000` terminator.
162162
let this = self.eval_context_mut();
163163

164164
let arg_type = Ty::new_array(this.tcx.tcx, this.tcx.types.u16, size);

src/shims/unix/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
893893

894894
let dirent64_layout = this.libc_ty_layout("dirent64");
895895
let d_name_offset = dirent64_layout.fields.offset(4 /* d_name */).bytes();
896-
let size = d_name_offset.checked_add(name_len).unwrap();
896+
let size = d_name_offset.strict_add(name_len);
897897

898898
let entry = this.allocate_ptr(
899899
Size::from_bytes(size),
@@ -994,7 +994,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
994994
name_place.ptr(),
995995
name_place.layout.size.bytes(),
996996
)?;
997-
let file_name_len = file_name_buf_len.checked_sub(1).unwrap();
997+
let file_name_len = file_name_buf_len.strict_sub(1);
998998
if !name_fits {
999999
throw_unsup_format!(
10001000
"a directory entry had a name too large to fit in libc::dirent"

src/shims/unix/socket.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
222222

223223
let fds = &mut this.machine.fds;
224224
let sv0 = fds.insert_fd(FileDescriptor::new(socketpair_0));
225-
let sv0 = Scalar::try_from_int(sv0, sv.layout.size).unwrap();
225+
let sv0 = Scalar::from_int(sv0, sv.layout.size);
226226
let sv1 = fds.insert_fd(FileDescriptor::new(socketpair_1));
227-
let sv1 = Scalar::try_from_int(sv1, sv.layout.size).unwrap();
227+
let sv1 = Scalar::from_int(sv1, sv.layout.size);
228228

229229
this.write_scalar(sv0, &sv)?;
230230
this.write_scalar(sv1, &sv.offset(sv.layout.size, sv.layout, this)?)?;

src/shims/x86/avx.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
176176
// of 4.
177177
let chunk_base = i & !0b11;
178178
let src_i = u64::from(this.read_scalar(&control)?.to_u32()? & 0b11)
179-
.checked_add(chunk_base)
180-
.unwrap();
179+
.strict_add(chunk_base);
181180

182181
this.copy_op(
183182
&this.project_index(&data, src_i)?,
@@ -210,9 +209,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
210209
// second instead of the first, ask Intel). To read the value from the current
211210
// chunk, add the destination index truncated to a multiple of 2.
212211
let chunk_base = i & !1;
213-
let src_i = ((this.read_scalar(&control)?.to_u64()? >> 1) & 1)
214-
.checked_add(chunk_base)
215-
.unwrap();
212+
let src_i =
213+
((this.read_scalar(&control)?.to_u64()? >> 1) & 1).strict_add(chunk_base);
216214

217215
this.copy_op(
218216
&this.project_index(&data, src_i)?,

tests/pass/intrinsics/portable-simd.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,32 @@ fn simd_masked_loadstore() {
658658
assert_eq!(buf, [2, 3, 4]);
659659
}
660660

661+
fn simd_ops_non_pow2() {
662+
// Just a little smoke test for operations on non-power-of-two vectors.
663+
#[repr(simd, packed)]
664+
#[derive(Copy, Clone)]
665+
pub struct SimdPacked<T, const N: usize>([T; N]);
666+
#[repr(simd)]
667+
#[derive(Copy, Clone)]
668+
pub struct SimdPadded<T, const N: usize>([T; N]);
669+
670+
let x = SimdPacked([1u32; 3]);
671+
let y = SimdPacked([2u32; 3]);
672+
let z = unsafe { intrinsics::simd_add(x, y) };
673+
assert_eq!({ z.0 }, [3u32; 3]);
674+
675+
let x = SimdPadded([1u32; 3]);
676+
let y = SimdPadded([2u32; 3]);
677+
let z = unsafe { intrinsics::simd_add(x, y) };
678+
assert_eq!(z.0, [3u32; 3]);
679+
}
680+
661681
fn main() {
662682
simd_mask();
663683
simd_ops_f32();
664684
simd_ops_f64();
665685
simd_ops_i32();
686+
simd_ops_non_pow2();
666687
simd_cast();
667688
simd_swizzle();
668689
simd_gather_scatter();

0 commit comments

Comments
 (0)