Skip to content

Commit cb06d12

Browse files
committed
Auto merge of rust-lang#137594 - RalfJung:miri-sync, r=RalfJung
Miri subtree update r? `@ghost` try-job: x86_64-gnu-aux
2 parents 85abb27 + 716dd22 commit cb06d12

38 files changed

+715
-298
lines changed

library/coretests/tests/num/int_log.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fn checked_ilog() {
3434
}
3535

3636
#[test]
37+
#[cfg_attr(miri, ignore)] // FIXME test is broken on Miri: https://github.com/rust-lang/rust/issues/137591
3738
fn checked_ilog2() {
3839
assert_eq!(5u32.checked_ilog2(), Some(2));
3940
assert_eq!(0u64.checked_ilog2(), None);

src/build_helper/src/git.rs

-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ pub fn get_closest_merge_commit(
154154
"rev-list",
155155
&format!("--author={}", config.git_merge_commit_email),
156156
"-n1",
157-
"--first-parent",
158157
&merge_base,
159158
]);
160159

src/tools/miri/.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
steps:
3131
- uses: actions/checkout@v4
3232
- uses: ./.github/workflows/setup
33+
with:
34+
toolchain_flags: "--host ${{ matrix.host_target }}"
3335

3436
# The `style` job only runs on Linux; this makes sure the Windows-host-specific
3537
# code is also covered by clippy.

src/tools/miri/.github/workflows/setup/action.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: "Miri CI setup"
22
description: "Sets up Miri CI"
3+
inputs:
4+
toolchain_flags:
5+
required: false
6+
default: ''
37
runs:
48
using: "composite"
59
steps:
@@ -45,7 +49,7 @@ runs:
4549
echo "Building against latest rustc git version"
4650
git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1 > rust-version
4751
fi
48-
./miri toolchain
52+
./miri toolchain ${{ inputs.toolchain_flags }}
4953
shell: bash
5054

5155
- name: Show Rust version (miri toolchain)

src/tools/miri/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ default = ["stack-cache"]
6767
stack-cache = []
6868
stack-cache-consistency-check = ["stack-cache"]
6969

70+
[lints.rust.unexpected_cfgs]
71+
level = "warn"
72+
check-cfg = ['cfg(bootstrap)']
73+
7074
# Be aware that this file is inside a workspace when used via the
7175
# submodule in the rustc repo. That means there are many cargo features
7276
# we cannot use, such as profiles.

src/tools/miri/build.rs

-10
This file was deleted.

src/tools/miri/ci/ci.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -euo pipefail
2+
set -eu
33

44
function begingroup {
55
echo "::group::$@"
@@ -11,6 +11,17 @@ function endgroup {
1111
echo "::endgroup"
1212
}
1313

14+
begingroup "Sanity-check environment"
15+
16+
# Ensure the HOST_TARGET is what it should be.
17+
if ! rustc -vV | grep -q "^host: $HOST_TARGET\$"; then
18+
echo "This runner should be using host target $HOST_TARGET but rustc disagrees:"
19+
rustc -vV
20+
exit 1
21+
fi
22+
23+
endgroup
24+
1425
begingroup "Building Miri"
1526

1627
# Global configuration

src/tools/miri/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6dd75f0d6802f56564f5f9c947a85ded286d3986
1+
f5729cfed3c45e061e8a443677fc1d5ef9277df7

src/tools/miri/src/bin/miri.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use std::num::NonZero;
2929
use std::ops::Range;
3030
use std::path::PathBuf;
3131
use std::str::FromStr;
32-
use std::sync::{Arc, Once};
3332
use std::sync::atomic::{AtomicI32, AtomicU32, Ordering};
33+
use std::sync::{Arc, Once};
3434

3535
use miri::{
3636
BacktraceStyle, BorrowTrackerMethod, MiriConfig, MiriEntryFnType, ProvenanceMode, RetagFields,
@@ -720,8 +720,8 @@ fn main() {
720720

721721
// Ensure we have parallelism for many-seeds mode.
722722
if many_seeds.is_some() && !rustc_args.iter().any(|arg| arg.starts_with("-Zthreads=")) {
723-
// Clamp to 10 threads; things get a lot less efficient beyond that due to lock contention.
724-
let threads = std::thread::available_parallelism().map_or(1, |n| n.get()).min(10);
723+
// Clamp to 20 threads; things get a less efficient beyond that due to lock contention.
724+
let threads = std::thread::available_parallelism().map_or(1, |n| n.get()).min(20);
725725
rustc_args.push(format!("-Zthreads={threads}"));
726726
}
727727
let many_seeds =

src/tools/miri/src/helpers.rs

+37-32
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,20 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
999999
&'a [OpTy<'tcx>; N]: TryFrom<&'a [OpTy<'tcx>]>,
10001000
{
10011001
self.check_abi_and_shim_symbol_clash(abi, exp_abi, link_name)?;
1002-
check_arg_count(args)
1002+
1003+
if abi.c_variadic {
1004+
throw_ub_format!(
1005+
"calling a non-variadic function with a variadic caller-side signature"
1006+
);
1007+
}
1008+
if let Ok(ops) = args.try_into() {
1009+
return interp_ok(ops);
1010+
}
1011+
throw_ub_format!(
1012+
"incorrect number of arguments for `{link_name}`: got {}, expected {}",
1013+
args.len(),
1014+
N
1015+
)
10031016
}
10041017

10051018
/// Check shim for variadic function.
@@ -1015,7 +1028,23 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10151028
&'a [OpTy<'tcx>; N]: TryFrom<&'a [OpTy<'tcx>]>,
10161029
{
10171030
self.check_abi_and_shim_symbol_clash(abi, exp_abi, link_name)?;
1018-
check_vargarg_fixed_arg_count(link_name, abi, args)
1031+
1032+
if !abi.c_variadic {
1033+
throw_ub_format!(
1034+
"calling a variadic function with a non-variadic caller-side signature"
1035+
);
1036+
}
1037+
if abi.fixed_count != u32::try_from(N).unwrap() {
1038+
throw_ub_format!(
1039+
"incorrect number of fixed arguments for variadic function `{}`: got {}, expected {N}",
1040+
link_name.as_str(),
1041+
abi.fixed_count
1042+
)
1043+
}
1044+
if let Some(args) = args.split_first_chunk() {
1045+
return interp_ok(args);
1046+
}
1047+
panic!("mismatch between signature and `args` slice");
10191048
}
10201049

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

