Skip to content

Commit 5ca3ad8

Browse files
committed
Auto merge of #122690 - matthiaskrgr:rollup-43fggl0, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #122480 (Avoid various uses of `Option<Span>` in favor of using `DUMMY_SP` in the few cases that used `None`) - #122567 (Remove fixme about LLVM basic block naming) - #122588 (less useless filter calls in imported_source_file) - #122647 (add_retag: ensure box-to-raw-ptr casts are preserved for Miri) - #122649 (Update the minimum external LLVM to 17) - #122680 (Do not eat nested expressions' results in `MayContainYieldPoint` format args visitor) - #122683 (add missing test: expected paren or brace in macro) - #122689 (Add missing `try_visit` calls in visitors.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 38ca6d6 + c34e9f0 commit 5ca3ad8

File tree

8 files changed

+16
-68
lines changed

8 files changed

+16
-68
lines changed

src/borrow_tracker/mod.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::num::NonZero;
55
use smallvec::SmallVec;
66

77
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
8-
use rustc_middle::{mir::RetagKind, ty::Ty};
8+
use rustc_middle::mir::RetagKind;
99
use rustc_target::abi::Size;
1010

1111
use crate::*;
@@ -291,19 +291,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
291291
}
292292
}
293293

294-
fn retag_box_to_raw(
295-
&mut self,
296-
val: &ImmTy<'tcx, Provenance>,
297-
alloc_ty: Ty<'tcx>,
298-
) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> {
299-
let this = self.eval_context_mut();
300-
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
301-
match method {
302-
BorrowTrackerMethod::StackedBorrows => this.sb_retag_box_to_raw(val, alloc_ty),
303-
BorrowTrackerMethod::TreeBorrows => this.tb_retag_box_to_raw(val, alloc_ty),
304-
}
305-
}
306-
307294
fn retag_place_contents(
308295
&mut self,
309296
kind: RetagKind,

src/borrow_tracker/stacked_borrows/mod.rs

+10-28
Original file line numberDiff line numberDiff line change
@@ -865,24 +865,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
865865
this.sb_retag_reference(val, new_perm, RetagInfo { cause, in_field: false })
866866
}
867867

