Skip to content

Commit 2606815

Browse files
committed
Auto merge of rust-lang#122953 - matthiaskrgr:rollup-rioxw1r, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#122379 (transmute: caution against int2ptr transmutation) - rust-lang#122895 (add some ice tests 5xxxx to 9xxxx) - rust-lang#122907 (Uniquify `ReError` on input mode in canonicalizer) - rust-lang#122942 (Add test in higher ranked subtype) - rust-lang#122943 (add a couple more ice tests) - rust-lang#122952 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 020bbe4 + 70b2185 commit 2606815

File tree

65 files changed

+1296
-130
lines changed

Some content is hidden

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

65 files changed

+1296
-130
lines changed

compiler/rustc_next_trait_solver/src/canonicalizer.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
239239
// FIXME: We should investigate the perf implications of not uniquifying
240240
// `ReErased`. We may be able to short-circuit registering region
241241
// obligations if we encounter a `ReErased` on one side, for example.
242-
ty::ReStatic | ty::ReErased => match self.canonicalize_mode {
242+
ty::ReStatic | ty::ReErased | ty::ReError(_) => match self.canonicalize_mode {
243243
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
244244
CanonicalizeMode::Response { .. } => return r,
245245
},
@@ -277,7 +277,6 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
277277
}
278278
}
279279
}
280-
ty::ReError(_) => return r,
281280
};
282281

283282
let existing_bound_var = match self.canonicalize_mode {

library/core/src/intrinsics.rs

+33-8
Original file line numberDiff line numberDiff line change
@@ -1164,14 +1164,6 @@ extern "rust-intrinsic" {
11641164
/// may lead to unexpected and unstable compilation results. This makes `transmute` **incredibly
11651165
/// unsafe**. `transmute` should be the absolute last resort.
11661166
///
1167-
/// Transmuting pointers *to* integers in a `const` context is [undefined behavior][ub],
1168-
/// unless the pointer was originally created *from* an integer.
1169-
/// (That includes this function specifically, integer-to-pointer casts, and helpers like [`invalid`][crate::ptr::dangling],
1170-
/// but also semantically-equivalent conversions such as punning through `repr(C)` union fields.)
1171-
/// Any attempt to use the resulting value for integer operations will abort const-evaluation.
1172-
/// (And even outside `const`, such transmutation is touching on many unspecified aspects of the
1173-
/// Rust memory model and should be avoided. See below for alternatives.)
1174-
///
11751167
/// Because `transmute` is a by-value operation, alignment of the *transmuted values
11761168
/// themselves* is not a concern. As with any other function, the compiler already ensures
11771169
/// both `Src` and `Dst` are properly aligned. However, when transmuting values that *point
@@ -1182,6 +1174,39 @@ extern "rust-intrinsic" {
11821174
///
11831175
/// [ub]: ../../reference/behavior-considered-undefined.html
11841176
///
1177+
/// # Transmutation between pointers and integers
1178+
///
1179+
/// Special care has to be taken when transmuting between pointers and integers, e.g.
1180+
/// transmuting between `*const ()` and `usize`.
1181+
///
1182+
/// Transmuting *pointers to integers* in a `const` context is [undefined behavior][ub], unless
1183+
/// the pointer was originally created *from* an integer. (That includes this function
1184+
/// specifically, integer-to-pointer casts, and helpers like [`dangling`][crate::ptr::dangling],
1185+
/// but also semantically-equivalent conversions such as punning through `repr(C)` union
1186+
/// fields.) Any attempt to use the resulting value for integer operations will abort
1187+
/// const-evaluation. (And even outside `const`, such transmutation is touching on many
1188+
/// unspecified aspects of the Rust memory model and should be avoided. See below for
1189+
/// alternatives.)
1190+
///
1191+
/// Transmuting *integers to pointers* is a largely unspecified operation. It is likely *not*
1192+
/// equivalent to an `as` cast. Doing non-zero-sized memory accesses with a pointer constructed
1193+
/// this way is currently considered undefined behavior.
1194+
///
1195+
/// All this also applies when the integer is nested inside an array, tuple, struct, or enum.
1196+
/// However, `MaybeUninit<usize>` is not considered an integer type for the purpose of this
1197+
/// section. Transmuting `*const ()` to `MaybeUninit<usize>` is fine---but then calling
1198+
/// `assume_init()` on that result is considered as completing the pointer-to-integer transmute
1199+
/// and thus runs into the issues discussed above.
1200+
///
1201+
/// In particular, doing a pointer-to-integer-to-pointer roundtrip via `transmute` is *not* a
1202+
/// lossless process. If you want to round-trip a pointer through an integer in a way that you
1203+
/// can get back the original pointer, you need to use `as` casts, or replace the integer type
1204+
/// by `MaybeUninit<$int>` (and never call `assume_init()`). If you are looking for a way to
1205+
/// store data of arbitrary type, also use `MaybeUninit<T>` (that will also handle uninitialized
1206+
/// memory due to padding). If you specifically need to store something that is "either an
1207+
/// integer or a pointer", use `*mut ()`: integers can be converted to pointers and back without
1208+
/// any loss (via `as` casts or via `transmute`).
1209+
///
11851210
/// # Examples
11861211
///
11871212
/// There are a few things that `transmute` is really useful for.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ jobs:
206206
run: |
207207
PR=$(gh pr create -B master --title 'Automatic Rustup' --body '')
208208
~/.local/bin/zulip-send --user $ZULIP_BOT_EMAIL --api-key $ZULIP_API_TOKEN --site https://rust-lang.zulipchat.com \
209-
--stream miri --subject "Cron Job Failure (miri, $(date -u +%Y-%m))" \
209+
--stream miri --subject "Miri Build Failure ($(date -u +%Y-%m))" \
210210
--message "A PR doing a rustc-pull [has been automatically created]($PR) for your convenience."
211211
env:
212212
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

src/tools/miri/bench-cargo-miri/invalidate/Cargo.lock src/tools/miri/bench-cargo-miri/range-iteration/Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
version = 3
44

55
[[package]]
6-
name = "invalidate"
6+
name = "range-iteration"
77
version = "0.1.0"

src/tools/miri/bench-cargo-miri/invalidate/Cargo.toml src/tools/miri/bench-cargo-miri/range-iteration/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "invalidate"
2+
name = "range-iteration"
33
version = "0.1.0"
44
edition = "2021"
55

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
//! This generates a lot of work for the AllocId part of the GC.
12
fn main() {
23
// The end of the range is just chosen to make the benchmark run for a few seconds.
3-
for _ in 0..200_000 {}
4+
for _ in 0..50_000 {}
45
}

src/tools/miri/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ee03c286cfdca26fa5b2a4ee40957625d2c826ff
1+
c3b05c6e5b5b59613350b8c2875b0add67ed74df

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

+20
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,26 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
179179
});
180180
}
181181
}
182+
183+
fn after_analysis<'tcx>(
184+
&mut self,
185+
_: &rustc_interface::interface::Compiler,
186+
queries: &'tcx rustc_interface::Queries<'tcx>,
187+
) -> Compilation {
188+
queries.global_ctxt().unwrap().enter(|tcx| {
189+
if self.target_crate {
190+
// cargo-miri has patched the compiler flags to make these into check-only builds,
191+
// but we are still emulating regular rustc builds, which would perform post-mono
192+
// const-eval during collection. So let's also do that here, even if we might be
193+
// running with `--emit=metadata`. In particular this is needed to make
194+
// `compile_fail` doc tests trigger post-mono errors.
195+
// In general `collect_and_partition_mono_items` is not safe to call in check-only
196+
// builds, but we are setting `-Zalways-encode-mir` which avoids those issues.
197+
let _ = tcx.collect_and_partition_mono_items(());
198+
}
199+
});
200+
Compilation::Continue
201+
}
182202
}
183203