12011230
/// Check that the number of args is what we expect.
1202-
pub fn check_arg_count<'a, 'tcx, const N: usize>(
1231+
pub fn check_intrinsic_arg_count<'a, 'tcx, const N: usize>(
12031232
args: &'a [OpTy<'tcx>],
12041233
) -> InterpResult<'tcx, &'a [OpTy<'tcx>; N]>
12051234
where
@@ -1208,7 +1237,11 @@ where
12081237
if let Ok(ops) = args.try_into() {
12091238
return interp_ok(ops);
12101239
}
1211-
throw_ub_format!("incorrect number of arguments: got {}, expected {}", args.len(), N)
1240+
throw_ub_format!(
1241+
"incorrect number of arguments for intrinsic: got {}, expected {}",
1242+
args.len(),
1243+
N
1244+
)
12121245
}
12131246

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

1231-
/// Check the number of fixed args of a vararg function.
1232-
/// Returns a tuple that consisting of an array of fixed args, and a slice of varargs.
1233-
fn check_vargarg_fixed_arg_count<'a, 'tcx, const N: usize>(
1234-
link_name: Symbol,
1235-
abi: &FnAbi<'tcx, Ty<'tcx>>,
1236-
args: &'a [OpTy<'tcx>],
1237-
) -> InterpResult<'tcx, (&'a [OpTy<'tcx>; N], &'a [OpTy<'tcx>])> {
1238-
if !abi.c_variadic {
1239-
throw_ub_format!("calling a variadic function with a non-variadic caller-side signature");
1240-
}
1241-
if abi.fixed_count != u32::try_from(N).unwrap() {
1242-
throw_ub_format!(
1243-
"incorrect number of fixed arguments for variadic function `{}`: got {}, expected {N}",
1244-
link_name.as_str(),
1245-
abi.fixed_count
1246-
)
1247-
}
1248-
if let Some(args) = args.split_first_chunk() {
1249-
return interp_ok(args);
1250-
}
1251-
throw_ub_format!(
1252-
"incorrect number of arguments for `{}`: got {}, expected at least {}",
1253-
link_name.as_str(),
1254-
args.len(),
1255-
N
1256-
)
1257-
}
1258-
12591264
pub fn isolation_abort_error<'tcx>(name: &str) -> InterpResult<'tcx> {
12601265
throw_machine_stop!(TerminationInfo::UnsupportedInIsolation(format!(
12611266
"{name} not available when isolation is enabled",

src/tools/miri/src/intrinsics/atomic.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_middle::mir::BinOp;
22
use rustc_middle::{mir, ty};
33

4-
use self::helpers::check_arg_count;
4+
use self::helpers::check_intrinsic_arg_count;
55
use crate::*;
66

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

134-
let [place] = check_arg_count(args)?;
134+
let [place] = check_intrinsic_arg_count(args)?;
135135
let place = this.deref_pointer(place)?;
136136

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

147-
let [place, val] = check_arg_count(args)?;
147+
let [place, val] = check_intrinsic_arg_count(args)?;
148148
let place = this.deref_pointer(place)?;
149149

150150
// Perform regular load.
@@ -159,7 +159,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
159159
args: &[OpTy<'tcx>],
160160
atomic: AtomicFenceOrd,
161161
) -> InterpResult<'tcx> {
162-
let [] = check_arg_count(args)?;
162+
let [] = check_intrinsic_arg_count(args)?;
163163
let _ = atomic;
164164
//FIXME: compiler fences are currently ignored
165165
interp_ok(())
@@ -171,7 +171,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
171171
atomic: AtomicFenceOrd,
172172
) -> InterpResult<'tcx> {
173173
let this = self.eval_context_mut();
174-
let [] = check_arg_count(args)?;
174+
let [] = check_intrinsic_arg_count(args)?;
175175
this.atomic_fence(atomic)?;
176176
interp_ok(())
177177
}
@@ -185,7 +185,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
185185
) -> InterpResult<'tcx> {
186186
let this = self.eval_context_mut();
187187

188-
let [place, rhs] = check_arg_count(args)?;
188+
let [place, rhs] = check_intrinsic_arg_count(args)?;
189189
let place = this.deref_pointer(place)?;
190190
let rhs = this.read_immediate(rhs)?;
191191

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

229-
let [place, new] = check_arg_count(args)?;
229+
let [place, new] = check_intrinsic_arg_count(args)?;
230230
let place = this.deref_pointer(place)?;
231231
let new = this.read_scalar(new)?;
232232

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

248-
let [place, expect_old, new] = check_arg_count(args)?;
248+
let [place, expect_old, new] = check_intrinsic_arg_count(args)?;
249249
let place = this.deref_pointer(place)?;
250250
let expect_old = this.read_immediate(expect_old)?; // read as immediate for the sake of `binary_op()`
251251
let new = this.read_scalar(new)?;

0 commit comments

Comments
 (0)