diff options
| author | Ralf Jung <post@ralfj.de> | 2024-03-09 13:05:13 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-03-09 13:08:55 +0100 |
| commit | e632e3f9a501daefde13a264e1d0aff54a417510 (patch) | |
| tree | 359398ad1caca9d7bba77599018ea1f0a284537b /compiler | |
| parent | 1b427b3bf79c2cd48c75915301be3b009b82dea3 (diff) | |
| download | rust-e632e3f9a501daefde13a264e1d0aff54a417510.tar.gz rust-e632e3f9a501daefde13a264e1d0aff54a417510.zip | |
miri: do not apply aliasing restrictions to Box with custom allocator
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/validity.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/visitor.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/intrinsic.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/sty.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_span/src/symbol.rs | 1 |
5 files changed, 18 insertions, 12 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index ff1cb43db86..c568f9acfd3 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -17,8 +17,8 @@ use rustc_middle::mir::interpret::{ ExpectedKind, InterpError, InvalidMetaKind, Misalignment, PointerKind, Provenance, ValidationErrorInfo, ValidationErrorKind, ValidationErrorKind::*, }; -use rustc_middle::ty; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; +use rustc_middle::ty::{self, Ty}; use rustc_span::symbol::{sym, Symbol}; use rustc_target::abi::{ Abi, FieldIdx, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange, @@ -783,7 +783,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> } #[inline] - fn visit_box(&mut self, op: &OpTy<'tcx, M::Provenance>) -> InterpResult<'tcx> { + fn visit_box( + &mut self, + _box_ty: Ty<'tcx>, + op: &OpTy<'tcx, M::Provenance>, + ) -> InterpResult<'tcx> { self.check_safe_pointer(op, PointerKind::Box)?; Ok(()) } diff --git a/compiler/rustc_const_eval/src/interpret/visitor.rs b/compiler/rustc_const_eval/src/interpret/visitor.rs index b200ecbf73a..0e824f3f592 100644 --- a/compiler/rustc_const_eval/src/interpret/visitor.rs +++ b/compiler/rustc_const_eval/src/interpret/visitor.rs @@ -3,7 +3,7 @@ use rustc_index::IndexVec; use rustc_middle::mir::interpret::InterpResult; -use rustc_middle::ty; +use rustc_middle::ty::{self, Ty}; use rustc_target::abi::FieldIdx; use rustc_target::abi::{FieldsShape, VariantIdx, Variants}; @@ -47,10 +47,10 @@ pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized { Ok(()) } /// Visits the given value as the pointer of a `Box`. There is nothing to recurse into. - /// The type of `v` will be a raw pointer, but this is a field of `Box<T>` and the - /// pointee type is the actual `T`. + /// The type of `v` will be a raw pointer to `T`, but this is a field of `Box<T>` and the + /// pointee type is the actual `T`. `box_ty` provides the full type of the `Box` itself. #[inline(always)] - fn visit_box(&mut self, _v: &Self::V) -> InterpResult<'tcx> { + fn visit_box(&mut self, _box_ty: Ty<'tcx>, _v: &Self::V) -> InterpResult<'tcx> { Ok(()) } @@ -144,7 +144,7 @@ pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized { assert_eq!(nonnull_ptr.layout().fields.count(), 1); let raw_ptr = self.ecx().project_field(&nonnull_ptr, 0)?; // the actual raw ptr // ... whose only field finally is a raw ptr we can dereference. - self.visit_box(&raw_ptr)?; + self.visit_box(ty, &raw_ptr)?; // The second `Box` field is the allocator, which we recursively check for validity // like in regular structs. diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 95c51cc0486..5a74bdc8a84 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -657,6 +657,10 @@ pub fn check_intrinsic_type( sym::simd_shuffle => (3, 0, vec![param(0), param(0), param(1)], param(2)), sym::simd_shuffle_generic => (2, 1, vec![param(0), param(0)], param(1)), + sym::retag_box_to_raw => { + (2, 0, vec![Ty::new_mut_ptr(tcx, param(0))], Ty::new_mut_ptr(tcx, param(0))) + } + other => { tcx.dcx().emit_err(UnrecognizedIntrinsicFunction { span, name: other }); return; diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 427c0f04bd1..39b5d3b6ea7 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -2008,13 +2008,10 @@ impl<'tcx> Ty<'tcx> { // Single-argument Box is always global. (for "minicore" tests) return true; }; - if let Some(alloc_adt) = alloc.expect_ty().ty_adt_def() { + alloc.expect_ty().ty_adt_def().is_some_and(|alloc_adt| { let global_alloc = tcx.require_lang_item(LangItem::GlobalAlloc, None); alloc_adt.did() == global_alloc - } else { - // Allocator is not an ADT... - false - } + }) } _ => false, } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 9dadd471247..283c685eaa3 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1450,6 +1450,7 @@ symbols! { residual, result, resume, + retag_box_to_raw, return_position_impl_trait_in_trait, return_type_notation, rhs, |
