Skip to content

Commit

Permalink
Auto merge of rust-lang#137594 - RalfJung:miri-sync, r=RalfJung
Browse files Browse the repository at this point in the history
Miri subtree update

r? `@ghost`
  • Loading branch information
bors committed Feb 25, 2025
2 parents ad27045 + 5e4c582 commit ca04cf6
Show file tree
Hide file tree
Showing 37 changed files with 705 additions and 299 deletions.
1 change: 1 addition & 0 deletions library/coretests/tests/num/int_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn checked_ilog() {
}

#[test]
#[cfg_attr(miri, ignore)] // FIXME test is broken on Miri: https://github.com/rust-lang/rust/issues/137591
fn checked_ilog2() {
assert_eq!(5u32.checked_ilog2(), Some(2));
assert_eq!(0u64.checked_ilog2(), None);
Expand Down
2 changes: 2 additions & 0 deletions src/tools/miri/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/setup
with:
toolchain_flags: "--host ${{ matrix.host_target }}"

# The `style` job only runs on Linux; this makes sure the Windows-host-specific
# code is also covered by clippy.
Expand Down
6 changes: 5 additions & 1 deletion src/tools/miri/.github/workflows/setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: "Miri CI setup"
description: "Sets up Miri CI"
inputs:
toolchain_flags:
required: false
default: ''
runs:
using: "composite"
steps:
Expand Down Expand Up @@ -45,7 +49,7 @@ runs:
echo "Building against latest rustc git version"
git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1 > rust-version
fi
./miri toolchain
./miri toolchain ${{ inputs.toolchain_flags }}
shell: bash

- name: Show Rust version (miri toolchain)
Expand Down
4 changes: 4 additions & 0 deletions src/tools/miri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ default = ["stack-cache"]
stack-cache = []
stack-cache-consistency-check = ["stack-cache"]

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = ['cfg(bootstrap)']

# Be aware that this file is inside a workspace when used via the
# submodule in the rustc repo. That means there are many cargo features
# we cannot use, such as profiles.
10 changes: 0 additions & 10 deletions src/tools/miri/build.rs

This file was deleted.

13 changes: 12 additions & 1 deletion src/tools/miri/ci/ci.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -euo pipefail
set -eu

function begingroup {
echo "::group::$@"
Expand All @@ -11,6 +11,17 @@ function endgroup {
echo "::endgroup"
}

begingroup "Sanity-check environment"

# Ensure the HOST_TARGET is what it should be.
if ! rustc -vV | grep -q "^host: $HOST_TARGET\$"; then
echo "This runner should be using host target $HOST_TARGET but rustc disagrees:"
rustc -vV
exit 1
fi

endgroup

begingroup "Building Miri"

# Global configuration
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 @@
6dd75f0d6802f56564f5f9c947a85ded286d3986
f5729cfed3c45e061e8a443677fc1d5ef9277df7
6 changes: 3 additions & 3 deletions src/tools/miri/src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use std::num::NonZero;
use std::ops::Range;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::{Arc, Once};
use std::sync::atomic::{AtomicI32, AtomicU32, Ordering};
use std::sync::{Arc, Once};

use miri::{
BacktraceStyle, BorrowTrackerMethod, MiriConfig, MiriEntryFnType, ProvenanceMode, RetagFields,
Expand Down Expand Up @@ -720,8 +720,8 @@ fn main() {

// Ensure we have parallelism for many-seeds mode.
if many_seeds.is_some() && !rustc_args.iter().any(|arg| arg.starts_with("-Zthreads=")) {
// Clamp to 10 threads; things get a lot less efficient beyond that due to lock contention.
let threads = std::thread::available_parallelism().map_or(1, |n| n.get()).min(10);
// Clamp to 20 threads; things get a less efficient beyond that due to lock contention.
let threads = std::thread::available_parallelism().map_or(1, |n| n.get()).min(20);
rustc_args.push(format!("-Zthreads={threads}"));
}
let many_seeds =
Expand Down
69 changes: 37 additions & 32 deletions src/tools/miri/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,20 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
&'a [OpTy<'tcx>; N]: TryFrom<&'a [OpTy<'tcx>]>,
{
self.check_abi_and_shim_symbol_clash(abi, exp_abi, link_name)?;
check_arg_count(args)

if abi.c_variadic {
throw_ub_format!(
"calling a non-variadic function with a variadic caller-side signature"
);
}
if let Ok(ops) = args.try_into() {
return interp_ok(ops);
}
throw_ub_format!(
"incorrect number of arguments for `{link_name}`: got {}, expected {}",
args.len(),
N
)
}

/// Check shim for variadic function.
Expand All @@ -1015,7 +1028,23 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
&'a [OpTy<'tcx>; N]: TryFrom<&'a [OpTy<'tcx>]>,
{
self.check_abi_and_shim_symbol_clash(abi, exp_abi, link_name)?;
check_vargarg_fixed_arg_count(link_name, abi, args)

if !abi.c_variadic {
throw_ub_format!(
"calling a variadic function with a non-variadic caller-side signature"
);
}
if abi.fixed_count != u32::try_from(N).unwrap() {
throw_ub_format!(
"incorrect number of fixed arguments for variadic function `{}`: got {}, expected {N}",
link_name.as_str(),
abi.fixed_count
)
}
if let Some(args) = args.split_first_chunk() {
return interp_ok(args);
}
panic!("mismatch between signature and `args` slice");
}

