Skip to content

Commit 1623978

Browse files
committed
Auto merge of rust-lang#111535 - RalfJung:miri, r=RalfJung
update Miri Needed to get miri-test-libstd working again
2 parents dd8ec9c + d8815ef commit 1623978

File tree

10 files changed

+95
-31
lines changed

10 files changed

+95
-31
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -5123,9 +5123,9 @@ checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81"
51235123

51245124
[[package]]
51255125
name = "ui_test"
5126-
version = "0.9.0"
5126+
version = "0.10.0"
51275127
source = "registry+https://github.com/rust-lang/crates.io-index"
5128-
checksum = "95033b0e41b8018013d99a6f1486c1ae5bd080378ced60c5f797e93842423b33"
5128+
checksum = "191a442639ea102fa62671026047e51d574bfda44b7fdf32151d7314624c1cd2"
51295129
dependencies = [
51305130
"bstr 1.3.0",
51315131
"cargo-platform",

src/tools/miri/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,9 @@ dependencies = [
820820

821821
[[package]]
822822
name = "ui_test"
823-
version = "0.9.0"
823+
version = "0.10.0"
824824
source = "registry+https://github.com/rust-lang/crates.io-index"
825-
checksum = "95033b0e41b8018013d99a6f1486c1ae5bd080378ced60c5f797e93842423b33"
825+
checksum = "191a442639ea102fa62671026047e51d574bfda44b7fdf32151d7314624c1cd2"
826826
dependencies = [
827827
"bstr",
828828
"cargo-platform",

src/tools/miri/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ libloading = "0.7"
3939

4040
[dev-dependencies]
4141
colored = "2"
42-
ui_test = "0.9"
42+
ui_test = "0.10"
4343
rustc_version = "0.4"
4444
# Features chosen to match those required by env_logger, to avoid rebuilds
4545
regex = { version = "1.5.5", default-features = false, features = ["perf", "std"] }

src/tools/miri/miri

+8-2
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ test|bless)
306306
# Only in root project as `cargo-miri` has no tests.
307307
$CARGO test $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml "$@"
308308
;;
309-
run)
309+
run|run-dep)
310310
# Scan for "--target" to overwrite the "MIRI_TEST_TARGET" env var so
311311
# that we set the MIRI_SYSROOT up the right way.
312312
FOUND_TARGET_OPT=0
@@ -323,11 +323,17 @@ run)
323323
# Make sure Miri actually uses this target.
324324
MIRIFLAGS="$MIRIFLAGS --target $MIRI_TEST_TARGET"
325325
fi
326+
326327
# First build and get a sysroot.
327328
$CARGO build $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml
328329
find_sysroot
329330
# Then run the actual command.
330-
exec $CARGO run $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml -- $MIRIFLAGS "$@"
331+
332+
if [ "$COMMAND" = "run-dep" ]; then
333+
exec $CARGO test --test compiletest $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml -- --miri-run-dep-mode $MIRIFLAGS "$@"
334+
else
335+
exec $CARGO run $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml -- $MIRIFLAGS "$@"
336+
fi
331337
;;
332338
fmt)
333339
find "$MIRIDIR" -not \( -name target -prune \) -name '*.rs' \

src/tools/miri/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0b795044c6f0854445f1f2bb6443e87848e150d1
1+
69fef92ab2f287f072b66fb7b4f62c8bb4acba43

