CTFE: move target_{i, u}size_{min, max)
to rustc_abi::TargetDataLayout
This commit is contained in:
parent
bf2f8ff2ec
commit
39cfe70e4f
8 changed files with 37 additions and 49 deletions
|
@ -1,7 +1,6 @@
|
|||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::{LangItem, CRATE_HIR_ID};
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::mir::interpret::PointerArithmetic;
|
||||
use rustc_middle::ty::layout::{FnAbiOf, TyAndLayout};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_session::lint::builtin::INVALID_ALIGNMENT;
|
||||
|
@ -17,7 +16,7 @@ use rustc_ast::Mutability;
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::mir::AssertMessage;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_target::abi::{Align, Size};
|
||||
use rustc_target::abi::{Align, HasDataLayout as _, Size};
|
||||
use rustc_target::spec::abi::Abi as CallAbi;
|
||||
|
||||
use crate::errors::{LongRunning, LongRunningWarn};
|
||||
|
@ -304,8 +303,8 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
|
|||
Ok(ControlFlow::Break(()))
|
||||
} else {
|
||||
// Not alignable in const, return `usize::MAX`.
|
||||
let usize_max = Scalar::from_target_usize(self.target_usize_max(), self);
|
||||
self.write_scalar(usize_max, dest)?;
|
||||
let usize_max = self.data_layout().target_usize_max();
|
||||
self.write_scalar(Scalar::from_target_usize(usize_max, self), dest)?;
|
||||
self.return_to_block(ret)?;
|
||||
Ok(ControlFlow::Break(()))
|
||||
}
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::mir::{
|
||||
self,
|
||||
interpret::{
|
||||
Allocation, ConstAllocation, ConstValue, GlobalId, InterpResult, PointerArithmetic, Scalar,
|
||||
},
|
||||
interpret::{Allocation, ConstAllocation, ConstValue, GlobalId, InterpResult, Scalar},
|
||||
BinOp, NonDivergingIntrinsic,
|
||||
};
|
||||
use rustc_middle::ty;
|
||||
|
@ -15,7 +13,7 @@ use rustc_middle::ty::layout::{LayoutOf as _, ValidityRequirement};
|
|||
use rustc_middle::ty::GenericArgsRef;
|
||||
use rustc_middle::ty::{Ty, TyCtxt};
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_target::abi::{Abi, Align, Primitive, Size};
|
||||
use rustc_target::abi::{Abi, Align, HasDataLayout as _, Primitive, Size};
|
||||
|
||||
use super::{
|
||||
util::ensure_monomorphic_enough, CheckInAllocMsg, ImmTy, InterpCx, Machine, OpTy, PlaceTy,
|
||||
|
@ -361,11 +359,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
)?;
|
||||
|
||||
// Perform division by size to compute return value.
|
||||
let dl = self.data_layout();
|
||||
let ret_layout = if intrinsic_name == sym::ptr_offset_from_unsigned {
|
||||
assert!(0 <= dist && dist <= self.target_isize_max());
|
||||
assert!(0 <= dist && dist <= dl.target_isize_max());
|
||||
usize_layout
|
||||
} else {
|
||||
assert!(self.target_isize_min() <= dist && dist <= self.target_isize_max());
|
||||
assert!(dl.target_isize_min() <= dist && dist <= dl.target_isize_max());
|
||||
isize_layout
|
||||
};
|
||||
let pointee_layout = self.layout_of(instance_args.type_at(0))?;
|
||||
|
|
|
@ -1244,7 +1244,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
if offset > size.bytes() {
|
||||
// If the pointer is out-of-bounds, we do not have a
|
||||
// meaningful range to return.
|
||||
0..=dl.max_address()
|
||||
0..=dl.target_usize_max()
|
||||
} else {
|
||||
let (min, max) = dl.address_range_for(size, align);
|
||||
(min + offset)..=(max + offset)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue