Merge from rustc

This commit is contained in:
The Miri Cronjob Bot 2025-04-19 04:59:50 +00:00
commit 9726e6b468
127 changed files with 2457 additions and 643 deletions

View file

@ -179,7 +179,7 @@ fn find_first_mismatch(cx: &LateContext<'_>, pat: &Pat<'_>) -> Option<(Span, Mut
};
if let Some(adjustments) = cx.typeck_results().pat_adjustments().get(adjust_pat.hir_id) {
if let [first, ..] = **adjustments {
if let ty::Ref(.., mutability) = *first.kind() {
if let ty::Ref(.., mutability) = *first.source.kind() {
let level = if p.hir_id == pat.hir_id {
Level::Top
} else {

View file

@ -2363,14 +2363,14 @@ pub fn is_no_std_crate(cx: &LateContext<'_>) -> bool {
cx.tcx
.hir_attrs(hir::CRATE_HIR_ID)
.iter()
.any(|attr| attr.name_or_empty() == sym::no_std)
.any(|attr| attr.has_name(sym::no_std))
}
pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool {
cx.tcx
.hir_attrs(hir::CRATE_HIR_ID)
.iter()
.any(|attr| attr.name_or_empty() == sym::no_core)
.any(|attr| attr.has_name(sym::no_core))
}
/// Check if parent of a hir node is a trait implementation block.

View file

@ -178,6 +178,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"only-32bit",
"only-64bit",
"only-aarch64",
"only-aarch64-apple-darwin",
"only-aarch64-unknown-linux-gnu",
"only-apple",
"only-arm",
@ -191,6 +192,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"only-gnu",
"only-i686-pc-windows-gnu",
"only-i686-pc-windows-msvc",
"only-i686-unknown-linux-gnu",
"only-ios",
"only-linux",
"only-loongarch64",
@ -222,6 +224,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"only-windows-msvc",
"only-x86",
"only-x86_64",
"only-x86_64-apple-darwin",
"only-x86_64-fortanix-unknown-sgx",
"only-x86_64-pc-windows-gnu",
"only-x86_64-pc-windows-msvc",

View file

@ -156,7 +156,7 @@ static LINE_PATTERN: LazyLock<Regex> = LazyLock::new(|| {
r#"
//@\s+
(?P<negated>!?)
(?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*)
(?P<cmd>[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)
(?P<args>.*)$
"#,
)

View file

@ -42,6 +42,7 @@ fn errors_on_missing_links() {
)]),
paths: FxHashMap::default(),
external_crates: FxHashMap::default(),
target: rustdoc_json_types::Target { triple: "".to_string(), target_features: vec![] },
format_version: rustdoc_json_types::FORMAT_VERSION,
};
@ -112,6 +113,7 @@ fn errors_on_local_in_paths_and_not_index() {
},
)]),
external_crates: FxHashMap::default(),
target: rustdoc_json_types::Target { triple: "".to_string(), target_features: vec![] },
format_version: rustdoc_json_types::FORMAT_VERSION,
};
@ -216,6 +218,7 @@ fn errors_on_missing_path() {
ItemSummary { crate_id: 0, path: vec!["foo".to_owned()], kind: ItemKind::Module },
)]),
external_crates: FxHashMap::default(),
target: rustdoc_json_types::Target { triple: "".to_string(), target_features: vec![] },
format_version: rustdoc_json_types::FORMAT_VERSION,
};
@ -259,6 +262,7 @@ fn checks_local_crate_id_is_correct() {
)]),
paths: FxHashMap::default(),
external_crates: FxHashMap::default(),
target: rustdoc_json_types::Target { triple: "".to_string(), target_features: vec![] },
format_version: FORMAT_VERSION,
};
check(&krate, &[]);

View file

@ -0,0 +1,45 @@
//@compile-flags: -Zmiri-preemption-rate=0 -Zmiri-compare-exchange-weak-failure-rate=0
use std::sync::mpsc::channel;
use std::thread;
/// This test aims to trigger a race condition that causes a double free in the unbounded channel
/// implementation. The test relies on a particular thread scheduling to happen as annotated by the
/// comments below.
fn main() {
let (s1, r) = channel::<u64>();
let s2 = s1.clone();
let t1 = thread::spawn(move || {
// 1. The first action executed is an attempt to send the first value in the channel. This
// will begin to initialize the channel but will stop at a critical momement as
// indicated by the `yield_now()` call in the `start_send` method of the implementation.
let _ = s1.send(42);
// 4. The sender is re-scheduled and it finishes the initialization of the channel by
// setting head.block to the same value as tail.block. It then proceeds to publish its
// value but observes that the channel has already disconnected (due to the concurrent
// call of `discard_all_messages`) and aborts the send.
});
std::thread::yield_now();
// 2. A second sender attempts to send a value while the channel is in a half-initialized
// state. Here, half-initialized means that the `tail.block` pointer points to a valid block
// but `head.block` is still null. This condition is ensured by the yield of step 1. When
// this call returns the channel state has tail.index != head.index, tail.block != NULL, and
// head.block = NULL.
s2.send(42).unwrap();
// 3. This thread continues with dropping the one and only receiver. When all receivers are
// gone `discard_all_messages` will attempt to drop all currently sent values and
// de-allocate all the blocks. If `tail.block != NULL` but `head.block = NULL` the
// implementation waits for the initializing sender to finish by spinning/yielding.
drop(r);
// 5. This thread is rescheduled and `discard_all_messages` observes the head.block pointer set
// by step 4 and proceeds with deallocation. In the problematic version of the code
// `head.block` is simply read via an `Acquire` load and not swapped with NULL. After this
// call returns the channel state has tail.index = head.index, tail.block = NULL, and
// head.block != NULL.
t1.join().unwrap();
// 6. The last sender (s2) is dropped here which also attempts to cleanup any data in the
// channel. It observes `tail.index = head.index` and so it doesn't attempt to cleanup any
// messages but it also observes that `head.block != NULL` and attempts to deallocate it.
// This is however already deallocated by `discard_all_messages`, leading to a double free.
}