src/tools/miri/src/borrow_tracker/stacked_borrows/stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Stack {
8383
self.borrows.truncate(write_idx);
8484

8585
#[cfg(not(feature = "stack-cache"))]
86-
drop(first_removed); // This is only needed for the stack-cache
86+
let _unused = first_removed; // This is only needed for the stack-cache
8787

8888
#[cfg(feature = "stack-cache")]
8989
if let Some(first_removed) = first_removed {

src/tools/miri/src/shims/intrinsics/simd.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -421,34 +421,50 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
421421
}
422422
}
423423
#[rustfmt::skip]
424-
"cast" | "as" => {
424+
"cast" | "as" | "cast_ptr" | "expose_addr" | "from_exposed_addr" => {
425425
let [op] = check_arg_count(args)?;
426426
let (op, op_len) = this.operand_to_simd(op)?;
427427
let (dest, dest_len) = this.place_to_simd(dest)?;
428428

429429
assert_eq!(dest_len, op_len);
430430

431+
let unsafe_cast = intrinsic_name == "cast";
431432
let safe_cast = intrinsic_name == "as";
433+
let ptr_cast = intrinsic_name == "cast_ptr";
434+
let expose_cast = intrinsic_name == "expose_addr";
435+
let from_exposed_cast = intrinsic_name == "from_exposed_addr";
432436

433437
for i in 0..dest_len {
434438
let op = this.read_immediate(&this.mplace_index(&op, i)?.into())?;
435439
let dest = this.mplace_index(&dest, i)?;
436440

437441
let val = match (op.layout.ty.kind(), dest.layout.ty.kind()) {
438442
// Int-to-(int|float): always safe
439-
(ty::Int(_) | ty::Uint(_), ty::Int(_) | ty::Uint(_) | ty::Float(_)) =>
443+
(ty::Int(_) | ty::Uint(_), ty::Int(_) | ty::Uint(_) | ty::Float(_)) if safe_cast || unsafe_cast =>
440444
this.int_to_int_or_float(&op, dest.layout.ty)?,
441445
// Float-to-float: always safe
442-
(ty::Float(_), ty::Float(_)) =>
446+
(ty::Float(_), ty::Float(_)) if safe_cast || unsafe_cast =>
443447
this.float_to_float_or_int(&op, dest.layout.ty)?,
444448
// Float-to-int in safe mode
445449
(ty::Float(_), ty::Int(_) | ty::Uint(_)) if safe_cast =>
446450
this.float_to_float_or_int(&op, dest.layout.ty)?,
447451
// Float-to-int in unchecked mode
448-
(ty::Float(FloatTy::F32), ty::Int(_) | ty::Uint(_)) if !safe_cast =>
452+
(ty::Float(FloatTy::F32), ty::Int(_) | ty::Uint(_)) if unsafe_cast =>
449453
this.float_to_int_unchecked(op.to_scalar().to_f32()?, dest.layout.ty)?.into(),
450-
(ty::Float(FloatTy::F64), ty::Int(_) | ty::Uint(_)) if !safe_cast =>
454+
(ty::Float(FloatTy::F64), ty::Int(_) | ty::Uint(_)) if unsafe_cast =>
451455
this.float_to_int_unchecked(op.to_scalar().to_f64()?, dest.layout.ty)?.into(),
456+
// Ptr-to-ptr cast
457+
(ty::RawPtr(..), ty::RawPtr(..)) if ptr_cast => {
458+
this.ptr_to_ptr(&op, dest.layout.ty)?
459+
}
460+
// Ptr/Int casts
461+
(ty::RawPtr(..), ty::Int(_) | ty::Uint(_)) if expose_cast => {
462+
this.pointer_expose_address_cast(&op, dest.layout.ty)?
463+
}
464+
(ty::Int(_) | ty::Uint(_), ty::RawPtr(..)) if from_exposed_cast => {
465+
this.pointer_from_exposed_address_cast(&op, dest.layout.ty)?
466+
}
467+
// Error otherwise
452468
_ =>
453469
throw_unsup_format!(
454470
"Unsupported SIMD cast from element type {from_ty} to {to_ty}",

src/tools/miri/tests/compiletest.rs

+47-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use colored::*;
22
use regex::bytes::Regex;
3+
use std::ffi::OsString;
34
use std::path::{Path, PathBuf};
45
use std::{env, process::Command};
56
use ui_test::status_emitter::StatusEmitter;
@@ -45,7 +46,7 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
4546
so_file_path
4647
}
4748

48-
fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> Result<()> {
49+
fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) -> Config {
4950
// Miri is rustc-like, so we create a default builder for rustc and modify it
5051
let mut program = CommandBuilder::rustc();
5152
program.program = miri_path();
@@ -103,6 +104,26 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
103104
..Config::default()
104105
};
105106

107+
let use_std = env::var_os("MIRI_NO_STD").is_none();
108+
109+
if with_dependencies && use_std {
110+
config.dependencies_crate_manifest_path =
111+
Some(Path::new("test_dependencies").join("Cargo.toml"));
112+
config.dependency_builder.args = vec![
113+
"run".into(),
114+
"--manifest-path".into(),
115+
"cargo-miri/Cargo.toml".into(),
116+
"--".into(),
117+
"miri".into(),
118+
"run".into(), // There is no `cargo miri build` so we just use `cargo miri run`.
119+
];
120+
}
121+
config
122+
}
123+
124+
fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> Result<()> {
125+
let mut config = test_config(target, path, mode, with_dependencies);
126+
106127
// Handle command-line arguments.
107128
let mut after_dashdash = false;
108129
config.path_filter.extend(std::env::args().skip(1).filter(|arg| {
@@ -126,21 +147,6 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
126147
}
127148
}));
128149

129-
let use_std = env::var_os("MIRI_NO_STD").is_none();
130-
131-
if with_dependencies && use_std {
132-
config.dependencies_crate_manifest_path =
133-
Some(Path::new("test_dependencies").join("Cargo.toml"));
134-
config.dependency_builder.args = vec![
135-
"run".into(),
136-
"--manifest-path".into(),
137-
"cargo-miri/Cargo.toml".into(),
138-
"--".into(),
139-
"miri".into(),
140-
"run".into(), // There is no `cargo miri build` so we just use `cargo miri run`.
141-
];
142-
}
143-
144150
eprintln!(" Compiler: {}", config.program.display());
145151
ui_test::run_tests_generic(
146152
config,
@@ -226,8 +232,18 @@ fn get_target() -> String {
226232

227233
fn main() -> Result<()> {
228234
ui_test::color_eyre::install()?;
235+
229236
let target = get_target();
230237

238+
let mut args = std::env::args_os();
239+
240+
// Skip the program name and check whether this is a `./miri run-dep` invocation
241+
if let Some(first) = args.nth(1) {
242+
if first == "--miri-run-dep-mode" {
243+
return run_dep_mode(target, args);
244+
}
245+
}
246+
231247
// Add a test env var to do environment communication tests.
232248
env::set_var("MIRI_ENV_VAR_TEST", "0");
233249
// Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
@@ -250,6 +266,21 @@ fn main() -> Result<()> {
250266
Ok(())
251267
}
252268

269+
fn run_dep_mode(target: String, mut args: impl Iterator<Item = OsString>) -> Result<()> {
270+
let path = args.next().expect("./miri run-dep must be followed by a file name");
271+
let mut config = test_config(&target, "", Mode::Yolo, /* with dependencies */ true);
272+
config.program.args.remove(0); // remove the `--error-format=json` argument
273+
config.program.args.push("--color".into());
274+
config.program.args.push("always".into());
275+
let mut cmd = ui_test::test_command(config, Path::new(&path))?;
276+
// Separate the arguments to the `cargo miri` invocation from
277+
// the arguments to the interpreted prog
278+
cmd.arg("--");
279+
cmd.args(args);
280+
println!("{cmd:?}");
281+
if cmd.spawn()?.wait()?.success() { Ok(()) } else { std::process::exit(1) }
282+
}
283+
253284
/// This is a custom renderer for `ui_test` output that does not emit github actions
254285
/// `group`s, while still producing regular github actions messages on test failures.
255286
struct TextAndGha;

src/tools/miri/tests/fail/uninit_buffer_with_provenance.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//@error-in-other-file: memory is uninitialized at [0x4..0x8]
22
//@normalize-stderr-test: "a[0-9]+" -> "ALLOC"
33
#![feature(strict_provenance)]
4-
54
#![allow(drop_copy)]
65

76
// Test printing allocations that contain single-byte provenance.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Separate test without strict provenance
2+
//@compile-flags: -Zmiri-permissive-provenance
3+
#![feature(portable_simd, platform_intrinsics)]
4+
use std::ptr;
5+
use std::simd::*;
6+
7+
fn main() {
8+
// Pointer casts
9+
let _val: Simd<*const u8, 4> = Simd::<*const i32, 4>::splat(ptr::null()).cast_ptr();
10+
let addrs = Simd::<*const i32, 4>::splat(ptr::null()).expose_addr();
11+
let _ptrs = Simd::<*const i32, 4>::from_exposed_addr(addrs);
12+
}

0 commit comments

Comments
 (0)