184204
fn show_error(msg: &impl std::fmt::Display) -> ! {

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

+15-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::borrow_tracker::{
1818
stacked_borrows::diagnostics::{AllocHistory, DiagnosticCx, DiagnosticCxBuilder},
1919
GlobalStateInner, ProtectorKind,
2020
};
21+
use crate::concurrency::data_race::{NaReadType, NaWriteType};
2122
use crate::*;
2223

2324
use diagnostics::{RetagCause, RetagInfo};
@@ -751,7 +752,13 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
751752
assert_eq!(access, AccessKind::Write);
752753
// Make sure the data race model also knows about this.
753754
if let Some(data_race) = alloc_extra.data_race.as_mut() {
754-
data_race.write(alloc_id, range, machine)?;
755+
data_race.write(
756+
alloc_id,
757+
range,
758+
NaWriteType::Retag,
759+
Some(place.layout.ty),
760+
machine,
761+
)?;
755762
}
756763
}
757764
}
@@ -794,7 +801,13 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
794801
assert_eq!(access, AccessKind::Read);
795802
// Make sure the data race model also knows about this.
796803
if let Some(data_race) = alloc_extra.data_race.as_ref() {
797-
data_race.read(alloc_id, range, &this.machine)?;
804+
data_race.read(
805+
alloc_id,
806+
range,
807+
NaReadType::Retag,
808+
Some(place.layout.ty),
809+
&this.machine,
810+
)?;
798811
}
799812
}
800813
Ok(())

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ use rustc_middle::{
99
use rustc_span::def_id::DefId;
1010
use rustc_target::abi::{Abi, Size};
1111

12-
use crate::borrow_tracker::{GlobalState, GlobalStateInner, ProtectorKind};
1312
use crate::*;
13+
use crate::{
14+
borrow_tracker::{GlobalState, GlobalStateInner, ProtectorKind},
15+
concurrency::data_race::NaReadType,
16+
};
1417

1518
pub mod diagnostics;
1619
mod perms;
@@ -312,7 +315,13 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
312315
// Also inform the data race model (but only if any bytes are actually affected).
313316
if range.size.bytes() > 0 {
314317
if let Some(data_race) = alloc_extra.data_race.as_ref() {
315-
data_race.read(alloc_id, range, &this.machine)?;
318+
data_race.read(
319+
alloc_id,
320+
range,
321+
NaReadType::Retag,
322+
Some(place.layout.ty),
323+
&this.machine,
324+
)?;
316325
}
317326
}
318327

0 commit comments

Comments
 (0)