/// Mark a machine allocation that was just created as immutable.
Expand Down Expand Up @@ -1199,7 +1228,7 @@ impl<'tcx> MiriMachine<'tcx> {
}

/// Check that the number of args is what we expect.
pub fn check_arg_count<'a, 'tcx, const N: usize>(
pub fn check_intrinsic_arg_count<'a, 'tcx, const N: usize>(
args: &'a [OpTy<'tcx>],
) -> InterpResult<'tcx, &'a [OpTy<'tcx>; N]>
where
Expand All @@ -1208,7 +1237,11 @@ where
if let Ok(ops) = args.try_into() {
return interp_ok(ops);
}
throw_ub_format!("incorrect number of arguments: got {}, expected {}", args.len(), N)
throw_ub_format!(
"incorrect number of arguments for intrinsic: got {}, expected {}",
args.len(),
N
)
}

/// Check that the number of varargs is at least the minimum what we expect.
Expand All @@ -1228,34 +1261,6 @@ pub fn check_min_vararg_count<'a, 'tcx, const N: usize>(
)
}

/// Check the number of fixed args of a vararg function.
/// Returns a tuple that consisting of an array of fixed args, and a slice of varargs.
fn check_vargarg_fixed_arg_count<'a, 'tcx, const N: usize>(
link_name: Symbol,
abi: &FnAbi<'tcx, Ty<'tcx>>,
args: &'a [OpTy<'tcx>],
) -> InterpResult<'tcx, (&'a [OpTy<'tcx>; N], &'a [OpTy<'tcx>])> {
if !abi.c_variadic {
throw_ub_format!("calling a variadic function with a non-variadic caller-side signature");
}
if abi.fixed_count != u32::try_from(N).unwrap() {
throw_ub_format!(
"incorrect number of fixed arguments for variadic function `{}`: got {}, expected {N}",
link_name.as_str(),
abi.fixed_count
)
}
if let Some(args) = args.split_first_chunk() {
return interp_ok(args);
}
throw_ub_format!(
"incorrect number of arguments for `{}`: got {}, expected at least {}",
link_name.as_str(),
args.len(),
N
)
}

pub fn isolation_abort_error<'tcx>(name: &str) -> InterpResult<'tcx> {
throw_machine_stop!(TerminationInfo::UnsupportedInIsolation(format!(
"{name} not available when isolation is enabled",
Expand Down
16 changes: 8 additions & 8 deletions src/tools/miri/src/intrinsics/atomic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_middle::mir::BinOp;
use rustc_middle::{mir, ty};

use self::helpers::check_arg_count;
use self::helpers::check_intrinsic_arg_count;
use crate::*;

pub enum AtomicOp {
Expand Down Expand Up @@ -131,7 +131,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();

let [place] = check_arg_count(args)?;
let [place] = check_intrinsic_arg_count(args)?;
let place = this.deref_pointer(place)?;

// Perform atomic load.
Expand All @@ -144,7 +144,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
fn atomic_store(&mut self, args: &[OpTy<'tcx>], atomic: AtomicWriteOrd) -> InterpResult<'tcx> {
let this = self.eval_context_mut();

let [place, val] = check_arg_count(args)?;
let [place, val] = check_intrinsic_arg_count(args)?;
let place = this.deref_pointer(place)?;

// Perform regular load.
Expand All @@ -159,7 +159,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
args: &[OpTy<'tcx>],
atomic: AtomicFenceOrd,
) -> InterpResult<'tcx> {
let [] = check_arg_count(args)?;
let [] = check_intrinsic_arg_count(args)?;
let _ = atomic;
//FIXME: compiler fences are currently ignored
interp_ok(())
Expand All @@ -171,7 +171,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
atomic: AtomicFenceOrd,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let [] = check_arg_count(args)?;
let [] = check_intrinsic_arg_count(args)?;
this.atomic_fence(atomic)?;
interp_ok(())
}
Expand All @@ -185,7 +185,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();

let [place, rhs] = check_arg_count(args)?;
let [place, rhs] = check_intrinsic_arg_count(args)?;
let place = this.deref_pointer(place)?;
let rhs = this.read_immediate(rhs)?;

Expand Down Expand Up @@ -226,7 +226,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();

let [place, new] = check_arg_count(args)?;
let [place, new] = check_intrinsic_arg_count(args)?;
let place = this.deref_pointer(place)?;
let new = this.read_scalar(new)?;

Expand All @@ -245,7 +245,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();

let [place, expect_old, new] = check_arg_count(args)?;
let [place, expect_old, new] = check_intrinsic_arg_count(args)?;
let place = this.deref_pointer(place)?;
let expect_old = this.read_immediate(expect_old)?; // read as immediate for the sake of `binary_op()`
let new = this.read_scalar(new)?;
Expand Down
Loading

0 comments on commit ca04cf6

Please sign in to comment.