Skip to content

Miri subtree update #118567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1293a6a
Preparing for merge from rustc
Nov 27, 2023
fa6ecc9
Merge from rustc
Nov 27, 2023
9b8119d
Auto merge of #3193 - rust-lang:rustup-2023-11-27, r=RalfJung
bors Nov 27, 2023
8344dae
Remove Stacked Borrows GC heuristics
saethlin Nov 27, 2023
eaaf7e7
Auto merge of #3194 - saethlin:remove-gc-heuristics, r=RalfJung
bors Nov 28, 2023
1620865
explain tests that disable the provenance GC
RalfJung Nov 29, 2023
33e8232
Auto merge of #3196 - RalfJung:provenance-gc, r=RalfJung
bors Nov 29, 2023
76ec477
Preparing for merge from rustc
RalfJung Nov 30, 2023
7a661d0
Merge from rustc
RalfJung Nov 30, 2023
64fb96f
move 'uninit' tests into common directory
RalfJung Nov 30, 2023
a0c8b09
move some validity-related tests into subdir
RalfJung Nov 30, 2023
cd12440
give macOS some extra time, it needs that
RalfJung Nov 30, 2023
d368c40
Auto merge of #3197 - RalfJung:rustup, r=RalfJung
bors Nov 30, 2023
fce04ef
Preparing for merge from rustc
RalfJung Dec 2, 2023
b8a5076
Merge from rustc
RalfJung Dec 2, 2023
33515d7
Auto merge of #3201 - RalfJung:rustup, r=RalfJung
bors Dec 2, 2023
48176d4
Preparing for merge from rustc
Dec 3, 2023
3a6753b
Merge from rustc
Dec 3, 2023
6318e9d
Auto merge of #3202 - rust-lang:rustup-2023-12-03, r=saethlin
bors Dec 3, 2023
323ca94
new trophy case entry
RalfJung Dec 3, 2023
2a316c4
Auto merge of #3203 - RalfJung:trophy, r=RalfJung
bors Dec 3, 2023
11db9de
simd_select_bitmask: support passing the mask as an array
RalfJung Dec 3, 2023
31ea518
add simd_cttz and simd_ctlz
RalfJung Dec 3, 2023
2903f1c
add simd_bswap and simd_bitreverse
RalfJung Dec 3, 2023
28f9fe3
Auto merge of #3204 - RalfJung:simd, r=RalfJung
bors Dec 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/tools/miri/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ Definite bugs found:
* [`regex` incorrectly handling unaligned `Vec<u8>` buffers](https://www.reddit.com/r/rust/comments/vq3mmu/comment/ienc7t0?context=3)
* [Incorrect use of `compare_exchange_weak` in `once_cell`](https://github.com/matklad/once_cell/issues/186)
* [Dropping with unaligned pointers in `vec::IntoIter`](https://github.com/rust-lang/rust/pull/106084)
* [Deallocating with the wrong layout in new specializations for in-place `Iterator::collect`](https://github.com/rust-lang/rust/pull/118460)

Violations of [Stacked Borrows] found that are likely bugs (but Stacked Borrows is currently just an experiment):

Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3668a8af1b81447c4afa1f82f60d7b94b71a549f
225e36cff9809948d6567ab16f75d7b087ea83a7
15 changes: 3 additions & 12 deletions src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ pub struct Stacks {
history: AllocHistory,
/// The set of tags that have been exposed inside this allocation.
exposed_tags: FxHashSet<BorTag>,
/// Whether this memory has been modified since the last time the tag GC ran
modified_since_last_gc: bool,
}

/// Indicates which permissions to grant to the retagged pointer.
Expand Down Expand Up @@ -450,15 +448,10 @@ impl<'tcx> Stack {
/// Integration with the BorTag garbage collector
impl Stacks {
pub fn remove_unreachable_tags(&mut self, live_tags: &FxHashSet<BorTag>) {
if self.modified_since_last_gc {
for (_stack_range, stack) in self.stacks.iter_mut_all() {
if stack.len() > 64 {
stack.retain(live_tags);
}
}
self.history.retain(live_tags);
self.modified_since_last_gc = false;
for (_stack_range, stack) in self.stacks.iter_mut_all() {
stack.retain(live_tags);
}
self.history.retain(live_tags);
}
}

Expand Down Expand Up @@ -488,7 +481,6 @@ impl<'tcx> Stacks {
stacks: RangeMap::new(size, stack),
history: AllocHistory::new(id, item, machine),
exposed_tags: FxHashSet::default(),
modified_since_last_gc: false,
}
}

Expand All @@ -503,7 +495,6 @@ impl<'tcx> Stacks {
&mut FxHashSet<BorTag>,
) -> InterpResult<'tcx>,
) -> InterpResult<'tcx> {
self.modified_since_last_gc = true;
for (stack_range, stack) in self.stacks.iter_mut(range.start, range.size) {
let mut dcx = dcx_builder.build(&mut self.history, Size::from_bytes(stack_range.start));
f(stack, &mut dcx, &mut self.exposed_tags)?;
Expand Down
45 changes: 40 additions & 5 deletions src/tools/miri/src/shims/intrinsics/simd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rustc_apfloat::{Float, Round};
use rustc_middle::ty::layout::{HasParamEnv, LayoutOf};
use rustc_middle::{mir, ty, ty::FloatTy};
use rustc_span::{sym, Symbol};
use rustc_target::abi::{Endian, HasDataLayout};

use crate::*;
Expand All @@ -25,7 +26,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
| "floor"
| "round"
| "trunc"
| "fsqrt" => {
| "fsqrt"
| "ctlz"
| "cttz"
| "bswap"
| "bitreverse"
=> {
let [op] = check_arg_count(args)?;
let (op, op_len) = this.operand_to_simd(op)?;
let (dest, dest_len) = this.place_to_simd(dest)?;
Expand All @@ -38,6 +44,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
Abs,
Sqrt,
Round(rustc_apfloat::Round),
Numeric(Symbol),
}
let which = match intrinsic_name {
"neg" => Op::MirOp(mir::UnOp::Neg),
Expand All @@ -47,6 +54,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
"floor" => Op::Round(rustc_apfloat::Round::TowardNegative),
"round" => Op::Round(rustc_apfloat::Round::NearestTiesToAway),
"trunc" => Op::Round(rustc_apfloat::Round::TowardZero),
"ctlz" => Op::Numeric(sym::ctlz),
"cttz" => Op::Numeric(sym::cttz),
"bswap" => Op::Numeric(sym::bswap),
"bitreverse" => Op::Numeric(sym::bitreverse),
_ => unreachable!(),
};

Expand Down Expand Up @@ -101,6 +112,20 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
}
}
}
Op::Numeric(name) => {
assert!(op.layout.ty.is_integral());
let size = op.layout.size;
let bits = op.to_scalar().to_bits(size).unwrap();
let extra = 128u128.checked_sub(u128::from(size.bits())).unwrap();
let bits_out = match name {
sym::ctlz => u128::from(bits.leading_zeros()).checked_sub(extra).unwrap(),
sym::cttz => u128::from((bits << extra).trailing_zeros()).checked_sub(extra).unwrap(),
sym::bswap => (bits << extra).swap_bytes(),
sym::bitreverse => (bits << extra).reverse_bits(),
_ => unreachable!(),
};
Scalar::from_uint(bits_out, size)
}
};
this.write_scalar(val, &dest)?;
}
Expand All @@ -126,7 +151,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
| "fmin"
| "saturating_add"
| "saturating_sub"
| "arith_offset" => {
| "arith_offset"
=> {
use mir::BinOp;

let [left, right] = check_arg_count(args)?;
Expand Down Expand Up @@ -386,16 +412,25 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let (dest, dest_len) = this.place_to_simd(dest)?;
let bitmask_len = dest_len.max(8);

assert!(mask.layout.ty.is_integral());
assert!(bitmask_len <= 64);
assert_eq!(bitmask_len, mask.layout.size.bits());
assert_eq!(dest_len, yes_len);
assert_eq!(dest_len, no_len);
let dest_len = u32::try_from(dest_len).unwrap();
let bitmask_len = u32::try_from(bitmask_len).unwrap();

let mask: u64 =
this.read_scalar(mask)?.to_bits(mask.layout.size)?.try_into().unwrap();
// The mask can be a single integer or an array.
let mask: u64 = match mask.layout.ty.kind() {
ty::Int(..) | ty::Uint(..) =>
this.read_scalar(mask)?.to_bits(mask.layout.size)?.try_into().unwrap(),
ty::Array(elem, _) if matches!(elem.kind(), ty::Uint(ty::UintTy::U8)) => {
let mask_ty = this.machine.layouts.uint(mask.layout.size).unwrap();
let mask = mask.transmute(mask_ty, this)?;
this.read_scalar(&mask)?.to_bits(mask_ty.size)?.try_into().unwrap()
}
_ => bug!("simd_select_bitmask: invalid mask type {}", mask.layout.ty),
};

for i in 0..dest_len {
let mask = mask
& 1u64
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// We disable the GC for this test because it would change what is printed.
//@compile-flags: -Zmiri-tree-borrows -Zmiri-provenance-gc=0

// Check how a Reserved with interior mutability
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// We disable the GC for this test because it would change what is printed.
//@compile-flags: -Zmiri-tree-borrows -Zmiri-provenance-gc=0

#[path = "../../../utils/mod.rs"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@compile-flags: -Zmiri-disable-validation
//@error-in-other-file: memory is uninitialized at [0x4..0x10]

#![allow(dropping_copy_types)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LL | let mut order = unsafe { compare_bytes(left.as_ptr(), right.as_ptr(
= note: inside `<u8 as core::slice::cmp::SliceOrd>::compare` at RUSTLIB/core/src/slice/cmp.rs:LL:CC
= note: inside `core::slice::cmp::<impl std::cmp::Ord for [u8]>::cmp` at RUSTLIB/core/src/slice/cmp.rs:LL:CC
note: inside `main`
--> $DIR/uninit_buffer.rs:LL:CC
--> $DIR/uninit_alloc_diagnostic.rs:LL:CC
|
LL | drop(slice1.cmp(slice2));
| ^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@compile-flags: -Zmiri-disable-validation
//@error-in-other-file: memory is uninitialized at [0x4..0x8]
//@normalize-stderr-test: "a[0-9]+" -> "ALLOC"
#![feature(strict_provenance)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LL | let mut order = unsafe { compare_bytes(left.as_ptr(), right.as_ptr(
= note: inside `<u8 as core::slice::cmp::SliceOrd>::compare` at RUSTLIB/core/src/slice/cmp.rs:LL:CC
= note: inside `core::slice::cmp::<impl std::cmp::Ord for [u8]>::cmp` at RUSTLIB/core/src/slice/cmp.rs:LL:CC
note: inside `main`
--> $DIR/uninit_buffer_with_provenance.rs:LL:CC
--> $DIR/uninit_alloc_diagnostic_with_provenance.rs:LL:CC
|
LL | drop(slice1.cmp(slice2));
| ^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: Undefined Behavior: interpreting an invalid 8-bit value as a bool: 0x02
--> $DIR/invalid_bool.rs:LL:CC
--> $DIR/invalid_bool_op.rs:LL:CC
|
LL | let _x = b == std::hint::black_box(true);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ interpreting an invalid 8-bit value as a bool: 0x02
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `main` at $DIR/invalid_bool.rs:LL:CC
= note: inside `main` at $DIR/invalid_bool_op.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: Undefined Behavior: interpreting an invalid 32-bit value as a char: $HEX
--> $DIR/invalid_char.rs:LL:CC
--> $DIR/invalid_char_op.rs:LL:CC
|
LL | let _x = c == 'x';
| ^^^^^^^^ interpreting an invalid 32-bit value as a char: $HEX
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `main` at $DIR/invalid_char.rs:LL:CC
= note: inside `main` at $DIR/invalid_char_op.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: Undefined Behavior: enum value has invalid tag: $HEX
--> $DIR/invalid_enum_tag.rs:LL:CC
--> $DIR/invalid_enum_op.rs:LL:CC
|
LL | let _val = mem::discriminant(&f);
| ^^^^^^^^^^^^^^^^^^^^^ enum value has invalid tag: $HEX
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `main` at $DIR/invalid_enum_tag.rs:LL:CC
= note: inside `main` at $DIR/invalid_enum_op.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
--> $DIR/invalid_int.rs:LL:CC
--> $DIR/invalid_int_op.rs:LL:CC
|
LL | let i = unsafe { std::mem::MaybeUninit::<i32>::uninit().assume_init() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `main` at $DIR/invalid_int.rs:LL:CC
= note: inside `main` at $DIR/invalid_int_op.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/tests/pass/concurrency/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn check_conditional_variables_timed_wait_notimeout() {
cvar.notify_one();
});

let (_guard, timeout) = cvar.wait_timeout(guard, Duration::from_millis(500)).unwrap();
let (_guard, timeout) = cvar.wait_timeout(guard, Duration::from_millis(1000)).unwrap();
assert!(!timeout.timed_out());
handle.join().unwrap();
}
Expand Down
34 changes: 34 additions & 0 deletions src/tools/miri/tests/pass/portable-simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ fn simd_ops_i32() {
assert_eq!(b.reduce_or(), -1);
assert_eq!(a.reduce_xor(), 0);
assert_eq!(b.reduce_xor(), -4);

assert_eq!(b.leading_zeros(), u32x4::from_array([31, 30, 30, 0]));
assert_eq!(b.trailing_zeros(), u32x4::from_array([0, 1, 0, 2]));
assert_eq!(b.leading_ones(), u32x4::from_array([0, 0, 0, 30]));
assert_eq!(b.trailing_ones(), u32x4::from_array([1, 0, 2, 0]));
assert_eq!(
b.swap_bytes(),
i32x4::from_array([0x01000000, 0x02000000, 0x03000000, 0xfcffffffu32 as i32])
);
assert_eq!(
b.reverse_bits(),
i32x4::from_array([
0x80000000u32 as i32,
0x40000000,
0xc0000000u32 as i32,
0x3fffffffu32 as i32
])
);
}

fn simd_mask() {
Expand Down Expand Up @@ -247,6 +265,22 @@ fn simd_mask() {
assert_eq!(bitmask2, [0b0001]);
}
}

// This used to cause an ICE.
let bitmask = u8x8::from_array([0b01000101, 0, 0, 0, 0, 0, 0, 0]);
assert_eq!(
mask32x8::from_bitmask_vector(bitmask),
mask32x8::from_array([true, false, true, false, false, false, true, false]),
);
let bitmask =
u8x16::from_array([0b01000101, 0b11110000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
assert_eq!(
mask32x16::from_bitmask_vector(bitmask),
mask32x16::from_array([
true, false, true, false, false, false, true, false, false, false, false, false, true,
true, true, true,
]),
);
}

fn simd_cast() {
Expand Down
5 changes: 4 additions & 1 deletion src/tools/miri/tests/pass/stacked-borrows/stack-printing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//@compile-flags: -Zmiri-permissive-provenance
// We disable the GC for this test because it would change what is printed. We are testing the
// printing, not how it interacts with the GC.
//@compile-flags: -Zmiri-permissive-provenance -Zmiri-provenance-gc=0

#![feature(strict_provenance)]
use std::{
alloc::{self, Layout},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// We disable the GC for this test because it would change what is printed.
//@compile-flags: -Zmiri-tree-borrows -Zmiri-provenance-gc=0
#[path = "../../utils/mod.rs"]
#[macro_use]
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/pass/tree_borrows/end-of-protector.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// We disable the GC for this test because it would change what is printed.
//@compile-flags: -Zmiri-tree-borrows -Zmiri-provenance-gc=0

// Check that a protector goes back to normal behavior when the function
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/pass/tree_borrows/formatting.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// We disable the GC for this test because it would change what is printed.
//@compile-flags: -Zmiri-tree-borrows -Zmiri-provenance-gc=0

#[path = "../../utils/mod.rs"]
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/pass/tree_borrows/reborrow-is-read.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// We disable the GC for this test because it would change what is printed.
//@compile-flags: -Zmiri-tree-borrows -Zmiri-provenance-gc=0

#[path = "../../utils/mod.rs"]
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/pass/tree_borrows/reserved.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// We disable the GC for this test because it would change what is printed.
//@compile-flags: -Zmiri-tree-borrows -Zmiri-provenance-gc=0

#[path = "../../utils/mod.rs"]
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/pass/tree_borrows/unique.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@revisions: default uniq
// We disable the GC for this test because it would change what is printed.
//@compile-flags: -Zmiri-tree-borrows -Zmiri-provenance-gc=0
//@[uniq]compile-flags: -Zmiri-unique-is-unique

Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/pass/tree_borrows/vec_unique.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@revisions: default uniq
// We disable the GC for this test because it would change what is printed.
//@compile-flags: -Zmiri-tree-borrows -Zmiri-provenance-gc=0
//@[uniq]compile-flags: -Zmiri-unique-is-unique

Expand Down