Skip to content

Commit 9e973d8

Browse files
committed
Auto merge of #153911 - Zalathar:rollup-BFEZ6Th, r=Zalathar
Rollup of 2 pull requests Successful merges: - #153909 (miri subtree update) - #153896 ([tiny] Tweak "use of `Deref`" suggestion message)
2 parents 79d2026 + 627f513 commit 9e973d8

45 files changed

Lines changed: 1864 additions & 470 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
392392
{
393393
err.span_suggestion_verbose(
394394
span,
395-
"consider dereferencing to access the inner value using the Deref trait",
395+
"consider dereferencing to access the inner value using the `Deref` trait",
396396
format!("{prefix}{peeled_snippet}"),
397397
Applicability::MaybeIncorrect,
398398
);

src/tools/miri/README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ platform. For example `cargo miri test --target s390x-unknown-linux-gnu`
154154
will run your test suite on a big-endian target, which is useful for testing
155155
endian-sensitive code.
156156

157+
### Controlling target features
158+
159+
Controlling target features works similar to regular rustc invocations:
160+
`RUSTFLAGS="-Ctarget-features=+avx512f" cargo miri test` runs the tests with AVX512 enabled. (Miri
161+
only supports very few AVX512 intrinsics at the moment.) `-Ctarget-cpu` also works. If target
162+
features are also relevant for doctests, you have to also set `RUSTDOCFLAGS`.
163+
164+
Unlike regular rustc, this flag has *two* effects: it builds the code with that target feature
165+
available (which affects `cfg(target_feature)`), and it tells Miri to consider the "virtual CPU"
166+
that the interpreted program runs on as having the feature available (meaning the code is allowed to
167+
invoke the corresponding intrinsics).
168+
157169
### Testing multiple different executions
158170

159171
Certain parts of the execution are picked randomly by Miri, such as the exact base address
@@ -421,10 +433,11 @@ to Miri failing to detect cases of undefined behavior in a program.
421433
are experimental). Later flags take precedence: borrow tracking can be reactivated
422434
by `-Zmiri-tree-borrows`.
423435
* `-Zmiri-disable-validation` disables enforcing validity invariants, which are
424-
enforced by default. This is mostly useful to focus on other failures (such
425-
as out-of-bounds accesses) first. Setting this flag means Miri can miss bugs
426-
in your program. However, this can also help to make Miri run faster. Using
427-
this flag is **unsound**.
436+
enforced by default. This only disables these checks for typed copies; using
437+
invalid values in any other operation will still cause an error. This is mostly useful
438+
to focus on other failures (such as out-of-bounds accesses) first. Setting this
439+
flag means Miri can miss bugs in your program. However, this can also help to
440+
make Miri run faster. Using this flag is **unsound**.
428441
* `-Zmiri-disable-weak-memory-emulation` disables the emulation of some C++11 weak
429442
memory effects.
430443
* `-Zmiri-fixed-schedule` disables preemption (like `-Zmiri-preemption-rate=0.0`) and furthermore

src/tools/miri/rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d933cf483edf1605142ac6899ff32536c0ad8b22
1+
d1ee5e59a964a419b84b760812a35075034f4861