868-
fn sb_retag_box_to_raw(
869-
&mut self,
870-
val: &ImmTy<'tcx, Provenance>,
871-
alloc_ty: Ty<'tcx>,
872-
) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> {
873-
let this = self.eval_context_mut();
874-
let is_global_alloc = alloc_ty.ty_adt_def().is_some_and(|adt| {
875-
let global_alloc = this.tcx.require_lang_item(rustc_hir::LangItem::GlobalAlloc, None);
876-
adt.did() == global_alloc
877-
});
878-
if is_global_alloc {
879-
// Retag this as-if it was a mutable reference.
880-
this.sb_retag_ptr_value(RetagKind::Raw, val)
881-
} else {
882-
Ok(val.clone())
883-
}
884-
}
885-
886868
fn sb_retag_place_contents(
887869
&mut self,
888870
kind: RetagKind,
@@ -891,9 +873,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
891873
let this = self.eval_context_mut();
892874
let retag_fields = this.machine.borrow_tracker.as_mut().unwrap().get_mut().retag_fields;
893875
let retag_cause = match kind {
894-
RetagKind::Raw | RetagKind::TwoPhase { .. } => unreachable!(), // these can only happen in `retag_ptr_value`
876+
RetagKind::TwoPhase { .. } => unreachable!(), // can only happen in `retag_ptr_value`
895877
RetagKind::FnEntry => RetagCause::FnEntry,
896-
RetagKind::Default => RetagCause::Normal,
878+
RetagKind::Default | RetagKind::Raw => RetagCause::Normal,
897879
};
898880
let mut visitor =
899881
RetagVisitor { ecx: this, kind, retag_cause, retag_fields, in_field: false };
@@ -959,14 +941,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
959941

960942
// Check the type of this value to see what to do with it (retag, or recurse).
961943
match place.layout.ty.kind() {
962-
ty::Ref(..) => {
963-
let new_perm =
964-
NewPermission::from_ref_ty(place.layout.ty, self.kind, self.ecx);
965-
self.retag_ptr_inplace(place, new_perm)?;
966-
}
967-
ty::RawPtr(..) => {
968-
// We do *not* want to recurse into raw pointers -- wide raw pointers have
969-
// fields, and for dyn Trait pointees those can have reference type!
944+
ty::Ref(..) | ty::RawPtr(..) => {
945+
if matches!(place.layout.ty.kind(), ty::Ref(..))
946+
|| self.kind == RetagKind::Raw
947+
{
948+
let new_perm =
949+
NewPermission::from_ref_ty(place.layout.ty, self.kind, self.ecx);
950+
self.retag_ptr_inplace(place, new_perm)?;
951+
}
970952
}
971953
ty::Adt(adt, _) if adt.is_box() => {
972954
// Recurse for boxes, they require some tricky handling and will end up in `visit_box` above.

src/borrow_tracker/tree_borrows/mod.rs

-9
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
392392
}
393393
}
394394

395-
fn tb_retag_box_to_raw(
396-
&mut self,
397-
val: &ImmTy<'tcx, Provenance>,
398-
_alloc_ty: Ty<'tcx>,
399-
) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> {
400-
// Casts to raw pointers are NOPs in Tree Borrows.
401-
Ok(val.clone())
402-
}
403-
404395
/// Retag all pointers that are stored in this place.
405396
fn tb_retag_place_contents(
406397
&mut self,

src/machine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1503,15 +1503,15 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
15031503
fn eval_mir_constant<F>(
15041504
ecx: &InterpCx<'mir, 'tcx, Self>,
15051505
val: mir::Const<'tcx>,
1506-
span: Option<Span>,
1506+
span: Span,
15071507
layout: Option<TyAndLayout<'tcx>>,
15081508
eval: F,
15091509
) -> InterpResult<'tcx, OpTy<'tcx, Self::Provenance>>
15101510
where
15111511
F: Fn(
15121512
&InterpCx<'mir, 'tcx, Self>,
15131513
mir::Const<'tcx>,
1514-
Option<Span>,
1514+
Span,
15151515
Option<TyAndLayout<'tcx>>,
15161516
) -> InterpResult<'tcx, OpTy<'tcx, Self::Provenance>>,
15171517
{

src/shims/intrinsics/mod.rs

-12
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
140140

141141
this.write_pointer(Pointer::new(ptr.provenance, masked_addr), dest)?;
142142
}
143-
"retag_box_to_raw" => {
144-
let [ptr] = check_arg_count(args)?;
145-
let alloc_ty = generic_args[1].expect_ty();
146-
147-
let val = this.read_immediate(ptr)?;
148-
let new_val = if this.machine.borrow_tracker.is_some() {
149-
this.retag_box_to_raw(&val, alloc_ty)?
150-
} else {
151-
val
152-
};
153-
this.write_immediate(*new_val, dest)?;
154-
}
155143

156144
// We want to return either `true` or `false` at random, or else something like
157145
// ```

src/shims/intrinsics/simd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
549549

550550
let index = generic_args[2]
551551
.expect_const()
552-
.eval(*this.tcx, this.param_env(), Some(this.tcx.span))
552+
.eval(*this.tcx, this.param_env(), this.tcx.span)
553553
.unwrap()
554554
.unwrap_branch();
555555
let index_len = index.len();

tests/fail/both_borrows/newtype_pair_retagging.stack.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
9-
help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
9+
help: <TAG> was created by a Unique retag at offsets [0x0..0x4]
1010
--> $DIR/newtype_pair_retagging.rs:LL:CC
1111
|
1212
LL | let ptr = Box::into_raw(Box::new(0i32));

tests/fail/both_borrows/newtype_retagging.stack.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
9-
help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
9+
help: <TAG> was created by a Unique retag at offsets [0x0..0x4]
1010
--> $DIR/newtype_retagging.rs:LL:CC
1111
|
1212
LL | let ptr = Box::into_raw(Box::new(0i32));

0 commit comments

Comments
 (0)