src/tools/miri/src/alloc/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod alloc_bytes;
2-
#[cfg(all(unix, feature = "native-lib"))]
2+
#[cfg(all(feature = "native-lib", unix))]
33
pub mod isolated_alloc;
4-
#[cfg(not(all(unix, feature = "native-lib")))]
4+
#[cfg(not(all(feature = "native-lib", unix)))]
55
pub mod isolated_alloc {
66
use std::alloc::Layout;
77

src/tools/miri/src/alloc_addresses/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
163163
this.get_alloc_bytes_unchecked_raw(alloc_id)?
164164
}
165165
}
166-
#[cfg(all(unix, feature = "native-lib"))]
166+
#[cfg(all(feature = "native-lib", unix))]
167167
AllocKind::Function => {
168168
if let Some(GlobalAlloc::Function { instance, .. }) =
169169
this.tcx.try_get_global_alloc(alloc_id)
@@ -186,7 +186,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
186186
dummy_alloc(params)
187187
}
188188
}
189-
#[cfg(not(all(unix, feature = "native-lib")))]
189+
#[cfg(not(all(feature = "native-lib", unix)))]
190190
AllocKind::Function => dummy_alloc(params),
191191
AllocKind::VTable | AllocKind::VaList => dummy_alloc(params),
192192
AllocKind::TypeId | AllocKind::Dead => unreachable!(),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ fn exit(exit_code: i32) -> ! {
382382
// Drop the tracing guard before exiting, so tracing calls are flushed correctly.
383383
deinit_loggers();
384384
// Make sure the supervisor knows about the exit code.
385-
#[cfg(all(unix, feature = "native-lib"))]
385+
#[cfg(all(feature = "native-lib", unix))]
386386
miri::native_lib::register_retcode_sv(exit_code);
387387
// Actually exit.
388388
std::process::exit(exit_code);
@@ -756,7 +756,7 @@ fn main() -> ExitCode {
756756
debug!("crate arguments: {:?}", miri_config.args);
757757
if !miri_config.native_lib.is_empty() && miri_config.native_lib_enable_tracing {
758758
// SAFETY: No other threads are running
759-
#[cfg(all(unix, feature = "native-lib"))]
759+
#[cfg(all(feature = "native-lib", unix))]
760760
if unsafe { miri::native_lib::init_sv() }.is_err() {
761761
eprintln!(
762762
"warning: The native-lib tracer could not be started. Is this an x86 Linux system, and does Miri have permissions to ptrace?\n\

src/tools/miri/src/borrow_tracker/tree_borrows/wildcard.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ impl WildcardAccessRelatedness {
5050
}
5151
}
5252

53-
/// Caches information about where in the tree exposed nodes with permission to do reads/ rites are
54-
/// located. [`ExposedCache`] stores this information a single location (or rather, a range of
53+
/// Caches information about where in the tree exposed nodes with permission to do reads/writes are
54+
/// located. [`ExposedCache`] stores this information for a single location (or rather, a range of
5555
/// homogeneous locations) for all nodes in an allocation.
5656
///
5757
/// Nodes not in this map have a default [`ExposedCacheNode`], i.e. they have no exposed children.

src/tools/miri/src/diagnostics.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ pub enum NonHaltingDiagnostic {
141141
effective_failure_ordering: AtomicReadOrd,
142142
},
143143
FileInProcOpened,
144+
SocketListenUnsupportedBacklog {
145+
details: bool,
146+
/// Unsupported backlog value provided the by the program.
147+
provided: i32,
148+
/// Supported backlog value by Miri.
149+
supported: i32,
150+
},
144151
}
145152

146153
/// Level of Miri specific diagnostics
@@ -643,6 +650,8 @@ impl<'tcx> MiriMachine<'tcx> {
643650
| WeakMemoryOutdatedLoad { .. } =>
644651
("tracking was triggered here".to_string(), DiagLevel::Note),
645652
FileInProcOpened => ("open a file in `/proc`".to_string(), DiagLevel::Warning),
653+
SocketListenUnsupportedBacklog { .. } =>
654+
("call to `listen` with unsupported backlog value".to_string(), DiagLevel::Warning),
646655
};
647656

648657
let title = match &e {
@@ -690,13 +699,18 @@ impl<'tcx> MiriMachine<'tcx> {
690699
};
691700
format!("GenMC currently does not model the failure ordering for `compare_exchange`. {was_upgraded_msg}. Miri with GenMC might miss bugs related to this memory access.")
692701
}
693-
FileInProcOpened => format!("files in `/proc` can bypass the Abstract Machine and might not work properly in Miri")
702+
FileInProcOpened => format!("files in `/proc` can bypass the Abstract Machine and might not work properly in Miri"),
703+
SocketListenUnsupportedBacklog { provided, supported, .. } => format!("called `listen` on socket with backlog value of {provided} but only {supported} is supported"),
694704
};
695705

696706
let notes = match &e {
697707
ProgressReport { block_count } => {
698708
vec![note!("so far, {block_count} basic blocks have been executed")]
699709
}
710+
SocketListenUnsupportedBacklog { details: true, supported, .. } =>
711+
vec![note!(
712+
"the given value will be ignored and a backlog of {supported} will be used instead"
713+
)],
700714
_ => vec![],
701715
};
702716

src/tools/miri/src/helpers.rs

Lines changed: 11 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::{cmp, iter};
55

66
use rand::RngCore;
77
use rustc_abi::{Align, ExternAbi, FieldIdx, FieldsShape, Size, Variants};
8-
use rustc_apfloat::Float;
98
use rustc_data_structures::fx::{FxBuildHasher, FxHashSet};
109
use rustc_hir::Safety;
1110
use rustc_hir::def::{DefKind, Namespace};
@@ -165,50 +164,6 @@ pub fn iter_exported_symbols<'tcx>(
165164
interp_ok(())
166165
}
167166

168-
/// Convert a softfloat type to its corresponding hostfloat type.
169-
pub trait ToHost {
170-
type HostFloat;
171-
fn to_host(self) -> Self::HostFloat;
172-
}
173-
174-
/// Convert a hostfloat type to its corresponding softfloat type.
175-
pub trait ToSoft {
176-
type SoftFloat;
177-
fn to_soft(self) -> Self::SoftFloat;
178-
}
179-
180-
impl ToHost for rustc_apfloat::ieee::Double {
181-
type HostFloat = f64;
182-
183-
fn to_host(self) -> Self::HostFloat {
184-
f64::from_bits(self.to_bits().try_into().unwrap())
185-
}
186-
}
187-
188-
impl ToSoft for f64 {
189-
type SoftFloat = rustc_apfloat::ieee::Double;
190-
191-
fn to_soft(self) -> Self::SoftFloat {
192-
Float::from_bits(self.to_bits().into())
193-
}
194-
}
195-
196-
impl ToHost for rustc_apfloat::ieee::Single {
197-
type HostFloat = f32;
198-
199-
fn to_host(self) -> Self::HostFloat {
200-
f32::from_bits(self.to_bits().try_into().unwrap())
201-
}
202-
}
203-
204-
impl ToSoft for f32 {
205-
type SoftFloat = rustc_apfloat::ieee::Single;
206-
207-
fn to_soft(self) -> Self::SoftFloat {
208-
Float::from_bits(self.to_bits().into())
209-
}
210-
}
211-
212167
impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
213168
pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
214169
/// Checks if the given crate/module exists.
@@ -774,19 +729,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
774729
let nanoseconds_scalar = this.read_scalar(&nanoseconds_place)?;
775730
let nanoseconds = nanoseconds_scalar.to_target_isize(this)?;
776731

777-
interp_ok(
778-
try {
779-
// tv_sec must be non-negative.
780-
let seconds: u64 = seconds.try_into().ok()?;
781-
// tv_nsec must be non-negative.
782-
let nanoseconds: u32 = nanoseconds.try_into().ok()?;
783-
if nanoseconds >= 1_000_000_000 {
784-
// tv_nsec must not be greater than 999,999,999.
785-
None?
786-
}
787-
Duration::new(seconds, nanoseconds)
788-
},
789-
)
732+
interp_ok(try {
733+
// tv_sec must be non-negative.
734+
let seconds: u64 = seconds.try_into().ok()?;
735+
// tv_nsec must be non-negative.
736+
let nanoseconds: u32 = nanoseconds.try_into().ok()?;
737+
if nanoseconds >= 1_000_000_000 {
738+
// tv_nsec must not be greater than 999,999,999.
739+
None?
740+
}
741+
Duration::new(seconds, nanoseconds)
742+
})
790743
}
791744

792745
/// Read bytes from a byte slice.

0 commit comments

Comments
 (0)