mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Auto merge of #128504 - matthiaskrgr:rollup-pawylnk, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #127490 (Add target page for riscv64gc-unknown-linux-gnu) - #128433 (fix(hermit): `deny(unsafe_op_in_unsafe_fn)`) - #128482 (interpret: on a signed deref check, mention the right pointer in the error) - #128496 (Fix removed `box_syntax` diagnostic if source isn't available) - #128497 (fix dropck documentation for `[T;0]` special-case) - #128499 (chore: refactor backtrace formatting) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
a886938671
@ -516,7 +516,7 @@ impl Size {
|
|||||||
/// Truncates `value` to `self` bits and then sign-extends it to 128 bits
|
/// Truncates `value` to `self` bits and then sign-extends it to 128 bits
|
||||||
/// (i.e., if it is negative, fill with 1's on the left).
|
/// (i.e., if it is negative, fill with 1's on the left).
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn sign_extend(self, value: u128) -> u128 {
|
pub fn sign_extend(self, value: u128) -> i128 {
|
||||||
let size = self.bits();
|
let size = self.bits();
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
// Truncated until nothing is left.
|
// Truncated until nothing is left.
|
||||||
@ -526,7 +526,7 @@ impl Size {
|
|||||||
let shift = 128 - size;
|
let shift = 128 - size;
|
||||||
// Shift the unsigned value to the left, then shift back to the right as signed
|
// Shift the unsigned value to the left, then shift back to the right as signed
|
||||||
// (essentially fills with sign bit on the left).
|
// (essentially fills with sign bit on the left).
|
||||||
(((value << shift) as i128) >> shift) as u128
|
((value << shift) as i128) >> shift
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Truncates `value` to `self` bits.
|
/// Truncates `value` to `self` bits.
|
||||||
@ -544,7 +544,7 @@ impl Size {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn signed_int_min(&self) -> i128 {
|
pub fn signed_int_min(&self) -> i128 {
|
||||||
self.sign_extend(1_u128 << (self.bits() - 1)) as i128
|
self.sign_extend(1_u128 << (self.bits() - 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -88,10 +88,18 @@ const_eval_exact_div_has_remainder =
|
|||||||
exact_div: {$a} cannot be divided by {$b} without remainder
|
exact_div: {$a} cannot be divided by {$b} without remainder
|
||||||
|
|
||||||
const_eval_expected_inbounds_pointer =
|
const_eval_expected_inbounds_pointer =
|
||||||
expected {$inbounds_size ->
|
expected a pointer to {$inbounds_size_abs ->
|
||||||
[0] a pointer to some allocation
|
[0] some allocation
|
||||||
[1] a pointer to 1 byte of memory
|
*[x] {$inbounds_size_is_neg ->
|
||||||
*[x] a pointer to {$inbounds_size} bytes of memory
|
[false] {$inbounds_size_abs ->
|
||||||
|
[1] 1 byte of memory
|
||||||
|
*[x] {$inbounds_size_abs} bytes of memory
|
||||||
|
}
|
||||||
|
*[true] the end of {$inbounds_size_abs ->
|
||||||
|
[1] 1 byte of memory
|
||||||
|
*[x] {$inbounds_size_abs} bytes of memory
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const_eval_extern_static =
|
const_eval_extern_static =
|
||||||
@ -243,7 +251,7 @@ const_eval_offset_from_different_allocations =
|
|||||||
const_eval_offset_from_overflow =
|
const_eval_offset_from_overflow =
|
||||||
`{$name}` called when first pointer is too far ahead of second
|
`{$name}` called when first pointer is too far ahead of second
|
||||||
const_eval_offset_from_test =
|
const_eval_offset_from_test =
|
||||||
out-of-bounds `offset_from`
|
out-of-bounds `offset_from` origin
|
||||||
const_eval_offset_from_underflow =
|
const_eval_offset_from_underflow =
|
||||||
`{$name}` called when first pointer is too far before second
|
`{$name}` called when first pointer is too far before second
|
||||||
const_eval_offset_from_unsigned_overflow =
|
const_eval_offset_from_unsigned_overflow =
|
||||||
@ -269,17 +277,24 @@ const_eval_partial_pointer_copy =
|
|||||||
const_eval_partial_pointer_overwrite =
|
const_eval_partial_pointer_overwrite =
|
||||||
unable to overwrite parts of a pointer in memory at {$ptr}
|
unable to overwrite parts of a pointer in memory at {$ptr}
|
||||||
const_eval_pointer_arithmetic_overflow =
|
const_eval_pointer_arithmetic_overflow =
|
||||||
overflowing in-bounds pointer arithmetic
|
overflowing pointer arithmetic: the total offset in bytes does not fit in an `isize`
|
||||||
const_eval_pointer_arithmetic_test = out-of-bounds pointer arithmetic
|
const_eval_pointer_arithmetic_test = out-of-bounds pointer arithmetic
|
||||||
const_eval_pointer_out_of_bounds =
|
const_eval_pointer_out_of_bounds =
|
||||||
{$bad_pointer_message}: {const_eval_expected_inbounds_pointer}, but got {$pointer} {$ptr_offset_is_neg ->
|
{$bad_pointer_message}: {const_eval_expected_inbounds_pointer}, but got {$pointer} {$ptr_offset_is_neg ->
|
||||||
[true] which points to before the beginning of the allocation
|
[true] which points to before the beginning of the allocation
|
||||||
*[false] {$alloc_size_minus_ptr_offset ->
|
*[false] {$inbounds_size_is_neg ->
|
||||||
[0] which is at or beyond the end of the allocation of size {$alloc_size ->
|
[true] {$ptr_offset_abs ->
|
||||||
[1] 1 byte
|
[0] which is at the beginning of the allocation
|
||||||
*[x] {$alloc_size} bytes
|
*[other] which does not have enough space to the beginning of the allocation
|
||||||
|
}
|
||||||
|
*[false] {$alloc_size_minus_ptr_offset ->
|
||||||
|
[0] which is at or beyond the end of the allocation of size {$alloc_size ->
|
||||||
|
[1] 1 byte
|
||||||
|
*[x] {$alloc_size} bytes
|
||||||
|
}
|
||||||
|
[1] which is only 1 byte from the end of the allocation
|
||||||
|
*[x] which is only {$alloc_size_minus_ptr_offset} bytes from the end of the allocation
|
||||||
}
|
}
|
||||||
*[x] and there are only {$alloc_size_minus_ptr_offset} bytes starting at that pointer
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const_eval_pointer_use_after_free =
|
const_eval_pointer_use_after_free =
|
||||||
|
@ -295,7 +295,7 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.ptr_try_get_alloc_id(ptr) {
|
match self.ptr_try_get_alloc_id(ptr, 0) {
|
||||||
Ok((alloc_id, offset, _extra)) => {
|
Ok((alloc_id, offset, _extra)) => {
|
||||||
let (_size, alloc_align, _kind) = self.get_alloc_info(alloc_id);
|
let (_size, alloc_align, _kind) = self.get_alloc_info(alloc_id);
|
||||||
|
|
||||||
@ -510,7 +510,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
|
|||||||
|
|
||||||
// If an allocation is created in an another const,
|
// If an allocation is created in an another const,
|
||||||
// we don't deallocate it.
|
// we don't deallocate it.
|
||||||
let (alloc_id, _, _) = ecx.ptr_get_alloc_id(ptr)?;
|
let (alloc_id, _, _) = ecx.ptr_get_alloc_id(ptr, 0)?;
|
||||||
let is_allocated_in_another_const = matches!(
|
let is_allocated_in_another_const = matches!(
|
||||||
ecx.tcx.try_get_global_alloc(alloc_id),
|
ecx.tcx.try_get_global_alloc(alloc_id),
|
||||||
Some(interpret::GlobalAlloc::Memory(_))
|
Some(interpret::GlobalAlloc::Memory(_))
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use rustc_errors::codes::*;
|
use rustc_errors::codes::*;
|
||||||
@ -15,7 +16,7 @@ use rustc_middle::mir::interpret::{
|
|||||||
use rustc_middle::ty::{self, Mutability, Ty};
|
use rustc_middle::ty::{self, Mutability, Ty};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_target::abi::call::AdjustForForeignAbiError;
|
use rustc_target::abi::call::AdjustForForeignAbiError;
|
||||||
use rustc_target::abi::{Size, WrappingRange};
|
use rustc_target::abi::WrappingRange;
|
||||||
|
|
||||||
use crate::interpret::InternKind;
|
use crate::interpret::InternKind;
|
||||||
|
|
||||||
@ -575,18 +576,21 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
|
|||||||
.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
|
.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
|
||||||
}
|
}
|
||||||
PointerOutOfBounds { alloc_id, alloc_size, ptr_offset, inbounds_size, msg } => {
|
PointerOutOfBounds { alloc_id, alloc_size, ptr_offset, inbounds_size, msg } => {
|
||||||
diag.arg("alloc_size", alloc_size.bytes())
|
diag.arg("alloc_size", alloc_size.bytes());
|
||||||
.arg("inbounds_size", inbounds_size.bytes())
|
diag.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
|
||||||
.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
|
diag.arg("pointer", {
|
||||||
diag.arg(
|
let mut out = format!("{:?}", alloc_id);
|
||||||
"pointer",
|
if ptr_offset > 0 {
|
||||||
Pointer::new(
|
write!(out, "+{:#x}", ptr_offset).unwrap();
|
||||||
Some(CtfeProvenance::from(alloc_id)),
|
} else if ptr_offset < 0 {
|
||||||
Size::from_bytes(ptr_offset as u64),
|
write!(out, "-{:#x}", ptr_offset.unsigned_abs()).unwrap();
|
||||||
)
|
}
|
||||||
.to_string(),
|
out
|
||||||
);
|
});
|
||||||
|
diag.arg("inbounds_size_is_neg", inbounds_size < 0);
|
||||||
|
diag.arg("inbounds_size_abs", inbounds_size.unsigned_abs());
|
||||||
diag.arg("ptr_offset_is_neg", ptr_offset < 0);
|
diag.arg("ptr_offset_is_neg", ptr_offset < 0);
|
||||||
|
diag.arg("ptr_offset_abs", ptr_offset.unsigned_abs());
|
||||||
diag.arg(
|
diag.arg(
|
||||||
"alloc_size_minus_ptr_offset",
|
"alloc_size_minus_ptr_offset",
|
||||||
alloc_size.bytes().saturating_sub(ptr_offset as u64),
|
alloc_size.bytes().saturating_sub(ptr_offset as u64),
|
||||||
@ -600,7 +604,8 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
diag.arg("inbounds_size", inbounds_size.bytes());
|
diag.arg("inbounds_size_is_neg", inbounds_size < 0);
|
||||||
|
diag.arg("inbounds_size_abs", inbounds_size.unsigned_abs());
|
||||||
diag.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
|
diag.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
|
||||||
}
|
}
|
||||||
AlignmentCheckFailed(Misalignment { required, has }, msg) => {
|
AlignmentCheckFailed(Misalignment { required, has }, msg) => {
|
||||||
|
@ -560,17 +560,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
self.frame().body
|
self.frame().body
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn sign_extend(&self, value: u128, ty: TyAndLayout<'_>) -> u128 {
|
|
||||||
assert!(ty.abi.is_signed());
|
|
||||||
ty.size.sign_extend(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn truncate(&self, value: u128, ty: TyAndLayout<'_>) -> u128 {
|
|
||||||
ty.size.truncate(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
|
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
|
||||||
ty.is_freeze(*self.tcx, self.param_env)
|
ty.is_freeze(*self.tcx, self.param_env)
|
||||||
|
@ -206,7 +206,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
} else {
|
} else {
|
||||||
(val_bits >> shift_bits) | (val_bits << inv_shift_bits)
|
(val_bits >> shift_bits) | (val_bits << inv_shift_bits)
|
||||||
};
|
};
|
||||||
let truncated_bits = self.truncate(result_bits, layout_val);
|
let truncated_bits = layout_val.size.truncate(result_bits);
|
||||||
let result = Scalar::from_uint(truncated_bits, layout_val.size);
|
let result = Scalar::from_uint(truncated_bits, layout_val.size);
|
||||||
self.write_scalar(result, dest)?;
|
self.write_scalar(result, dest)?;
|
||||||
}
|
}
|
||||||
@ -243,7 +243,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
let (a_offset, b_offset, is_addr) = if M::Provenance::OFFSET_IS_ADDR {
|
let (a_offset, b_offset, is_addr) = if M::Provenance::OFFSET_IS_ADDR {
|
||||||
(a.addr().bytes(), b.addr().bytes(), /*is_addr*/ true)
|
(a.addr().bytes(), b.addr().bytes(), /*is_addr*/ true)
|
||||||
} else {
|
} else {
|
||||||
match (self.ptr_try_get_alloc_id(a), self.ptr_try_get_alloc_id(b)) {
|
match (self.ptr_try_get_alloc_id(a, 0), self.ptr_try_get_alloc_id(b, 0)) {
|
||||||
(Err(a), Err(b)) => {
|
(Err(a), Err(b)) => {
|
||||||
// Neither pointer points to an allocation, so they are both absolute.
|
// Neither pointer points to an allocation, so they are both absolute.
|
||||||
(a, b, /*is_addr*/ true)
|
(a, b, /*is_addr*/ true)
|
||||||
@ -312,7 +312,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Check that the memory between them is dereferenceable at all, starting from the
|
// Check that the memory between them is dereferenceable at all, starting from the
|
||||||
// base pointer: `dist` is `a - b`, so it is based on `b`.
|
// origin pointer: `dist` is `a - b`, so it is based on `b`.
|
||||||
self.check_ptr_access_signed(b, dist, CheckInAllocMsg::OffsetFromTest)?;
|
self.check_ptr_access_signed(b, dist, CheckInAllocMsg::OffsetFromTest)?;
|
||||||
// Then check that this is also dereferenceable from `a`. This ensures that they are
|
// Then check that this is also dereferenceable from `a`. This ensures that they are
|
||||||
// derived from the same allocation.
|
// derived from the same allocation.
|
||||||
@ -580,13 +580,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
ptr: Pointer<Option<M::Provenance>>,
|
ptr: Pointer<Option<M::Provenance>>,
|
||||||
offset_bytes: i64,
|
offset_bytes: i64,
|
||||||
) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>> {
|
) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>> {
|
||||||
// We first compute the pointer with overflow checks, to get a specific error for when it
|
|
||||||
// overflows (though technically this is redundant with the following inbounds check).
|
|
||||||
let result = ptr.signed_offset(offset_bytes, self)?;
|
|
||||||
// The offset must be in bounds starting from `ptr`.
|
// The offset must be in bounds starting from `ptr`.
|
||||||
self.check_ptr_access_signed(ptr, offset_bytes, CheckInAllocMsg::PointerArithmeticTest)?;
|
self.check_ptr_access_signed(ptr, offset_bytes, CheckInAllocMsg::PointerArithmeticTest)?;
|
||||||
// Done.
|
// This also implies that there is no overflow, so we are done.
|
||||||
Ok(result)
|
Ok(ptr.wrapping_signed_offset(offset_bytes, self))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copy `count*size_of::<T>()` many bytes from `*src` to `*dst`.
|
/// Copy `count*size_of::<T>()` many bytes from `*src` to `*dst`.
|
||||||
|
@ -321,15 +321,21 @@ pub trait Machine<'tcx>: Sized {
|
|||||||
ptr: Pointer<Self::Provenance>,
|
ptr: Pointer<Self::Provenance>,
|
||||||
) -> InterpResult<'tcx>;
|
) -> InterpResult<'tcx>;
|
||||||
|
|
||||||
/// Convert a pointer with provenance into an allocation-offset pair
|
/// Convert a pointer with provenance into an allocation-offset pair and extra provenance info.
|
||||||
/// and extra provenance info.
|
/// `size` says how many bytes of memory are expected at that pointer. The *sign* of `size` can
|
||||||
|
/// be used to disambiguate situations where a wildcard pointer sits right in between two
|
||||||
|
/// allocations.
|
||||||
///
|
///
|
||||||
/// The returned `AllocId` must be the same as `ptr.provenance.get_alloc_id()`.
|
/// If `ptr.provenance.get_alloc_id()` is `Some(p)`, the returned `AllocId` must be `p`.
|
||||||
|
/// The resulting `AllocId` will just be used for that one step and the forgotten again
|
||||||
|
/// (i.e., we'll never turn the data returned here back into a `Pointer` that might be
|
||||||
|
/// stored in machine state).
|
||||||
///
|
///
|
||||||
/// When this fails, that means the pointer does not point to a live allocation.
|
/// When this fails, that means the pointer does not point to a live allocation.
|
||||||
fn ptr_get_alloc(
|
fn ptr_get_alloc(
|
||||||
ecx: &InterpCx<'tcx, Self>,
|
ecx: &InterpCx<'tcx, Self>,
|
||||||
ptr: Pointer<Self::Provenance>,
|
ptr: Pointer<Self::Provenance>,
|
||||||
|
size: i64,
|
||||||
) -> Option<(AllocId, Size, Self::ProvenanceExtra)>;
|
) -> Option<(AllocId, Size, Self::ProvenanceExtra)>;
|
||||||
|
|
||||||
/// Called to adjust global allocations to the Provenance and AllocExtra of this machine.
|
/// Called to adjust global allocations to the Provenance and AllocExtra of this machine.
|
||||||
@ -658,6 +664,7 @@ pub macro compile_time_machine(<$tcx: lifetime>) {
|
|||||||
fn ptr_get_alloc(
|
fn ptr_get_alloc(
|
||||||
_ecx: &InterpCx<$tcx, Self>,
|
_ecx: &InterpCx<$tcx, Self>,
|
||||||
ptr: Pointer<CtfeProvenance>,
|
ptr: Pointer<CtfeProvenance>,
|
||||||
|
_size: i64,
|
||||||
) -> Option<(AllocId, Size, Self::ProvenanceExtra)> {
|
) -> Option<(AllocId, Size, Self::ProvenanceExtra)> {
|
||||||
// We know `offset` is relative to the allocation, so we can use `into_parts`.
|
// We know `offset` is relative to the allocation, so we can use `into_parts`.
|
||||||
let (prov, offset) = ptr.into_parts();
|
let (prov, offset) = ptr.into_parts();
|
||||||
|
@ -261,7 +261,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
new_align: Align,
|
new_align: Align,
|
||||||
kind: MemoryKind<M::MemoryKind>,
|
kind: MemoryKind<M::MemoryKind>,
|
||||||
) -> InterpResult<'tcx, Pointer<M::Provenance>> {
|
) -> InterpResult<'tcx, Pointer<M::Provenance>> {
|
||||||
let (alloc_id, offset, _prov) = self.ptr_get_alloc_id(ptr)?;
|
let (alloc_id, offset, _prov) = self.ptr_get_alloc_id(ptr, 0)?;
|
||||||
if offset.bytes() != 0 {
|
if offset.bytes() != 0 {
|
||||||
throw_ub_custom!(
|
throw_ub_custom!(
|
||||||
fluent::const_eval_realloc_or_alloc_with_offset,
|
fluent::const_eval_realloc_or_alloc_with_offset,
|
||||||
@ -291,7 +291,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
old_size_and_align: Option<(Size, Align)>,
|
old_size_and_align: Option<(Size, Align)>,
|
||||||
kind: MemoryKind<M::MemoryKind>,
|
kind: MemoryKind<M::MemoryKind>,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
let (alloc_id, offset, prov) = self.ptr_get_alloc_id(ptr)?;
|
let (alloc_id, offset, prov) = self.ptr_get_alloc_id(ptr, 0)?;
|
||||||
trace!("deallocating: {alloc_id:?}");
|
trace!("deallocating: {alloc_id:?}");
|
||||||
|
|
||||||
if offset.bytes() != 0 {
|
if offset.bytes() != 0 {
|
||||||
@ -383,6 +383,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
ptr: Pointer<Option<M::Provenance>>,
|
ptr: Pointer<Option<M::Provenance>>,
|
||||||
size: Size,
|
size: Size,
|
||||||
) -> InterpResult<'tcx, Option<(AllocId, Size, M::ProvenanceExtra)>> {
|
) -> InterpResult<'tcx, Option<(AllocId, Size, M::ProvenanceExtra)>> {
|
||||||
|
let size = i64::try_from(size.bytes()).unwrap(); // it would be an error to even ask for more than isize::MAX bytes
|
||||||
self.check_and_deref_ptr(
|
self.check_and_deref_ptr(
|
||||||
ptr,
|
ptr,
|
||||||
size,
|
size,
|
||||||
@ -404,6 +405,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
size: Size,
|
size: Size,
|
||||||
msg: CheckInAllocMsg,
|
msg: CheckInAllocMsg,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
|
let size = i64::try_from(size.bytes()).unwrap(); // it would be an error to even ask for more than isize::MAX bytes
|
||||||
self.check_and_deref_ptr(ptr, size, msg, |alloc_id, _, _| {
|
self.check_and_deref_ptr(ptr, size, msg, |alloc_id, _, _| {
|
||||||
let (size, align) = self.get_live_alloc_size_and_align(alloc_id, msg)?;
|
let (size, align) = self.get_live_alloc_size_and_align(alloc_id, msg)?;
|
||||||
Ok((size, align, ()))
|
Ok((size, align, ()))
|
||||||
@ -420,19 +422,17 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
size: i64,
|
size: i64,
|
||||||
msg: CheckInAllocMsg,
|
msg: CheckInAllocMsg,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
if let Ok(size) = u64::try_from(size) {
|
self.check_and_deref_ptr(ptr, size, msg, |alloc_id, _, _| {
|
||||||
self.check_ptr_access(ptr, Size::from_bytes(size), msg)
|
let (size, align) = self.get_live_alloc_size_and_align(alloc_id, msg)?;
|
||||||
} else {
|
Ok((size, align, ()))
|
||||||
// Compute the pointer at the beginning of the range, and do the standard
|
})?;
|
||||||
// dereferenceability check from there.
|
Ok(())
|
||||||
let begin_ptr = ptr.wrapping_signed_offset(size, self);
|
|
||||||
self.check_ptr_access(begin_ptr, Size::from_bytes(size.unsigned_abs()), msg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Low-level helper function to check if a ptr is in-bounds and potentially return a reference
|
/// Low-level helper function to check if a ptr is in-bounds and potentially return a reference
|
||||||
/// to the allocation it points to. Supports both shared and mutable references, as the actual
|
/// to the allocation it points to. Supports both shared and mutable references, as the actual
|
||||||
/// checking is offloaded to a helper closure.
|
/// checking is offloaded to a helper closure. Supports signed sizes for checks "to the left" of
|
||||||
|
/// a pointer.
|
||||||
///
|
///
|
||||||
/// `alloc_size` will only get called for non-zero-sized accesses.
|
/// `alloc_size` will only get called for non-zero-sized accesses.
|
||||||
///
|
///
|
||||||
@ -440,7 +440,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
fn check_and_deref_ptr<T>(
|
fn check_and_deref_ptr<T>(
|
||||||
&self,
|
&self,
|
||||||
ptr: Pointer<Option<M::Provenance>>,
|
ptr: Pointer<Option<M::Provenance>>,
|
||||||
size: Size,
|
size: i64,
|
||||||
msg: CheckInAllocMsg,
|
msg: CheckInAllocMsg,
|
||||||
alloc_size: impl FnOnce(
|
alloc_size: impl FnOnce(
|
||||||
AllocId,
|
AllocId,
|
||||||
@ -449,24 +449,31 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
) -> InterpResult<'tcx, (Size, Align, T)>,
|
) -> InterpResult<'tcx, (Size, Align, T)>,
|
||||||
) -> InterpResult<'tcx, Option<T>> {
|
) -> InterpResult<'tcx, Option<T>> {
|
||||||
// Everything is okay with size 0.
|
// Everything is okay with size 0.
|
||||||
if size.bytes() == 0 {
|
if size == 0 {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(match self.ptr_try_get_alloc_id(ptr) {
|
Ok(match self.ptr_try_get_alloc_id(ptr, size) {
|
||||||
Err(addr) => {
|
Err(addr) => {
|
||||||
// We couldn't get a proper allocation.
|
// We couldn't get a proper allocation.
|
||||||
throw_ub!(DanglingIntPointer { addr, inbounds_size: size, msg });
|
throw_ub!(DanglingIntPointer { addr, inbounds_size: size, msg });
|
||||||
}
|
}
|
||||||
Ok((alloc_id, offset, prov)) => {
|
Ok((alloc_id, offset, prov)) => {
|
||||||
let (alloc_size, _alloc_align, ret_val) = alloc_size(alloc_id, offset, prov)?;
|
let (alloc_size, _alloc_align, ret_val) = alloc_size(alloc_id, offset, prov)?;
|
||||||
// Test bounds.
|
let offset = offset.bytes();
|
||||||
// It is sufficient to check this for the end pointer. Also check for overflow!
|
// Compute absolute begin and end of the range.
|
||||||
if offset.checked_add(size, &self.tcx).is_none_or(|end| end > alloc_size) {
|
let (begin, end) = if size >= 0 {
|
||||||
|
(Some(offset), offset.checked_add(size as u64))
|
||||||
|
} else {
|
||||||
|
(offset.checked_sub(size.unsigned_abs()), Some(offset))
|
||||||
|
};
|
||||||
|
// Ensure both are within bounds.
|
||||||
|
let in_bounds = begin.is_some() && end.is_some_and(|e| e <= alloc_size.bytes());
|
||||||
|
if !in_bounds {
|
||||||
throw_ub!(PointerOutOfBounds {
|
throw_ub!(PointerOutOfBounds {
|
||||||
alloc_id,
|
alloc_id,
|
||||||
alloc_size,
|
alloc_size,
|
||||||
ptr_offset: self.target_usize_to_isize(offset.bytes()),
|
ptr_offset: self.sign_extend_to_target_isize(offset),
|
||||||
inbounds_size: size,
|
inbounds_size: size,
|
||||||
msg,
|
msg,
|
||||||
})
|
})
|
||||||
@ -498,7 +505,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn offset_misalignment(offset: u64, align: Align) -> Option<Misalignment> {
|
fn is_offset_misaligned(offset: u64, align: Align) -> Option<Misalignment> {
|
||||||
if offset % align.bytes() == 0 {
|
if offset % align.bytes() == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@ -508,8 +515,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.ptr_try_get_alloc_id(ptr) {
|
match self.ptr_try_get_alloc_id(ptr, 0) {
|
||||||
Err(addr) => offset_misalignment(addr, align),
|
Err(addr) => is_offset_misaligned(addr, align),
|
||||||
Ok((alloc_id, offset, _prov)) => {
|
Ok((alloc_id, offset, _prov)) => {
|
||||||
let (_size, alloc_align, kind) = self.get_alloc_info(alloc_id);
|
let (_size, alloc_align, kind) = self.get_alloc_info(alloc_id);
|
||||||
if let Some(misalign) =
|
if let Some(misalign) =
|
||||||
@ -517,14 +524,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
{
|
{
|
||||||
Some(misalign)
|
Some(misalign)
|
||||||
} else if M::Provenance::OFFSET_IS_ADDR {
|
} else if M::Provenance::OFFSET_IS_ADDR {
|
||||||
// `use_addr_for_alignment_check` can only be true if `OFFSET_IS_ADDR` is true.
|
is_offset_misaligned(ptr.addr().bytes(), align)
|
||||||
offset_misalignment(ptr.addr().bytes(), align)
|
|
||||||
} else {
|
} else {
|
||||||
// Check allocation alignment and offset alignment.
|
// Check allocation alignment and offset alignment.
|
||||||
if alloc_align.bytes() < align.bytes() {
|
if alloc_align.bytes() < align.bytes() {
|
||||||
Some(Misalignment { has: alloc_align, required: align })
|
Some(Misalignment { has: alloc_align, required: align })
|
||||||
} else {
|
} else {
|
||||||
offset_misalignment(offset.bytes(), align)
|
is_offset_misaligned(offset.bytes(), align)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -660,9 +666,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
size: Size,
|
size: Size,
|
||||||
) -> InterpResult<'tcx, Option<AllocRef<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
|
) -> InterpResult<'tcx, Option<AllocRef<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
|
||||||
{
|
{
|
||||||
|
let size_i64 = i64::try_from(size.bytes()).unwrap(); // it would be an error to even ask for more than isize::MAX bytes
|
||||||
let ptr_and_alloc = self.check_and_deref_ptr(
|
let ptr_and_alloc = self.check_and_deref_ptr(
|
||||||
ptr,
|
ptr,
|
||||||
size,
|
size_i64,
|
||||||
CheckInAllocMsg::MemoryAccessTest,
|
CheckInAllocMsg::MemoryAccessTest,
|
||||||
|alloc_id, offset, prov| {
|
|alloc_id, offset, prov| {
|
||||||
let alloc = self.get_alloc_raw(alloc_id)?;
|
let alloc = self.get_alloc_raw(alloc_id)?;
|
||||||
@ -673,7 +680,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
// accesses. That means we cannot rely on the closure above or the `Some` branch below. We
|
// accesses. That means we cannot rely on the closure above or the `Some` branch below. We
|
||||||
// do this after `check_and_deref_ptr` to ensure some basic sanity has already been checked.
|
// do this after `check_and_deref_ptr` to ensure some basic sanity has already been checked.
|
||||||
if !self.memory.validation_in_progress.get() {
|
if !self.memory.validation_in_progress.get() {
|
||||||
if let Ok((alloc_id, ..)) = self.ptr_try_get_alloc_id(ptr) {
|
if let Ok((alloc_id, ..)) = self.ptr_try_get_alloc_id(ptr, size_i64) {
|
||||||
M::before_alloc_read(self, alloc_id)?;
|
M::before_alloc_read(self, alloc_id)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -894,7 +901,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
ptr: Pointer<Option<M::Provenance>>,
|
ptr: Pointer<Option<M::Provenance>>,
|
||||||
) -> InterpResult<'tcx, FnVal<'tcx, M::ExtraFnVal>> {
|
) -> InterpResult<'tcx, FnVal<'tcx, M::ExtraFnVal>> {
|
||||||
trace!("get_ptr_fn({:?})", ptr);
|
trace!("get_ptr_fn({:?})", ptr);
|
||||||
let (alloc_id, offset, _prov) = self.ptr_get_alloc_id(ptr)?;
|
let (alloc_id, offset, _prov) = self.ptr_get_alloc_id(ptr, 0)?;
|
||||||
if offset.bytes() != 0 {
|
if offset.bytes() != 0 {
|
||||||
throw_ub!(InvalidFunctionPointer(Pointer::new(alloc_id, offset)))
|
throw_ub!(InvalidFunctionPointer(Pointer::new(alloc_id, offset)))
|
||||||
}
|
}
|
||||||
@ -910,7 +917,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
expected_trait: Option<&'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>>,
|
expected_trait: Option<&'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>>,
|
||||||
) -> InterpResult<'tcx, Ty<'tcx>> {
|
) -> InterpResult<'tcx, Ty<'tcx>> {
|
||||||
trace!("get_ptr_vtable({:?})", ptr);
|
trace!("get_ptr_vtable({:?})", ptr);
|
||||||
let (alloc_id, offset, _tag) = self.ptr_get_alloc_id(ptr)?;
|
let (alloc_id, offset, _tag) = self.ptr_get_alloc_id(ptr, 0)?;
|
||||||
if offset.bytes() != 0 {
|
if offset.bytes() != 0 {
|
||||||
throw_ub!(InvalidVTablePointer(Pointer::new(alloc_id, offset)))
|
throw_ub!(InvalidVTablePointer(Pointer::new(alloc_id, offset)))
|
||||||
}
|
}
|
||||||
@ -1391,7 +1398,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
Err(_) => {
|
Err(_) => {
|
||||||
// Can only happen during CTFE.
|
// Can only happen during CTFE.
|
||||||
let ptr = scalar.to_pointer(self)?;
|
let ptr = scalar.to_pointer(self)?;
|
||||||
match self.ptr_try_get_alloc_id(ptr) {
|
match self.ptr_try_get_alloc_id(ptr, 0) {
|
||||||
Ok((alloc_id, offset, _)) => {
|
Ok((alloc_id, offset, _)) => {
|
||||||
let (size, _align, _kind) = self.get_alloc_info(alloc_id);
|
let (size, _align, _kind) = self.get_alloc_info(alloc_id);
|
||||||
// If the pointer is out-of-bounds, it may be null.
|
// If the pointer is out-of-bounds, it may be null.
|
||||||
@ -1407,6 +1414,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
/// Turning a "maybe pointer" into a proper pointer (and some information
|
/// Turning a "maybe pointer" into a proper pointer (and some information
|
||||||
/// about where it points), or an absolute address.
|
/// about where it points), or an absolute address.
|
||||||
///
|
///
|
||||||
|
/// `size` says how many bytes of memory are expected at that pointer. This is largely only used
|
||||||
|
/// for error messages; however, the *sign* of `size` can be used to disambiguate situations
|
||||||
|
/// where a wildcard pointer sits right in between two allocations.
|
||||||
|
/// It is almost always okay to just set the size to 0; this will be treated like a positive size
|
||||||
|
/// for handling wildcard pointers.
|
||||||
|
///
|
||||||
/// The result must be used immediately; it is not allowed to convert
|
/// The result must be used immediately; it is not allowed to convert
|
||||||
/// the returned data back into a `Pointer` and store that in machine state.
|
/// the returned data back into a `Pointer` and store that in machine state.
|
||||||
/// (In fact that's not even possible since `M::ProvenanceExtra` is generic and
|
/// (In fact that's not even possible since `M::ProvenanceExtra` is generic and
|
||||||
@ -1414,9 +1427,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
pub fn ptr_try_get_alloc_id(
|
pub fn ptr_try_get_alloc_id(
|
||||||
&self,
|
&self,
|
||||||
ptr: Pointer<Option<M::Provenance>>,
|
ptr: Pointer<Option<M::Provenance>>,
|
||||||
|
size: i64,
|
||||||
) -> Result<(AllocId, Size, M::ProvenanceExtra), u64> {
|
) -> Result<(AllocId, Size, M::ProvenanceExtra), u64> {
|
||||||
match ptr.into_pointer_or_addr() {
|
match ptr.into_pointer_or_addr() {
|
||||||
Ok(ptr) => match M::ptr_get_alloc(self, ptr) {
|
Ok(ptr) => match M::ptr_get_alloc(self, ptr, size) {
|
||||||
Some((alloc_id, offset, extra)) => Ok((alloc_id, offset, extra)),
|
Some((alloc_id, offset, extra)) => Ok((alloc_id, offset, extra)),
|
||||||
None => {
|
None => {
|
||||||
assert!(M::Provenance::OFFSET_IS_ADDR);
|
assert!(M::Provenance::OFFSET_IS_ADDR);
|
||||||
@ -1430,6 +1444,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
|
|
||||||
/// Turning a "maybe pointer" into a proper pointer (and some information about where it points).
|
/// Turning a "maybe pointer" into a proper pointer (and some information about where it points).
|
||||||
///
|
///
|
||||||
|
/// `size` says how many bytes of memory are expected at that pointer. This is largely only used
|
||||||
|
/// for error messages; however, the *sign* of `size` can be used to disambiguate situations
|
||||||
|
/// where a wildcard pointer sits right in between two allocations.
|
||||||
|
/// It is almost always okay to just set the size to 0; this will be treated like a positive size
|
||||||
|
/// for handling wildcard pointers.
|
||||||
|
///
|
||||||
/// The result must be used immediately; it is not allowed to convert
|
/// The result must be used immediately; it is not allowed to convert
|
||||||
/// the returned data back into a `Pointer` and store that in machine state.
|
/// the returned data back into a `Pointer` and store that in machine state.
|
||||||
/// (In fact that's not even possible since `M::ProvenanceExtra` is generic and
|
/// (In fact that's not even possible since `M::ProvenanceExtra` is generic and
|
||||||
@ -1438,12 +1458,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
pub fn ptr_get_alloc_id(
|
pub fn ptr_get_alloc_id(
|
||||||
&self,
|
&self,
|
||||||
ptr: Pointer<Option<M::Provenance>>,
|
ptr: Pointer<Option<M::Provenance>>,
|
||||||
|
size: i64,
|
||||||
) -> InterpResult<'tcx, (AllocId, Size, M::ProvenanceExtra)> {
|
) -> InterpResult<'tcx, (AllocId, Size, M::ProvenanceExtra)> {
|
||||||
self.ptr_try_get_alloc_id(ptr).map_err(|offset| {
|
self.ptr_try_get_alloc_id(ptr, size).map_err(|offset| {
|
||||||
err_ub!(DanglingIntPointer {
|
err_ub!(DanglingIntPointer {
|
||||||
addr: offset,
|
addr: offset,
|
||||||
// We don't know the actually required size.
|
inbounds_size: size,
|
||||||
inbounds_size: Size::ZERO,
|
|
||||||
msg: CheckInAllocMsg::InboundsTest
|
msg: CheckInAllocMsg::InboundsTest
|
||||||
})
|
})
|
||||||
.into()
|
.into()
|
||||||
|
@ -7,7 +7,7 @@ use rustc_middle::{bug, mir, span_bug};
|
|||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
use super::{err_ub, throw_ub, ImmTy, InterpCx, Machine, MemPlaceMeta};
|
use super::{throw_ub, ImmTy, InterpCx, Machine, MemPlaceMeta};
|
||||||
|
|
||||||
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||||
fn three_way_compare<T: Ord>(&self, lhs: T, rhs: T) -> ImmTy<'tcx, M::Provenance> {
|
fn three_way_compare<T: Ord>(&self, lhs: T, rhs: T) -> ImmTy<'tcx, M::Provenance> {
|
||||||
@ -298,17 +298,23 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
// Pointer ops that are always supported.
|
// Pointer ops that are always supported.
|
||||||
Offset => {
|
Offset => {
|
||||||
let ptr = left.to_scalar().to_pointer(self)?;
|
let ptr = left.to_scalar().to_pointer(self)?;
|
||||||
let offset_count = right.to_scalar().to_target_isize(self)?;
|
|
||||||
let pointee_ty = left.layout.ty.builtin_deref(true).unwrap();
|
let pointee_ty = left.layout.ty.builtin_deref(true).unwrap();
|
||||||
|
let pointee_layout = self.layout_of(pointee_ty)?;
|
||||||
|
assert!(pointee_layout.abi.is_sized());
|
||||||
|
|
||||||
// We cannot overflow i64 as a type's size must be <= isize::MAX.
|
// We cannot overflow i64 as a type's size must be <= isize::MAX.
|
||||||
let pointee_size = i64::try_from(self.layout_of(pointee_ty)?.size.bytes()).unwrap();
|
let pointee_size = i64::try_from(pointee_layout.size.bytes()).unwrap();
|
||||||
// The computed offset, in bytes, must not overflow an isize.
|
let pointee_size = ImmTy::from_int(pointee_size, right.layout);
|
||||||
// `checked_mul` enforces a too small bound, but no actual allocation can be big enough for
|
// Multiply element size and element count.
|
||||||
// the difference to be noticeable.
|
let (val, overflowed) = self
|
||||||
let offset_bytes =
|
.binary_op(mir::BinOp::MulWithOverflow, right, &pointee_size)?
|
||||||
offset_count.checked_mul(pointee_size).ok_or(err_ub!(PointerArithOverflow))?;
|
.to_scalar_pair();
|
||||||
|
// This must not overflow.
|
||||||
|
if overflowed.to_bool()? {
|
||||||
|
throw_ub!(PointerArithOverflow)
|
||||||
|
}
|
||||||
|
|
||||||
|
let offset_bytes = val.to_target_isize(self)?;
|
||||||
let offset_ptr = self.ptr_offset_inbounds(ptr, offset_bytes)?;
|
let offset_ptr = self.ptr_offset_inbounds(ptr, offset_bytes)?;
|
||||||
Ok(ImmTy::from_scalar(Scalar::from_maybe_pointer(offset_ptr, self), left.layout))
|
Ok(ImmTy::from_scalar(Scalar::from_maybe_pointer(offset_ptr, self), left.layout))
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,9 @@ use rustc_target::abi::{Abi, Align, HasDataLayout, Size};
|
|||||||
use tracing::{instrument, trace};
|
use tracing::{instrument, trace};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
alloc_range, mir_assign_valid_types, throw_ub, AllocRef, AllocRefMut, CheckAlignMsg,
|
alloc_range, mir_assign_valid_types, AllocRef, AllocRefMut, CheckAlignMsg, CtfeProvenance,
|
||||||
CtfeProvenance, ImmTy, Immediate, InterpCx, InterpResult, Machine, MemoryKind, Misalignment,
|
ImmTy, Immediate, InterpCx, InterpResult, Machine, MemoryKind, Misalignment, OffsetMode, OpTy,
|
||||||
OffsetMode, OpTy, Operand, Pointer, PointerArithmetic, Projectable, Provenance, Readable,
|
Operand, Pointer, Projectable, Provenance, Readable, Scalar,
|
||||||
Scalar,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
|
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
|
||||||
@ -85,9 +84,6 @@ impl<Prov: Provenance> MemPlace<Prov> {
|
|||||||
!meta.has_meta() || self.meta.has_meta(),
|
!meta.has_meta() || self.meta.has_meta(),
|
||||||
"cannot use `offset_with_meta` to add metadata to a place"
|
"cannot use `offset_with_meta` to add metadata to a place"
|
||||||
);
|
);
|
||||||
if offset > ecx.data_layout().max_size_of_val() {
|
|
||||||
throw_ub!(PointerArithOverflow);
|
|
||||||
}
|
|
||||||
let ptr = match mode {
|
let ptr = match mode {
|
||||||
OffsetMode::Inbounds => {
|
OffsetMode::Inbounds => {
|
||||||
ecx.ptr_offset_inbounds(self.ptr, offset.bytes().try_into().unwrap())?
|
ecx.ptr_offset_inbounds(self.ptr, offset.bytes().try_into().unwrap())?
|
||||||
@ -289,10 +285,8 @@ impl<'tcx, Prov: Provenance> Projectable<'tcx, Prov> for PlaceTy<'tcx, Prov> {
|
|||||||
// projections are type-checked and bounds-checked.
|
// projections are type-checked and bounds-checked.
|
||||||
assert!(offset + layout.size <= self.layout.size);
|
assert!(offset + layout.size <= self.layout.size);
|
||||||
|
|
||||||
let new_offset = Size::from_bytes(
|
// Size `+`, ensures no overflow.
|
||||||
ecx.data_layout()
|
let new_offset = old_offset.unwrap_or(Size::ZERO) + offset;
|
||||||
.offset(old_offset.unwrap_or(Size::ZERO).bytes(), offset.bytes())?,
|
|
||||||
);
|
|
||||||
|
|
||||||
PlaceTy {
|
PlaceTy {
|
||||||
place: Place::Local { local, offset: Some(new_offset), locals_addr },
|
place: Place::Local { local, offset: Some(new_offset), locals_addr },
|
||||||
|
@ -362,7 +362,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
// of the first element.
|
// of the first element.
|
||||||
let elem_size = first.layout.size;
|
let elem_size = first.layout.size;
|
||||||
let first_ptr = first.ptr();
|
let first_ptr = first.ptr();
|
||||||
let rest_ptr = first_ptr.offset(elem_size, self)?;
|
let rest_ptr = first_ptr.wrapping_offset(elem_size, self);
|
||||||
// No alignment requirement since `copy_op` above already checked it.
|
// No alignment requirement since `copy_op` above already checked it.
|
||||||
self.mem_copy_repeatedly(
|
self.mem_copy_repeatedly(
|
||||||
first_ptr,
|
first_ptr,
|
||||||
|
@ -455,7 +455,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
|
|||||||
};
|
};
|
||||||
// Proceed recursively even for ZST, no reason to skip them!
|
// Proceed recursively even for ZST, no reason to skip them!
|
||||||
// `!` is a ZST and we want to validate it.
|
// `!` is a ZST and we want to validate it.
|
||||||
if let Ok((alloc_id, _offset, _prov)) = self.ecx.ptr_try_get_alloc_id(place.ptr()) {
|
if let Ok((alloc_id, _offset, _prov)) = self.ecx.ptr_try_get_alloc_id(place.ptr(), 0) {
|
||||||
let mut skip_recursive_check = false;
|
let mut skip_recursive_check = false;
|
||||||
if let Some(GlobalAlloc::Static(did)) = self.ecx.tcx.try_get_global_alloc(alloc_id)
|
if let Some(GlobalAlloc::Static(did)) = self.ecx.tcx.try_get_global_alloc(alloc_id)
|
||||||
{
|
{
|
||||||
|
@ -309,11 +309,7 @@ fn report_bin_hex_error(
|
|||||||
) {
|
) {
|
||||||
let (t, actually) = match ty {
|
let (t, actually) = match ty {
|
||||||
attr::IntType::SignedInt(t) => {
|
attr::IntType::SignedInt(t) => {
|
||||||
let actually = if negative {
|
let actually = if negative { -(size.sign_extend(val)) } else { size.sign_extend(val) };
|
||||||
-(size.sign_extend(val) as i128)
|
|
||||||
} else {
|
|
||||||
size.sign_extend(val) as i128
|
|
||||||
};
|
|
||||||
(t.name_str(), actually.to_string())
|
(t.name_str(), actually.to_string())
|
||||||
}
|
}
|
||||||
attr::IntType::UnsignedInt(t) => {
|
attr::IntType::UnsignedInt(t) => {
|
||||||
|
@ -334,14 +334,15 @@ pub enum UndefinedBehaviorInfo<'tcx> {
|
|||||||
alloc_size: Size,
|
alloc_size: Size,
|
||||||
ptr_offset: i64,
|
ptr_offset: i64,
|
||||||
/// The size of the memory range that was expected to be in-bounds.
|
/// The size of the memory range that was expected to be in-bounds.
|
||||||
inbounds_size: Size,
|
inbounds_size: i64,
|
||||||
msg: CheckInAllocMsg,
|
msg: CheckInAllocMsg,
|
||||||
},
|
},
|
||||||
/// Using an integer as a pointer in the wrong way.
|
/// Using an integer as a pointer in the wrong way.
|
||||||
DanglingIntPointer {
|
DanglingIntPointer {
|
||||||
addr: u64,
|
addr: u64,
|
||||||
/// The size of the memory range that was expected to be in-bounds (or 0 if we don't know).
|
/// The size of the memory range that was expected to be in-bounds (or 0 if we need an
|
||||||
inbounds_size: Size,
|
/// allocation but not any actual memory there, e.g. for function pointers).
|
||||||
|
inbounds_size: i64,
|
||||||
msg: CheckInAllocMsg,
|
msg: CheckInAllocMsg,
|
||||||
},
|
},
|
||||||
/// Used a pointer with bad alignment.
|
/// Used a pointer with bad alignment.
|
||||||
|
@ -5,7 +5,7 @@ use rustc_data_structures::static_assert_size;
|
|||||||
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
|
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
|
||||||
use rustc_target::abi::{HasDataLayout, Size};
|
use rustc_target::abi::{HasDataLayout, Size};
|
||||||
|
|
||||||
use super::{AllocId, InterpResult};
|
use super::AllocId;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Pointer arithmetic
|
// Pointer arithmetic
|
||||||
@ -40,62 +40,13 @@ pub trait PointerArithmetic: HasDataLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn target_usize_to_isize(&self, val: u64) -> i64 {
|
fn truncate_to_target_usize(&self, val: u64) -> u64 {
|
||||||
let val = val as i64;
|
self.pointer_size().truncate(val.into()).try_into().unwrap()
|
||||||
// Now wrap-around into the machine_isize range.
|
|
||||||
if val > self.target_isize_max() {
|
|
||||||
// This can only happen if the ptr size is < 64, so we know max_usize_plus_1 fits into
|
|
||||||
// i64.
|
|
||||||
debug_assert!(self.pointer_size().bits() < 64);
|
|
||||||
let max_usize_plus_1 = 1u128 << self.pointer_size().bits();
|
|
||||||
val - i64::try_from(max_usize_plus_1).unwrap()
|
|
||||||
} else {
|
|
||||||
val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper function: truncate given value-"overflowed flag" pair to pointer size and
|
|
||||||
/// update "overflowed flag" if there was an overflow.
|
|
||||||
/// This should be called by all the other methods before returning!
|
|
||||||
#[inline]
|
|
||||||
fn truncate_to_ptr(&self, (val, over): (u64, bool)) -> (u64, bool) {
|
|
||||||
let val = u128::from(val);
|
|
||||||
let max_ptr_plus_1 = 1u128 << self.pointer_size().bits();
|
|
||||||
(u64::try_from(val % max_ptr_plus_1).unwrap(), over || val >= max_ptr_plus_1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_offset(&self, val: u64, i: u64) -> (u64, bool) {
|
fn sign_extend_to_target_isize(&self, val: u64) -> i64 {
|
||||||
// We do not need to check if i fits in a machine usize. If it doesn't,
|
self.pointer_size().sign_extend(val.into()).try_into().unwrap()
|
||||||
// either the wrapping_add will wrap or res will not fit in a pointer.
|
|
||||||
let res = val.overflowing_add(i);
|
|
||||||
self.truncate_to_ptr(res)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn overflowing_signed_offset(&self, val: u64, i: i64) -> (u64, bool) {
|
|
||||||
// We need to make sure that i fits in a machine isize.
|
|
||||||
let n = i.unsigned_abs();
|
|
||||||
if i >= 0 {
|
|
||||||
let (val, over) = self.overflowing_offset(val, n);
|
|
||||||
(val, over || i > self.target_isize_max())
|
|
||||||
} else {
|
|
||||||
let res = val.overflowing_sub(n);
|
|
||||||
let (val, over) = self.truncate_to_ptr(res);
|
|
||||||
(val, over || i < self.target_isize_min())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn offset<'tcx>(&self, val: u64, i: u64) -> InterpResult<'tcx, u64> {
|
|
||||||
let (res, over) = self.overflowing_offset(val, i);
|
|
||||||
if over { throw_ub!(PointerArithOverflow) } else { Ok(res) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn signed_offset<'tcx>(&self, val: u64, i: i64) -> InterpResult<'tcx, u64> {
|
|
||||||
let (res, over) = self.overflowing_signed_offset(val, i);
|
|
||||||
if over { throw_ub!(PointerArithOverflow) } else { Ok(res) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,12 +132,9 @@ impl Provenance for CtfeProvenance {
|
|||||||
fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
// Print AllocId.
|
// Print AllocId.
|
||||||
fmt::Debug::fmt(&ptr.provenance.alloc_id(), f)?; // propagates `alternate` flag
|
fmt::Debug::fmt(&ptr.provenance.alloc_id(), f)?; // propagates `alternate` flag
|
||||||
// Print offset only if it is non-zero. Print it signed.
|
// Print offset only if it is non-zero.
|
||||||
let signed_offset = ptr.offset.bytes() as i64;
|
if ptr.offset.bytes() > 0 {
|
||||||
if signed_offset > 0 {
|
write!(f, "+{:#x}", ptr.offset.bytes())?;
|
||||||
write!(f, "+{:#x}", signed_offset)?;
|
|
||||||
} else if signed_offset < 0 {
|
|
||||||
write!(f, "-{:#x}", signed_offset.unsigned_abs())?;
|
|
||||||
}
|
}
|
||||||
// Print immutable status.
|
// Print immutable status.
|
||||||
if ptr.provenance.immutable() {
|
if ptr.provenance.immutable() {
|
||||||
@ -334,7 +282,7 @@ impl<Prov> Pointer<Option<Prov>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, Prov> Pointer<Prov> {
|
impl<Prov> Pointer<Prov> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn new(provenance: Prov, offset: Size) -> Self {
|
pub fn new(provenance: Prov, offset: Size) -> Self {
|
||||||
Pointer { provenance, offset }
|
Pointer { provenance, offset }
|
||||||
@ -352,43 +300,16 @@ impl<'tcx, Prov> Pointer<Prov> {
|
|||||||
Pointer { provenance: f(self.provenance), ..self }
|
Pointer { provenance: f(self.provenance), ..self }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn offset(self, i: Size, cx: &impl HasDataLayout) -> InterpResult<'tcx, Self> {
|
|
||||||
Ok(Pointer {
|
|
||||||
offset: Size::from_bytes(cx.data_layout().offset(self.offset.bytes(), i.bytes())?),
|
|
||||||
..self
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn overflowing_offset(self, i: Size, cx: &impl HasDataLayout) -> (Self, bool) {
|
|
||||||
let (res, over) = cx.data_layout().overflowing_offset(self.offset.bytes(), i.bytes());
|
|
||||||
let ptr = Pointer { offset: Size::from_bytes(res), ..self };
|
|
||||||
(ptr, over)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn wrapping_offset(self, i: Size, cx: &impl HasDataLayout) -> Self {
|
pub fn wrapping_offset(self, i: Size, cx: &impl HasDataLayout) -> Self {
|
||||||
self.overflowing_offset(i, cx).0
|
let res =
|
||||||
}
|
cx.data_layout().truncate_to_target_usize(self.offset.bytes().wrapping_add(i.bytes()));
|
||||||
|
Pointer { offset: Size::from_bytes(res), ..self }
|
||||||
#[inline]
|
|
||||||
pub fn signed_offset(self, i: i64, cx: &impl HasDataLayout) -> InterpResult<'tcx, Self> {
|
|
||||||
Ok(Pointer {
|
|
||||||
offset: Size::from_bytes(cx.data_layout().signed_offset(self.offset.bytes(), i)?),
|
|
||||||
..self
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn overflowing_signed_offset(self, i: i64, cx: &impl HasDataLayout) -> (Self, bool) {
|
|
||||||
let (res, over) = cx.data_layout().overflowing_signed_offset(self.offset.bytes(), i);
|
|
||||||
let ptr = Pointer { offset: Size::from_bytes(res), ..self };
|
|
||||||
(ptr, over)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn wrapping_signed_offset(self, i: i64, cx: &impl HasDataLayout) -> Self {
|
pub fn wrapping_signed_offset(self, i: i64, cx: &impl HasDataLayout) -> Self {
|
||||||
self.overflowing_signed_offset(i, cx).0
|
// It's wrapping anyway, so we can just cast to `u64`.
|
||||||
|
self.wrapping_offset(Size::from_bytes(i as u64), cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -393,7 +393,7 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_int(self, size: Size) -> InterpResult<'tcx, i128> {
|
pub fn to_int(self, size: Size) -> InterpResult<'tcx, i128> {
|
||||||
let b = self.to_bits(size)?;
|
let b = self.to_bits(size)?;
|
||||||
Ok(size.sign_extend(b) as i128)
|
Ok(size.sign_extend(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the scalar to produce an `i8`. Fails if the scalar is a pointer.
|
/// Converts the scalar to produce an `i8`. Fails if the scalar is a pointer.
|
||||||
|
@ -234,7 +234,7 @@ impl ScalarInt {
|
|||||||
let data = i.into();
|
let data = i.into();
|
||||||
// `into` performed sign extension, we have to truncate
|
// `into` performed sign extension, we have to truncate
|
||||||
let r = Self::raw(size.truncate(data as u128), size);
|
let r = Self::raw(size.truncate(data as u128), size);
|
||||||
(r, size.sign_extend(r.data) as i128 != data)
|
(r, size.sign_extend(r.data) != data)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -335,7 +335,7 @@ impl ScalarInt {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_int(self, size: Size) -> i128 {
|
pub fn to_int(self, size: Size) -> i128 {
|
||||||
let b = self.to_bits(size);
|
let b = self.to_bits(size);
|
||||||
size.sign_extend(b) as i128
|
size.sign_extend(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the `ScalarInt` to i8.
|
/// Converts the `ScalarInt` to i8.
|
||||||
|
@ -79,7 +79,7 @@ impl<'tcx> Discr<'tcx> {
|
|||||||
let (val, oflo) = if signed {
|
let (val, oflo) = if signed {
|
||||||
let min = size.signed_int_min();
|
let min = size.signed_int_min();
|
||||||
let max = size.signed_int_max();
|
let max = size.signed_int_max();
|
||||||
let val = size.sign_extend(self.val) as i128;
|
let val = size.sign_extend(self.val);
|
||||||
assert!(n < (i128::MAX as u128));
|
assert!(n < (i128::MAX as u128));
|
||||||
let n = n as i128;
|
let n = n as i128;
|
||||||
let oflo = val > max - n;
|
let oflo = val > max - n;
|
||||||
|
@ -66,7 +66,7 @@ parse_box_not_pat = expected pattern, found {$descr}
|
|||||||
.suggestion = escape `box` to use it as an identifier
|
.suggestion = escape `box` to use it as an identifier
|
||||||
|
|
||||||
parse_box_syntax_removed = `box_syntax` has been removed
|
parse_box_syntax_removed = `box_syntax` has been removed
|
||||||
.suggestion = use `Box::new()` instead
|
parse_box_syntax_removed_suggestion = use `Box::new()` instead
|
||||||
|
|
||||||
parse_cannot_be_raw_ident = `{$ident}` cannot be a raw identifier
|
parse_cannot_be_raw_ident = `{$ident}` cannot be a raw identifier
|
||||||
|
|
||||||
|
@ -2725,15 +2725,24 @@ impl HelpUseLatestEdition {
|
|||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(parse_box_syntax_removed)]
|
#[diag(parse_box_syntax_removed)]
|
||||||
pub struct BoxSyntaxRemoved<'a> {
|
pub struct BoxSyntaxRemoved {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[suggestion(
|
|
||||||
code = "Box::new({code})",
|
|
||||||
applicability = "machine-applicable",
|
|
||||||
style = "verbose"
|
|
||||||
)]
|
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub code: &'a str,
|
#[subdiagnostic]
|
||||||
|
pub sugg: AddBoxNew,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
#[multipart_suggestion(
|
||||||
|
parse_box_syntax_removed_suggestion,
|
||||||
|
applicability = "machine-applicable",
|
||||||
|
style = "verbose"
|
||||||
|
)]
|
||||||
|
pub struct AddBoxNew {
|
||||||
|
#[suggestion_part(code = "Box::new(")]
|
||||||
|
pub box_kw_and_lo: Span,
|
||||||
|
#[suggestion_part(code = ")")]
|
||||||
|
pub hi: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -618,10 +618,12 @@ impl<'a> Parser<'a> {
|
|||||||
/// Parse `box expr` - this syntax has been removed, but we still parse this
|
/// Parse `box expr` - this syntax has been removed, but we still parse this
|
||||||
/// for now to provide a more useful error
|
/// for now to provide a more useful error
|
||||||
fn parse_expr_box(&mut self, box_kw: Span) -> PResult<'a, (Span, ExprKind)> {
|
fn parse_expr_box(&mut self, box_kw: Span) -> PResult<'a, (Span, ExprKind)> {
|
||||||
let (span, _) = self.parse_expr_prefix_common(box_kw)?;
|
let (span, expr) = self.parse_expr_prefix_common(box_kw)?;
|
||||||
let inner_span = span.with_lo(box_kw.hi());
|
// Make a multipart suggestion instead of `span_to_snippet` in case source isn't available
|
||||||
let code = self.psess.source_map().span_to_snippet(inner_span).unwrap();
|
let box_kw_and_lo = box_kw.until(self.interpolated_or_expr_span(&expr));
|
||||||
let guar = self.dcx().emit_err(errors::BoxSyntaxRemoved { span: span, code: code.trim() });
|
let hi = span.shrink_to_hi();
|
||||||
|
let sugg = errors::AddBoxNew { box_kw_and_lo, hi };
|
||||||
|
let guar = self.dcx().emit_err(errors::BoxSyntaxRemoved { span, sugg });
|
||||||
Ok((span, ExprKind::Err(guar)))
|
Ok((span, ExprKind::Err(guar)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,12 +171,13 @@
|
|||||||
/// still be live when `T` gets dropped. The exact details of this analysis are not yet
|
/// still be live when `T` gets dropped. The exact details of this analysis are not yet
|
||||||
/// stably guaranteed and **subject to change**. Currently, the analysis works as follows:
|
/// stably guaranteed and **subject to change**. Currently, the analysis works as follows:
|
||||||
/// - If `T` has no drop glue, then trivially nothing is required to be live. This is the case if
|
/// - If `T` has no drop glue, then trivially nothing is required to be live. This is the case if
|
||||||
/// neither `T` nor any of its (recursive) fields have a destructor (`impl Drop`). [`PhantomData`]
|
/// neither `T` nor any of its (recursive) fields have a destructor (`impl Drop`). [`PhantomData`],
|
||||||
/// and [`ManuallyDrop`] are considered to never have a destructor, no matter their field type.
|
/// arrays of length 0 and [`ManuallyDrop`] are considered to never have a destructor, no matter
|
||||||
|
/// their field type.
|
||||||
/// - If `T` has drop glue, then, for all types `U` that are *owned* by any field of `T`,
|
/// - If `T` has drop glue, then, for all types `U` that are *owned* by any field of `T`,
|
||||||
/// recursively add the types and lifetimes that need to be live when `U` gets dropped. The set of
|
/// recursively add the types and lifetimes that need to be live when `U` gets dropped. The set of
|
||||||
/// owned types is determined by recursively traversing `T`:
|
/// owned types is determined by recursively traversing `T`:
|
||||||
/// - Recursively descend through `PhantomData`, `Box`, tuples, and arrays (including arrays of
|
/// - Recursively descend through `PhantomData`, `Box`, tuples, and arrays (excluding arrays of
|
||||||
/// length 0).
|
/// length 0).
|
||||||
/// - Stop at reference and raw pointer types as well as function pointers and function items;
|
/// - Stop at reference and raw pointer types as well as function pointers and function items;
|
||||||
/// they do not own anything.
|
/// they do not own anything.
|
||||||
|
@ -500,13 +500,8 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.show_backtrace {
|
if self.show_backtrace {
|
||||||
let backtrace = self.backtrace();
|
if let Some(backtrace) = self.backtrace() {
|
||||||
|
write!(f, "\n\nStack backtrace:\n{}", backtrace.to_string().trim_end())?;
|
||||||
if let Some(backtrace) = backtrace {
|
|
||||||
let backtrace = backtrace.to_string();
|
|
||||||
|
|
||||||
f.write_str("\n\nStack backtrace:\n")?;
|
|
||||||
f.write_str(backtrace.trim_end())?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#![stable(feature = "rust1", since = "1.0.0")]
|
#![stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#![deny(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
#[allow(unused_extern_crates)]
|
#[allow(unused_extern_crates)]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
@ -1,31 +1,28 @@
|
|||||||
use super::hermit_abi;
|
use super::hermit_abi;
|
||||||
use crate::alloc::{GlobalAlloc, Layout, System};
|
use crate::alloc::{GlobalAlloc, Layout, System};
|
||||||
use crate::ptr;
|
|
||||||
|
|
||||||
#[stable(feature = "alloc_system_type", since = "1.28.0")]
|
#[stable(feature = "alloc_system_type", since = "1.28.0")]
|
||||||
unsafe impl GlobalAlloc for System {
|
unsafe impl GlobalAlloc for System {
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||||
hermit_abi::malloc(layout.size(), layout.align())
|
let size = layout.size();
|
||||||
}
|
let align = layout.align();
|
||||||
|
unsafe { hermit_abi::malloc(size, align) }
|
||||||
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
|
|
||||||
let addr = hermit_abi::malloc(layout.size(), layout.align());
|
|
||||||
|
|
||||||
if !addr.is_null() {
|
|
||||||
ptr::write_bytes(addr, 0x00, layout.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
addr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||||
hermit_abi::free(ptr, layout.size(), layout.align())
|
let size = layout.size();
|
||||||
|
let align = layout.align();
|
||||||
|
unsafe {
|
||||||
|
hermit_abi::free(ptr, size, align);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
|
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
|
||||||
hermit_abi::realloc(ptr, layout.size(), layout.align(), new_size)
|
let size = layout.size();
|
||||||
|
let align = layout.align();
|
||||||
|
unsafe { hermit_abi::realloc(ptr, size, align, new_size) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,8 @@ impl FromInner<OwnedFd> for FileDesc {
|
|||||||
|
|
||||||
impl FromRawFd for FileDesc {
|
impl FromRawFd for FileDesc {
|
||||||
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
|
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
|
||||||
Self { fd: FromRawFd::from_raw_fd(raw_fd) }
|
let fd = unsafe { OwnedFd::from_raw_fd(raw_fd) };
|
||||||
|
Self { fd }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,7 +484,8 @@ impl IntoRawFd for File {
|
|||||||
|
|
||||||
impl FromRawFd for File {
|
impl FromRawFd for File {
|
||||||
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
|
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
|
||||||
Self(FromRawFd::from_raw_fd(raw_fd))
|
let file_desc = unsafe { FileDesc::from_raw_fd(raw_fd) };
|
||||||
|
Self(file_desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
//! compiling for wasm. That way it's a compile time error for something that's
|
//! compiling for wasm. That way it's a compile time error for something that's
|
||||||
//! guaranteed to be a runtime error!
|
//! guaranteed to be a runtime error!
|
||||||
|
|
||||||
#![allow(missing_docs, nonstandard_style, unsafe_op_in_unsafe_fn)]
|
#![deny(unsafe_op_in_unsafe_fn)]
|
||||||
|
#![allow(missing_docs, nonstandard_style)]
|
||||||
|
|
||||||
use crate::os::raw::c_char;
|
use crate::os::raw::c_char;
|
||||||
|
|
||||||
@ -49,9 +50,7 @@ pub fn unsupported_err() -> crate::io::Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn abort_internal() -> ! {
|
pub fn abort_internal() -> ! {
|
||||||
unsafe {
|
unsafe { hermit_abi::abort() }
|
||||||
hermit_abi::abort();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hashmap_random_keys() -> (u64, u64) {
|
pub fn hashmap_random_keys() -> (u64, u64) {
|
||||||
@ -80,7 +79,9 @@ pub extern "C" fn __rust_abort() {
|
|||||||
// SAFETY: must be called only once during runtime initialization.
|
// SAFETY: must be called only once during runtime initialization.
|
||||||
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
|
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
|
||||||
pub unsafe fn init(argc: isize, argv: *const *const u8, _sigpipe: u8) {
|
pub unsafe fn init(argc: isize, argv: *const *const u8, _sigpipe: u8) {
|
||||||
args::init(argc, argv);
|
unsafe {
|
||||||
|
args::init(argc, argv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SAFETY: must be called only once during runtime cleanup.
|
// SAFETY: must be called only once during runtime cleanup.
|
||||||
@ -101,10 +102,12 @@ pub unsafe extern "C" fn runtime_entry(
|
|||||||
// initialize environment
|
// initialize environment
|
||||||
os::init_environment(env as *const *const i8);
|
os::init_environment(env as *const *const i8);
|
||||||
|
|
||||||
let result = main(argc as isize, argv);
|
let result = unsafe { main(argc as isize, argv) };
|
||||||
|
|
||||||
crate::sys::thread_local::destructors::run();
|
unsafe {
|
||||||
hermit_abi::exit(result);
|
crate::sys::thread_local::destructors::run();
|
||||||
|
}
|
||||||
|
unsafe { hermit_abi::exit(result) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -68,21 +68,21 @@ pub fn current_exe() -> io::Result<PathBuf> {
|
|||||||
unsupported()
|
unsupported()
|
||||||
}
|
}
|
||||||
|
|
||||||
static mut ENV: Option<Mutex<HashMap<OsString, OsString>>> = None;
|
static ENV: Mutex<Option<HashMap<OsString, OsString>>> = Mutex::new(None);
|
||||||
|
|
||||||
pub fn init_environment(env: *const *const i8) {
|
pub fn init_environment(env: *const *const i8) {
|
||||||
|
let mut guard = ENV.lock().unwrap();
|
||||||
|
let map = guard.insert(HashMap::new());
|
||||||
|
|
||||||
|
if env.is_null() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
ENV = Some(Mutex::new(HashMap::new()));
|
|
||||||
|
|
||||||
if env.is_null() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut guard = ENV.as_ref().unwrap().lock().unwrap();
|
|
||||||
let mut environ = env;
|
let mut environ = env;
|
||||||
while !(*environ).is_null() {
|
while !(*environ).is_null() {
|
||||||
if let Some((key, value)) = parse(CStr::from_ptr(*environ).to_bytes()) {
|
if let Some((key, value)) = parse(CStr::from_ptr(*environ).to_bytes()) {
|
||||||
guard.insert(key, value);
|
map.insert(key, value);
|
||||||
}
|
}
|
||||||
environ = environ.add(1);
|
environ = environ.add(1);
|
||||||
}
|
}
|
||||||
@ -154,30 +154,26 @@ impl Iterator for Env {
|
|||||||
/// Returns a vector of (variable, value) byte-vector pairs for all the
|
/// Returns a vector of (variable, value) byte-vector pairs for all the
|
||||||
/// environment variables of the current process.
|
/// environment variables of the current process.
|
||||||
pub fn env() -> Env {
|
pub fn env() -> Env {
|
||||||
unsafe {
|
let guard = ENV.lock().unwrap();
|
||||||
let guard = ENV.as_ref().unwrap().lock().unwrap();
|
let env = guard.as_ref().unwrap();
|
||||||
let mut result = Vec::new();
|
|
||||||
|
|
||||||
for (key, value) in guard.iter() {
|
let result = env.iter().map(|(key, value)| (key.clone(), value.clone())).collect::<Vec<_>>();
|
||||||
result.push((key.clone(), value.clone()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Env { iter: result.into_iter() };
|
Env { iter: result.into_iter() }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getenv(k: &OsStr) -> Option<OsString> {
|
pub fn getenv(k: &OsStr) -> Option<OsString> {
|
||||||
unsafe { ENV.as_ref().unwrap().lock().unwrap().get_mut(k).cloned() }
|
ENV.lock().unwrap().as_ref().unwrap().get(k).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
|
pub unsafe fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
|
||||||
let (k, v) = (k.to_owned(), v.to_owned());
|
let (k, v) = (k.to_owned(), v.to_owned());
|
||||||
ENV.as_ref().unwrap().lock().unwrap().insert(k, v);
|
ENV.lock().unwrap().as_mut().unwrap().insert(k, v);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn unsetenv(k: &OsStr) -> io::Result<()> {
|
pub unsafe fn unsetenv(k: &OsStr) -> io::Result<()> {
|
||||||
ENV.as_ref().unwrap().lock().unwrap().remove(k);
|
ENV.lock().unwrap().as_mut().unwrap().remove(k);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,9 +186,7 @@ pub fn home_dir() -> Option<PathBuf> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn exit(code: i32) -> ! {
|
pub fn exit(code: i32) -> ! {
|
||||||
unsafe {
|
unsafe { hermit_abi::exit(code) }
|
||||||
hermit_abi::exit(code);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getpid() -> u32 {
|
pub fn getpid() -> u32 {
|
||||||
|
@ -25,18 +25,22 @@ impl Thread {
|
|||||||
core_id: isize,
|
core_id: isize,
|
||||||
) -> io::Result<Thread> {
|
) -> io::Result<Thread> {
|
||||||
let p = Box::into_raw(Box::new(p));
|
let p = Box::into_raw(Box::new(p));
|
||||||
let tid = hermit_abi::spawn2(
|
let tid = unsafe {
|
||||||
thread_start,
|
hermit_abi::spawn2(
|
||||||
p.expose_provenance(),
|
thread_start,
|
||||||
hermit_abi::Priority::into(hermit_abi::NORMAL_PRIO),
|
p.expose_provenance(),
|
||||||
stack,
|
hermit_abi::Priority::into(hermit_abi::NORMAL_PRIO),
|
||||||
core_id,
|
stack,
|
||||||
);
|
core_id,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
return if tid == 0 {
|
return if tid == 0 {
|
||||||
// The thread failed to start and as a result p was not consumed. Therefore, it is
|
// The thread failed to start and as a result p was not consumed. Therefore, it is
|
||||||
// safe to reconstruct the box so that it gets deallocated.
|
// safe to reconstruct the box so that it gets deallocated.
|
||||||
drop(Box::from_raw(p));
|
unsafe {
|
||||||
|
drop(Box::from_raw(p));
|
||||||
|
}
|
||||||
Err(io::const_io_error!(io::ErrorKind::Uncategorized, "Unable to create thread!"))
|
Err(io::const_io_error!(io::ErrorKind::Uncategorized, "Unable to create thread!"))
|
||||||
} else {
|
} else {
|
||||||
Ok(Thread { tid: tid })
|
Ok(Thread { tid: tid })
|
||||||
@ -54,7 +58,9 @@ impl Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
|
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
|
||||||
Thread::new_with_coreid(stack, p, -1 /* = no specific core */)
|
unsafe {
|
||||||
|
Thread::new_with_coreid(stack, p, -1 /* = no specific core */)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -65,6 +65,7 @@
|
|||||||
- [riscv32im-risc0-zkvm-elf](platform-support/riscv32im-risc0-zkvm-elf.md)
|
- [riscv32im-risc0-zkvm-elf](platform-support/riscv32im-risc0-zkvm-elf.md)
|
||||||
- [riscv32imac-unknown-xous-elf](platform-support/riscv32imac-unknown-xous-elf.md)
|
- [riscv32imac-unknown-xous-elf](platform-support/riscv32imac-unknown-xous-elf.md)
|
||||||
- [riscv32*-unknown-none-elf](platform-support/riscv32-unknown-none-elf.md)
|
- [riscv32*-unknown-none-elf](platform-support/riscv32-unknown-none-elf.md)
|
||||||
|
- [riscv64gc-unknown-linux-gnu](platform-support/riscv64gc-unknown-linux-gnu.md)
|
||||||
- [sparc-unknown-none-elf](./platform-support/sparc-unknown-none-elf.md)
|
- [sparc-unknown-none-elf](./platform-support/sparc-unknown-none-elf.md)
|
||||||
- [*-pc-windows-gnullvm](platform-support/pc-windows-gnullvm.md)
|
- [*-pc-windows-gnullvm](platform-support/pc-windows-gnullvm.md)
|
||||||
- [\*-nto-qnx-\*](platform-support/nto-qnx.md)
|
- [\*-nto-qnx-\*](platform-support/nto-qnx.md)
|
||||||
|
@ -97,7 +97,7 @@ target | notes
|
|||||||
`powerpc-unknown-linux-gnu` | PowerPC Linux (kernel 3.2, glibc 2.17)
|
`powerpc-unknown-linux-gnu` | PowerPC Linux (kernel 3.2, glibc 2.17)
|
||||||
`powerpc64-unknown-linux-gnu` | PPC64 Linux (kernel 3.2, glibc 2.17)
|
`powerpc64-unknown-linux-gnu` | PPC64 Linux (kernel 3.2, glibc 2.17)
|
||||||
`powerpc64le-unknown-linux-gnu` | PPC64LE Linux (kernel 3.10, glibc 2.17)
|
`powerpc64le-unknown-linux-gnu` | PPC64LE Linux (kernel 3.10, glibc 2.17)
|
||||||
`riscv64gc-unknown-linux-gnu` | RISC-V Linux (kernel 4.20, glibc 2.29)
|
[`riscv64gc-unknown-linux-gnu`](platform-support/riscv64gc-unknown-linux-gnu.md) | RISC-V Linux (kernel 4.20, glibc 2.29)
|
||||||
`s390x-unknown-linux-gnu` | S390x Linux (kernel 3.2, glibc 2.17)
|
`s390x-unknown-linux-gnu` | S390x Linux (kernel 3.2, glibc 2.17)
|
||||||
`x86_64-unknown-freebsd` | 64-bit FreeBSD
|
`x86_64-unknown-freebsd` | 64-bit FreeBSD
|
||||||
`x86_64-unknown-illumos` | illumos
|
`x86_64-unknown-illumos` | illumos
|
||||||
|
@ -0,0 +1,129 @@
|
|||||||
|
# `riscv64gc-unknown-linux-gnu`
|
||||||
|
|
||||||
|
**Tier: 2 (with Host Tools)**
|
||||||
|
|
||||||
|
RISC-V targets using the *RV64I* base instruction set with the *G* collection of extensions, as well as the *C* extension.
|
||||||
|
|
||||||
|
|
||||||
|
## Target maintainers
|
||||||
|
|
||||||
|
- Kito Cheng, <kito.cheng@gmail.com>, [@kito-cheng](https://github.com/kito-cheng)
|
||||||
|
- Michael Maitland, <michaeltmaitland@gmail.com>, [@michaelmaitland](https://github.com/michaelmaitland)
|
||||||
|
- Robin Randhawa, <robin.randhawa@sifive.com>, [@robin-randhawa-sifive](https://github.com/robin-randhawa-sifive)
|
||||||
|
- Craig Topper, <craig.topper@sifive.com>, [@topperc](https://github.com/topperc)
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
This target requires:
|
||||||
|
|
||||||
|
* Linux Kernel version 4.20 or later
|
||||||
|
* glibc 2.17 or later
|
||||||
|
|
||||||
|
|
||||||
|
## Building the target
|
||||||
|
|
||||||
|
These targets are distributed through `rustup`, and otherwise require no
|
||||||
|
special configuration.
|
||||||
|
|
||||||
|
If you need to build your own Rust for some reason though, the targets can be
|
||||||
|
enabled in `config.toml`. For example:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[build]
|
||||||
|
target = ["riscv64gc-unknown-linux-gnu"]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Building Rust programs
|
||||||
|
|
||||||
|
|
||||||
|
On a RISC-V host, the `riscv64gc-unknown-linux-gnu` target should be automatically
|
||||||
|
installed and used by default.
|
||||||
|
|
||||||
|
On a non-RISC-V host, add the target:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
rustup target add riscv64gc-unknown-linux-gnu
|
||||||
|
```
|
||||||
|
|
||||||
|
Then cross compile crates with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo build --target riscv64gc-unknown-linux-gnu
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
There are no special requirements for testing and running the targets.
|
||||||
|
For testing cross builds on the host, please refer to the "Cross-compilation
|
||||||
|
toolchains and C code"
|
||||||
|
section below.
|
||||||
|
|
||||||
|
|
||||||
|
## Cross-compilation toolchains and C code
|
||||||
|
|
||||||
|
A RISC-V toolchain can be obtained for Windows/Mac/Linux from the
|
||||||
|
[`riscv-gnu-toolchain`](https://github.com/riscv-collab/riscv-gnu-toolchain)
|
||||||
|
repostory. Binaries are available via
|
||||||
|
[embecosm](https://www.embecosm.com/resources/tool-chain-downloads/#riscv-linux),
|
||||||
|
and may also be available from your OS's package manager.
|
||||||
|
|
||||||
|
On Ubuntu, a RISC-V toolchain can be installed with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
apt install gcc-riscv64-linux-gnu g++-riscv64-linux-gnu libc6-dev-riscv64-cross
|
||||||
|
```
|
||||||
|
|
||||||
|
Depending on your system, you may need to configure the target to use the GNU
|
||||||
|
GCC linker. To use it, add the following to your `.cargo/config.toml`:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[target.riscv64gc-unknown-linux-gnu]
|
||||||
|
linker = "riscv64-linux-gnu-gcc"
|
||||||
|
```
|
||||||
|
|
||||||
|
If your `riscv64-linux-gnu-*` toolchain is not in your `PATH` you may need to
|
||||||
|
configure additional settings:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[target.riscv64gc-unknown-linux-gnu]
|
||||||
|
# Adjust the paths to point at your toolchain
|
||||||
|
cc = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-gcc"
|
||||||
|
cxx = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-g++"
|
||||||
|
ar = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-ar"
|
||||||
|
ranlib = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-ranlib"
|
||||||
|
linker = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-gcc"
|
||||||
|
```
|
||||||
|
|
||||||
|
To test cross compiled binaries on a non-RISCV-V host, you can use
|
||||||
|
[`qemu`](https://www.qemu.org/docs/master/system/target-riscv.html).
|
||||||
|
On Ubuntu, a RISC-V emulator can be obtained with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
apt install qemu-system-riscv64
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, in `.cargo/config.toml` set the `runner`:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[target.riscv64gc-unknown-linux-gnu]
|
||||||
|
runner = "qemu-riscv64-static -L /usr/riscv64-linux-gnu -cpu rv64"
|
||||||
|
```
|
||||||
|
|
||||||
|
On Mac and Linux, it's also possible to use
|
||||||
|
[`lima`](https://github.com/lima-vm/lima) to emulate RISC-V in a similar way to
|
||||||
|
how WSL2 works on Windows:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
limactl start template://riscv
|
||||||
|
limactl shell riscv
|
||||||
|
```
|
||||||
|
|
||||||
|
Using [Docker (with BuildKit)](https://docs.docker.com/build/buildkit/) the
|
||||||
|
[`riscv64/ubuntu`](https://hub.docker.com/r/riscv64/ubuntu) image can be used
|
||||||
|
to buiild or run `riscv64gc-unknown-linux-gnu` binaries.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --platform linux/riscv64 -ti --rm --mount "type=bind,src=$(pwd),dst=/checkout" riscv64/ubuntu bash
|
||||||
|
```
|
@ -11,7 +11,7 @@ use rand::Rng;
|
|||||||
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_target::abi::{Align, HasDataLayout, Size};
|
use rustc_target::abi::{Align, Size};
|
||||||
|
|
||||||
use crate::{concurrency::VClock, *};
|
use crate::{concurrency::VClock, *};
|
||||||
|
|
||||||
@ -105,15 +105,17 @@ impl<'tcx> EvalContextExtPriv<'tcx> for crate::MiriInterpCx<'tcx> {}
|
|||||||
trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||||
// Returns the exposed `AllocId` that corresponds to the specified addr,
|
// Returns the exposed `AllocId` that corresponds to the specified addr,
|
||||||
// or `None` if the addr is out of bounds
|
// or `None` if the addr is out of bounds
|
||||||
fn alloc_id_from_addr(&self, addr: u64) -> Option<AllocId> {
|
fn alloc_id_from_addr(&self, addr: u64, size: i64) -> Option<AllocId> {
|
||||||
let ecx = self.eval_context_ref();
|
let ecx = self.eval_context_ref();
|
||||||
let global_state = ecx.machine.alloc_addresses.borrow();
|
let global_state = ecx.machine.alloc_addresses.borrow();
|
||||||
assert!(global_state.provenance_mode != ProvenanceMode::Strict);
|
assert!(global_state.provenance_mode != ProvenanceMode::Strict);
|
||||||
|
|
||||||
|
// We always search the allocation to the right of this address. So if the size is structly
|
||||||
|
// negative, we have to search for `addr-1` instead.
|
||||||
|
let addr = if size >= 0 { addr } else { addr.saturating_sub(1) };
|
||||||
let pos = global_state.int_to_ptr_map.binary_search_by_key(&addr, |(addr, _)| *addr);
|
let pos = global_state.int_to_ptr_map.binary_search_by_key(&addr, |(addr, _)| *addr);
|
||||||
|
|
||||||
// Determine the in-bounds provenance for this pointer.
|
// Determine the in-bounds provenance for this pointer.
|
||||||
// (This is only called on an actual access, so in-bounds is the only possible kind of provenance.)
|
|
||||||
let alloc_id = match pos {
|
let alloc_id = match pos {
|
||||||
Ok(pos) => Some(global_state.int_to_ptr_map[pos].1),
|
Ok(pos) => Some(global_state.int_to_ptr_map[pos].1),
|
||||||
Err(0) => None,
|
Err(0) => None,
|
||||||
@ -305,20 +307,24 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
|
|
||||||
let (prov, offset) = ptr.into_parts(); // offset is relative (AllocId provenance)
|
let (prov, offset) = ptr.into_parts(); // offset is relative (AllocId provenance)
|
||||||
let alloc_id = prov.alloc_id();
|
let alloc_id = prov.alloc_id();
|
||||||
let base_addr = ecx.addr_from_alloc_id(alloc_id, kind)?;
|
|
||||||
|
|
||||||
// Add offset with the right kind of pointer-overflowing arithmetic.
|
// Get a pointer to the beginning of this allocation.
|
||||||
let dl = ecx.data_layout();
|
let base_addr = ecx.addr_from_alloc_id(alloc_id, kind)?;
|
||||||
let absolute_addr = dl.overflowing_offset(base_addr, offset.bytes()).0;
|
let base_ptr = interpret::Pointer::new(
|
||||||
Ok(interpret::Pointer::new(
|
|
||||||
Provenance::Concrete { alloc_id, tag },
|
Provenance::Concrete { alloc_id, tag },
|
||||||
Size::from_bytes(absolute_addr),
|
Size::from_bytes(base_addr),
|
||||||
))
|
);
|
||||||
|
// Add offset with the right kind of pointer-overflowing arithmetic.
|
||||||
|
Ok(base_ptr.wrapping_offset(offset, ecx))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// When a pointer is used for a memory access, this computes where in which allocation the
|
/// When a pointer is used for a memory access, this computes where in which allocation the
|
||||||
/// access is going.
|
/// access is going.
|
||||||
fn ptr_get_alloc(&self, ptr: interpret::Pointer<Provenance>) -> Option<(AllocId, Size)> {
|
fn ptr_get_alloc(
|
||||||
|
&self,
|
||||||
|
ptr: interpret::Pointer<Provenance>,
|
||||||
|
size: i64,
|
||||||
|
) -> Option<(AllocId, Size)> {
|
||||||
let ecx = self.eval_context_ref();
|
let ecx = self.eval_context_ref();
|
||||||
|
|
||||||
let (tag, addr) = ptr.into_parts(); // addr is absolute (Tag provenance)
|
let (tag, addr) = ptr.into_parts(); // addr is absolute (Tag provenance)
|
||||||
@ -327,7 +333,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
alloc_id
|
alloc_id
|
||||||
} else {
|
} else {
|
||||||
// A wildcard pointer.
|
// A wildcard pointer.
|
||||||
ecx.alloc_id_from_addr(addr.bytes())?
|
ecx.alloc_id_from_addr(addr.bytes(), size)?
|
||||||
};
|
};
|
||||||
|
|
||||||
// This cannot fail: since we already have a pointer with that provenance, adjust_alloc_root_pointer
|
// This cannot fail: since we already have a pointer with that provenance, adjust_alloc_root_pointer
|
||||||
@ -335,12 +341,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
let base_addr = *ecx.machine.alloc_addresses.borrow().base_addr.get(&alloc_id).unwrap();
|
let base_addr = *ecx.machine.alloc_addresses.borrow().base_addr.get(&alloc_id).unwrap();
|
||||||
|
|
||||||
// Wrapping "addr - base_addr"
|
// Wrapping "addr - base_addr"
|
||||||
#[allow(clippy::cast_possible_wrap)] // we want to wrap here
|
let rel_offset = ecx.truncate_to_target_usize(addr.bytes().wrapping_sub(base_addr));
|
||||||
let neg_base_addr = (base_addr as i64).wrapping_neg();
|
Some((alloc_id, Size::from_bytes(rel_offset)))
|
||||||
Some((
|
|
||||||
alloc_id,
|
|
||||||
Size::from_bytes(ecx.overflowing_signed_offset(addr.bytes(), neg_base_addr).0),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,7 +673,7 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
// attempt to use it for a non-zero-sized access.
|
// attempt to use it for a non-zero-sized access.
|
||||||
// Dangling slices are a common case here; it's valid to get their length but with raw
|
// Dangling slices are a common case here; it's valid to get their length but with raw
|
||||||
// pointer tagging for example all calls to get_unchecked on them are invalid.
|
// pointer tagging for example all calls to get_unchecked on them are invalid.
|
||||||
if let Ok((alloc_id, base_offset, orig_tag)) = this.ptr_try_get_alloc_id(place.ptr()) {
|
if let Ok((alloc_id, base_offset, orig_tag)) = this.ptr_try_get_alloc_id(place.ptr(), 0) {
|
||||||
log_creation(this, Some((alloc_id, base_offset, orig_tag)))?;
|
log_creation(this, Some((alloc_id, base_offset, orig_tag)))?;
|
||||||
// Still give it the new provenance, it got retagged after all.
|
// Still give it the new provenance, it got retagged after all.
|
||||||
return Ok(Some(Provenance::Concrete { alloc_id, tag: new_tag }));
|
return Ok(Some(Provenance::Concrete { alloc_id, tag: new_tag }));
|
||||||
@ -685,7 +685,7 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (alloc_id, base_offset, orig_tag) = this.ptr_get_alloc_id(place.ptr())?;
|
let (alloc_id, base_offset, orig_tag) = this.ptr_get_alloc_id(place.ptr(), 0)?;
|
||||||
log_creation(this, Some((alloc_id, base_offset, orig_tag)))?;
|
log_creation(this, Some((alloc_id, base_offset, orig_tag)))?;
|
||||||
|
|
||||||
trace!(
|
trace!(
|
||||||
|
@ -223,7 +223,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
trace!("Reborrow of size {:?}", ptr_size);
|
trace!("Reborrow of size {:?}", ptr_size);
|
||||||
let (alloc_id, base_offset, parent_prov) = match this.ptr_try_get_alloc_id(place.ptr()) {
|
let (alloc_id, base_offset, parent_prov) = match this.ptr_try_get_alloc_id(place.ptr(), 0) {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
// Unlike SB, we *do* a proper retag for size 0 if can identify the allocation.
|
// Unlike SB, we *do* a proper retag for size 0 if can identify the allocation.
|
||||||
// After all, the pointer may be lazily initialized outside this initial range.
|
// After all, the pointer may be lazily initialized outside this initial range.
|
||||||
|
@ -1180,7 +1180,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
|
|||||||
// We avoid `get_ptr_alloc` since we do *not* want to run the access hooks -- the actual
|
// We avoid `get_ptr_alloc` since we do *not* want to run the access hooks -- the actual
|
||||||
// access will happen later.
|
// access will happen later.
|
||||||
let (alloc_id, _offset, _prov) = this
|
let (alloc_id, _offset, _prov) = this
|
||||||
.ptr_try_get_alloc_id(place.ptr())
|
.ptr_try_get_alloc_id(place.ptr(), 0)
|
||||||
.expect("there are no zero-sized atomic accesses");
|
.expect("there are no zero-sized atomic accesses");
|
||||||
if this.get_alloc_mutability(alloc_id)? == Mutability::Not {
|
if this.get_alloc_mutability(alloc_id)? == Mutability::Not {
|
||||||
// See if this is fine.
|
// See if this is fine.
|
||||||
@ -1307,7 +1307,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
|
|||||||
if let Some(data_race) = &this.machine.data_race {
|
if let Some(data_race) = &this.machine.data_race {
|
||||||
if data_race.race_detecting() {
|
if data_race.race_detecting() {
|
||||||
let size = place.layout.size;
|
let size = place.layout.size;
|
||||||
let (alloc_id, base_offset, _prov) = this.ptr_get_alloc_id(place.ptr())?;
|
let (alloc_id, base_offset, _prov) = this.ptr_get_alloc_id(place.ptr(), 0)?;
|
||||||
// Load and log the atomic operation.
|
// Load and log the atomic operation.
|
||||||
// Note that atomic loads are possible even from read-only allocations, so `get_alloc_extra_mut` is not an option.
|
// Note that atomic loads are possible even from read-only allocations, so `get_alloc_extra_mut` is not an option.
|
||||||
let alloc_meta = this.get_alloc_extra(alloc_id)?.data_race.as_ref().unwrap();
|
let alloc_meta = this.get_alloc_extra(alloc_id)?.data_race.as_ref().unwrap();
|
||||||
|
@ -468,7 +468,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
init: Scalar,
|
init: Scalar,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
let this = self.eval_context_mut();
|
let this = self.eval_context_mut();
|
||||||
let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(place.ptr())?;
|
let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(place.ptr(), 0)?;
|
||||||
if let (
|
if let (
|
||||||
crate::AllocExtra { weak_memory: Some(alloc_buffers), .. },
|
crate::AllocExtra { weak_memory: Some(alloc_buffers), .. },
|
||||||
crate::MiriMachine { data_race: Some(global), threads, .. },
|
crate::MiriMachine { data_race: Some(global), threads, .. },
|
||||||
@ -495,7 +495,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
) -> InterpResult<'tcx, Scalar> {
|
) -> InterpResult<'tcx, Scalar> {
|
||||||
let this = self.eval_context_ref();
|
let this = self.eval_context_ref();
|
||||||
if let Some(global) = &this.machine.data_race {
|
if let Some(global) = &this.machine.data_race {
|
||||||
let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(place.ptr())?;
|
let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(place.ptr(), 0)?;
|
||||||
if let Some(alloc_buffers) = this.get_alloc_extra(alloc_id)?.weak_memory.as_ref() {
|
if let Some(alloc_buffers) = this.get_alloc_extra(alloc_id)?.weak_memory.as_ref() {
|
||||||
if atomic == AtomicReadOrd::SeqCst {
|
if atomic == AtomicReadOrd::SeqCst {
|
||||||
global.sc_read(&this.machine.threads);
|
global.sc_read(&this.machine.threads);
|
||||||
@ -535,7 +535,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
init: Scalar,
|
init: Scalar,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
let this = self.eval_context_mut();
|
let this = self.eval_context_mut();
|
||||||
let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(dest.ptr())?;
|
let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(dest.ptr(), 0)?;
|
||||||
if let (
|
if let (
|
||||||
crate::AllocExtra { weak_memory: Some(alloc_buffers), .. },
|
crate::AllocExtra { weak_memory: Some(alloc_buffers), .. },
|
||||||
crate::MiriMachine { data_race: Some(global), threads, .. },
|
crate::MiriMachine { data_race: Some(global), threads, .. },
|
||||||
@ -585,7 +585,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
global.sc_read(&this.machine.threads);
|
global.sc_read(&this.machine.threads);
|
||||||
}
|
}
|
||||||
let size = place.layout.size;
|
let size = place.layout.size;
|
||||||
let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(place.ptr())?;
|
let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(place.ptr(), 0)?;
|
||||||
if let Some(alloc_buffers) = this.get_alloc_extra(alloc_id)?.weak_memory.as_ref() {
|
if let Some(alloc_buffers) = this.get_alloc_extra(alloc_id)?.weak_memory.as_ref() {
|
||||||
let buffer = alloc_buffers
|
let buffer = alloc_buffers
|
||||||
.get_or_create_store_buffer(alloc_range(base_offset, size), init)?;
|
.get_or_create_store_buffer(alloc_range(base_offset, size), init)?;
|
||||||
|
@ -606,7 +606,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
}
|
}
|
||||||
// The part between the end_ptr and the end of the place is also frozen.
|
// The part between the end_ptr and the end of the place is also frozen.
|
||||||
// So pretend there is a 0-sized `UnsafeCell` at the end.
|
// So pretend there is a 0-sized `UnsafeCell` at the end.
|
||||||
unsafe_cell_action(&place.ptr().offset(size, this)?, Size::ZERO)?;
|
unsafe_cell_action(&place.ptr().wrapping_offset(size, this), Size::ZERO)?;
|
||||||
// Done!
|
// Done!
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
||||||
@ -975,7 +975,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
loop {
|
loop {
|
||||||
// FIXME: We are re-getting the allocation each time around the loop.
|
// FIXME: We are re-getting the allocation each time around the loop.
|
||||||
// Would be nice if we could somehow "extend" an existing AllocRange.
|
// Would be nice if we could somehow "extend" an existing AllocRange.
|
||||||
let alloc = this.get_ptr_alloc(ptr.offset(len, this)?, size1)?.unwrap(); // not a ZST, so we will get a result
|
let alloc = this.get_ptr_alloc(ptr.wrapping_offset(len, this), size1)?.unwrap(); // not a ZST, so we will get a result
|
||||||
let byte = alloc.read_integer(alloc_range(Size::ZERO, size1))?.to_u8()?;
|
let byte = alloc.read_integer(alloc_range(Size::ZERO, size1))?.to_u8()?;
|
||||||
if byte == 0 {
|
if byte == 0 {
|
||||||
break;
|
break;
|
||||||
@ -1039,7 +1039,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
wchars.push(wchar_int.try_into().unwrap());
|
wchars.push(wchar_int.try_into().unwrap());
|
||||||
ptr = ptr.offset(size, this)?;
|
ptr = ptr.wrapping_offset(size, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1198,19 +1198,23 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a pointer with provenance into an allocation-offset pair,
|
/// Convert a pointer with provenance into an allocation-offset pair and extra provenance info.
|
||||||
/// or a `None` with an absolute address if that conversion is not possible.
|
/// `size` says how many bytes of memory are expected at that pointer. The *sign* of `size` can
|
||||||
|
/// be used to disambiguate situations where a wildcard pointer sits right in between two
|
||||||
|
/// allocations.
|
||||||
///
|
///
|
||||||
/// This is called when a pointer is about to be used for memory access,
|
/// If `ptr.provenance.get_alloc_id()` is `Some(p)`, the returned `AllocId` must be `p`.
|
||||||
/// an in-bounds check, or anything else that requires knowing which allocation it points to.
|
|
||||||
/// The resulting `AllocId` will just be used for that one step and the forgotten again
|
/// The resulting `AllocId` will just be used for that one step and the forgotten again
|
||||||
/// (i.e., we'll never turn the data returned here back into a `Pointer` that might be
|
/// (i.e., we'll never turn the data returned here back into a `Pointer` that might be
|
||||||
/// stored in machine state).
|
/// stored in machine state).
|
||||||
|
///
|
||||||
|
/// When this fails, that means the pointer does not point to a live allocation.
|
||||||
fn ptr_get_alloc(
|
fn ptr_get_alloc(
|
||||||
ecx: &MiriInterpCx<'tcx>,
|
ecx: &MiriInterpCx<'tcx>,
|
||||||
ptr: StrictPointer,
|
ptr: StrictPointer,
|
||||||
|
size: i64,
|
||||||
) -> Option<(AllocId, Size, Self::ProvenanceExtra)> {
|
) -> Option<(AllocId, Size, Self::ProvenanceExtra)> {
|
||||||
let rel = ecx.ptr_get_alloc(ptr);
|
let rel = ecx.ptr_get_alloc(ptr, size);
|
||||||
|
|
||||||
rel.map(|(alloc_id, size)| {
|
rel.map(|(alloc_id, size)| {
|
||||||
let tag = match ptr.provenance {
|
let tag = match ptr.provenance {
|
||||||
|
@ -116,7 +116,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
|
|
||||||
let ptr = this.read_pointer(ptr)?;
|
let ptr = this.read_pointer(ptr)?;
|
||||||
// Take apart the pointer, we need its pieces. The offset encodes the span.
|
// Take apart the pointer, we need its pieces. The offset encodes the span.
|
||||||
let (alloc_id, offset, _prov) = this.ptr_get_alloc_id(ptr)?;
|
let (alloc_id, offset, _prov) = this.ptr_get_alloc_id(ptr, 0)?;
|
||||||
|
|
||||||
// This has to be an actual global fn ptr, not a dlsym function.
|
// This has to be an actual global fn ptr, not a dlsym function.
|
||||||
let fn_instance = if let Some(GlobalAlloc::Function { instance, .. }) =
|
let fn_instance = if let Some(GlobalAlloc::Function { instance, .. }) =
|
||||||
|
@ -278,7 +278,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
"miri_get_alloc_id" => {
|
"miri_get_alloc_id" => {
|
||||||
let [ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?;
|
let [ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?;
|
||||||
let ptr = this.read_pointer(ptr)?;
|
let ptr = this.read_pointer(ptr)?;
|
||||||
let (alloc_id, _, _) = this.ptr_get_alloc_id(ptr).map_err(|_e| {
|
let (alloc_id, _, _) = this.ptr_get_alloc_id(ptr, 0).map_err(|_e| {
|
||||||
err_machine_stop!(TerminationInfo::Abort(format!(
|
err_machine_stop!(TerminationInfo::Abort(format!(
|
||||||
"pointer passed to `miri_get_alloc_id` must not be dangling, got {ptr:?}"
|
"pointer passed to `miri_get_alloc_id` must not be dangling, got {ptr:?}"
|
||||||
)))
|
)))
|
||||||
@ -311,7 +311,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
"miri_static_root" => {
|
"miri_static_root" => {
|
||||||
let [ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?;
|
let [ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?;
|
||||||
let ptr = this.read_pointer(ptr)?;
|
let ptr = this.read_pointer(ptr)?;
|
||||||
let (alloc_id, offset, _) = this.ptr_get_alloc_id(ptr)?;
|
let (alloc_id, offset, _) = this.ptr_get_alloc_id(ptr, 0)?;
|
||||||
if offset != Size::ZERO {
|
if offset != Size::ZERO {
|
||||||
throw_unsup_format!(
|
throw_unsup_format!(
|
||||||
"pointer passed to `miri_static_root` must point to beginning of an allocated block"
|
"pointer passed to `miri_static_root` must point to beginning of an allocated block"
|
||||||
@ -392,7 +392,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
"`miri_promise_symbolic_alignment`: pointer is not actually aligned"
|
"`miri_promise_symbolic_alignment`: pointer is not actually aligned"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Ok((alloc_id, offset, ..)) = this.ptr_try_get_alloc_id(ptr) {
|
if let Ok((alloc_id, offset, ..)) = this.ptr_try_get_alloc_id(ptr, 0) {
|
||||||
let (_size, alloc_align, _kind) = this.get_alloc_info(alloc_id);
|
let (_size, alloc_align, _kind) = this.get_alloc_info(alloc_id);
|
||||||
// If the newly promised alignment is bigger than the native alignment of this
|
// If the newly promised alignment is bigger than the native alignment of this
|
||||||
// allocation, and bigger than the previously promised alignment, then set it.
|
// allocation, and bigger than the previously promised alignment, then set it.
|
||||||
@ -584,8 +584,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
let n = Size::from_bytes(this.read_target_usize(n)?);
|
let n = Size::from_bytes(this.read_target_usize(n)?);
|
||||||
|
|
||||||
// C requires that this must always be a valid pointer (C18 §7.1.4).
|
// C requires that this must always be a valid pointer (C18 §7.1.4).
|
||||||
this.ptr_get_alloc_id(left)?;
|
this.ptr_get_alloc_id(left, 0)?;
|
||||||
this.ptr_get_alloc_id(right)?;
|
this.ptr_get_alloc_id(right, 0)?;
|
||||||
|
|
||||||
let result = {
|
let result = {
|
||||||
let left_bytes = this.read_bytes_ptr_strip_provenance(left, n)?;
|
let left_bytes = this.read_bytes_ptr_strip_provenance(left, n)?;
|
||||||
@ -612,7 +612,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
let val = val as u8;
|
let val = val as u8;
|
||||||
|
|
||||||
// C requires that this must always be a valid pointer (C18 §7.1.4).
|
// C requires that this must always be a valid pointer (C18 §7.1.4).
|
||||||
this.ptr_get_alloc_id(ptr)?;
|
this.ptr_get_alloc_id(ptr, 0)?;
|
||||||
|
|
||||||
if let Some(idx) = this
|
if let Some(idx) = this
|
||||||
.read_bytes_ptr_strip_provenance(ptr, Size::from_bytes(num))?
|
.read_bytes_ptr_strip_provenance(ptr, Size::from_bytes(num))?
|
||||||
@ -622,7 +622,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
{
|
{
|
||||||
let idx = u64::try_from(idx).unwrap();
|
let idx = u64::try_from(idx).unwrap();
|
||||||
#[allow(clippy::arithmetic_side_effects)] // idx < num, so this never wraps
|
#[allow(clippy::arithmetic_side_effects)] // idx < num, so this never wraps
|
||||||
let new_ptr = ptr.offset(Size::from_bytes(num - idx - 1), this)?;
|
let new_ptr = ptr.wrapping_offset(Size::from_bytes(num - idx - 1), this);
|
||||||
this.write_pointer(new_ptr, dest)?;
|
this.write_pointer(new_ptr, dest)?;
|
||||||
} else {
|
} else {
|
||||||
this.write_null(dest)?;
|
this.write_null(dest)?;
|
||||||
@ -639,14 +639,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
let val = val as u8;
|
let val = val as u8;
|
||||||
|
|
||||||
// C requires that this must always be a valid pointer (C18 §7.1.4).
|
// C requires that this must always be a valid pointer (C18 §7.1.4).
|
||||||
this.ptr_get_alloc_id(ptr)?;
|
this.ptr_get_alloc_id(ptr, 0)?;
|
||||||
|
|
||||||
let idx = this
|
let idx = this
|
||||||
.read_bytes_ptr_strip_provenance(ptr, Size::from_bytes(num))?
|
.read_bytes_ptr_strip_provenance(ptr, Size::from_bytes(num))?
|
||||||
.iter()
|
.iter()
|
||||||
.position(|&c| c == val);
|
.position(|&c| c == val);
|
||||||
if let Some(idx) = idx {
|
if let Some(idx) = idx {
|
||||||
let new_ptr = ptr.offset(Size::from_bytes(idx as u64), this)?;
|
let new_ptr = ptr.wrapping_offset(Size::from_bytes(idx as u64), this);
|
||||||
this.write_pointer(new_ptr, dest)?;
|
this.write_pointer(new_ptr, dest)?;
|
||||||
} else {
|
} else {
|
||||||
this.write_null(dest)?;
|
this.write_null(dest)?;
|
||||||
@ -681,8 +681,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
|
|
||||||
// C requires that this must always be a valid pointer, even if `n` is zero, so we better check that.
|
// C requires that this must always be a valid pointer, even if `n` is zero, so we better check that.
|
||||||
// (This is more than Rust requires, so `mem_copy` is not sufficient.)
|
// (This is more than Rust requires, so `mem_copy` is not sufficient.)
|
||||||
this.ptr_get_alloc_id(ptr_dest)?;
|
this.ptr_get_alloc_id(ptr_dest, 0)?;
|
||||||
this.ptr_get_alloc_id(ptr_src)?;
|
this.ptr_get_alloc_id(ptr_src, 0)?;
|
||||||
|
|
||||||
this.mem_copy(ptr_src, ptr_dest, Size::from_bytes(n), true)?;
|
this.mem_copy(ptr_src, ptr_dest, Size::from_bytes(n), true)?;
|
||||||
this.write_pointer(ptr_dest, dest)?;
|
this.write_pointer(ptr_dest, dest)?;
|
||||||
|
@ -82,7 +82,7 @@ impl<'tcx> UnixEnvVars<'tcx> {
|
|||||||
};
|
};
|
||||||
// The offset is used to strip the "{name}=" part of the string.
|
// The offset is used to strip the "{name}=" part of the string.
|
||||||
let var_ptr = var_ptr
|
let var_ptr = var_ptr
|
||||||
.offset(Size::from_bytes(u64::try_from(name.len()).unwrap().strict_add(1)), ecx)?;
|
.wrapping_offset(Size::from_bytes(u64::try_from(name.len()).unwrap().strict_add(1)), ecx);
|
||||||
Ok(Some(var_ptr))
|
Ok(Some(var_ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -996,7 +996,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
&this.ptr_to_mplace(entry, dirent64_layout),
|
&this.ptr_to_mplace(entry, dirent64_layout),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let name_ptr = entry.offset(Size::from_bytes(d_name_offset), this)?;
|
let name_ptr = entry.wrapping_offset(Size::from_bytes(d_name_offset), this);
|
||||||
this.write_bytes_ptr(name_ptr, name_bytes.iter().copied())?;
|
this.write_bytes_ptr(name_ptr, name_bytes.iter().copied())?;
|
||||||
|
|
||||||
Some(entry)
|
Some(entry)
|
||||||
|
@ -53,7 +53,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
// We just allocated this, the access is definitely in-bounds and fits into our address space.
|
// We just allocated this, the access is definitely in-bounds and fits into our address space.
|
||||||
// mmap guarantees new mappings are zero-init.
|
// mmap guarantees new mappings are zero-init.
|
||||||
this.write_bytes_ptr(
|
this.write_bytes_ptr(
|
||||||
ptr.offset(Size::from_bytes(old_size), this).unwrap().into(),
|
ptr.wrapping_offset(Size::from_bytes(old_size), this).into(),
|
||||||
std::iter::repeat(0u8).take(usize::try_from(increase).unwrap()),
|
std::iter::repeat(0u8).take(usize::try_from(increase).unwrap()),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
error: Undefined Behavior: memory access failed: expected a pointer to 129 bytes of memory, but got ALLOC and there are only 128 bytes starting at that pointer
|
error: Undefined Behavior: memory access failed: expected a pointer to 129 bytes of memory, but got ALLOC which is only 128 bytes from the end of the allocation
|
||||||
--> $DIR/affinity.rs:LL:CC
|
--> $DIR/affinity.rs:LL:CC
|
||||||
|
|
|
|
||||||
LL | let err = unsafe { sched_setaffinity(PID, size_of::<cpu_set_t>() + 1, &cpuset) };
|
LL | let err = unsafe { sched_setaffinity(PID, size_of::<cpu_set_t>() + 1, &cpuset) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: expected a pointer to 129 bytes of memory, but got ALLOC and there are only 128 bytes starting at that pointer
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: expected a pointer to 129 bytes of memory, but got ALLOC which is only 128 bytes from the end of the allocation
|
||||||
|
|
|
|
||||||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
error: Undefined Behavior: out-of-bounds pointer use: expected a pointer to 4 bytes of memory, but got ALLOC and there are only 2 bytes starting at that pointer
|
error: Undefined Behavior: out-of-bounds pointer use: expected a pointer to 4 bytes of memory, but got ALLOC which is only 2 bytes from the end of the allocation
|
||||||
--> RUSTLIB/alloc/src/boxed.rs:LL:CC
|
--> RUSTLIB/alloc/src/boxed.rs:LL:CC
|
||||||
|
|
|
|
||||||
LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
|
LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: expected a pointer to 4 bytes of memory, but got ALLOC and there are only 2 bytes starting at that pointer
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: expected a pointer to 4 bytes of memory, but got ALLOC which is only 2 bytes from the end of the allocation
|
||||||
|
|
|
|
||||||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
error: Undefined Behavior: out-of-bounds pointer use: expected a pointer to 4 bytes of memory, but got ALLOC and there are only 2 bytes starting at that pointer
|
error: Undefined Behavior: out-of-bounds pointer use: expected a pointer to 4 bytes of memory, but got ALLOC which is only 2 bytes from the end of the allocation
|
||||||
--> RUSTLIB/alloc/src/boxed.rs:LL:CC
|
--> RUSTLIB/alloc/src/boxed.rs:LL:CC
|
||||||
|
|
|
|
||||||
LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
|
LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: expected a pointer to 4 bytes of memory, but got ALLOC and there are only 2 bytes starting at that pointer
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: expected a pointer to 4 bytes of memory, but got ALLOC which is only 2 bytes from the end of the allocation
|
||||||
|
|
|
|
||||||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
error: Undefined Behavior: out-of-bounds pointer arithmetic: expected a pointer to 8 bytes of memory, but got ALLOC and there are only 4 bytes starting at that pointer
|
error: Undefined Behavior: out-of-bounds pointer arithmetic: expected a pointer to 8 bytes of memory, but got ALLOC which is only 4 bytes from the end of the allocation
|
||||||
--> $DIR/out_of_bounds_project.rs:LL:CC
|
--> $DIR/out_of_bounds_project.rs:LL:CC
|
||||||
|
|
|
|
||||||
LL | let _field = addr_of!((*ptr).2);
|
LL | let _field = addr_of!((*ptr).2);
|
||||||
| ^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: expected a pointer to 8 bytes of memory, but got ALLOC and there are only 4 bytes starting at that pointer
|
| ^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: expected a pointer to 8 bytes of memory, but got ALLOC which is only 4 bytes from the end of the allocation
|
||||||
|
|
|
|
||||||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
fn main() {
|
|
||||||
let v = [0i8; 4];
|
|
||||||
let x = &v as *const i8;
|
|
||||||
let x = unsafe { x.offset(isize::MIN) }; //~ERROR: overflowing in-bounds pointer arithmetic
|
|
||||||
panic!("this should never print: {:?}", x);
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
error: Undefined Behavior: overflowing in-bounds pointer arithmetic
|
|
||||||
--> $DIR/out_of_bounds_ptr_2.rs:LL:CC
|
|
||||||
|
|
|
||||||
LL | let x = unsafe { x.offset(isize::MIN) };
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ overflowing in-bounds pointer arithmetic
|
|
||||||
|
|
|
||||||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
|
||||||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
|
||||||
= note: BACKTRACE:
|
|
||||||
= note: inside `main` at $DIR/out_of_bounds_ptr_2.rs:LL:CC
|
|
||||||
|
|
||||||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
error: Undefined Behavior: out-of-bounds `offset_from`: expected a pointer to 1 byte of memory, but got 0xa[noalloc] which is a dangling pointer (it has no provenance)
|
error: Undefined Behavior: out-of-bounds `offset_from` origin: expected a pointer to the end of 1 byte of memory, but got 0xb[noalloc] which is a dangling pointer (it has no provenance)
|
||||||
--> $DIR/ptr_offset_from_different_ints.rs:LL:CC
|
--> $DIR/ptr_offset_from_different_ints.rs:LL:CC
|
||||||
|
|
|
|
||||||
LL | let _ = p1.byte_offset_from(p2);
|
LL | let _ = p1.byte_offset_from(p2);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds `offset_from`: expected a pointer to 1 byte of memory, but got 0xa[noalloc] which is a dangling pointer (it has no provenance)
|
| ^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds `offset_from` origin: expected a pointer to the end of 1 byte of memory, but got 0xb[noalloc] which is a dangling pointer (it has no provenance)
|
||||||
|
|
|
|
||||||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
//@compile-flags: -Zmiri-permissive-provenance
|
//@compile-flags: -Zmiri-permissive-provenance
|
||||||
//@normalize-stderr-test: "to \d+ bytes of memory" -> "to $$BYTES bytes of memory"
|
//@normalize-stderr-test: "\d+ bytes" -> "$$BYTES bytes"
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let ptr = Box::into_raw(Box::new(0u32));
|
let ptr = Box::into_raw(Box::new(0u32));
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let v = [0i8; 4];
|
let v = [0i8; 4];
|
||||||
let x = &v as *const i8;
|
let x = &v as *const i8;
|
||||||
// The error is inside another function, so we cannot match it by line
|
|
||||||
let x = unsafe { x.offset(5) }; //~ERROR: expected a pointer to 5 bytes of memory
|
let x = unsafe { x.offset(5) }; //~ERROR: expected a pointer to 5 bytes of memory
|
||||||
panic!("this should never print: {:?}", x);
|
panic!("this should never print: {:?}", x);
|
||||||
}
|
}
|
@ -1,18 +1,18 @@
|
|||||||
error: Undefined Behavior: out-of-bounds pointer arithmetic: expected a pointer to 5 bytes of memory, but got ALLOC and there are only 4 bytes starting at that pointer
|
error: Undefined Behavior: out-of-bounds pointer arithmetic: expected a pointer to 5 bytes of memory, but got ALLOC which is only 4 bytes from the end of the allocation
|
||||||
--> $DIR/out_of_bounds_ptr_1.rs:LL:CC
|
--> $DIR/ptr_offset_out_of_bounds.rs:LL:CC
|
||||||
|
|
|
|
||||||
LL | let x = unsafe { x.offset(5) };
|
LL | let x = unsafe { x.offset(5) };
|
||||||
| ^^^^^^^^^^^ out-of-bounds pointer arithmetic: expected a pointer to 5 bytes of memory, but got ALLOC and there are only 4 bytes starting at that pointer
|
| ^^^^^^^^^^^ out-of-bounds pointer arithmetic: expected a pointer to 5 bytes of memory, but got ALLOC which is only 4 bytes from the end of the allocation
|
||||||
|
|
|
|
||||||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||||
help: ALLOC was allocated here:
|
help: ALLOC was allocated here:
|
||||||
--> $DIR/out_of_bounds_ptr_1.rs:LL:CC
|
--> $DIR/ptr_offset_out_of_bounds.rs:LL:CC
|
||||||
|
|
|
|
||||||
LL | let v = [0i8; 4];
|
LL | let v = [0i8; 4];
|
||||||
| ^
|
| ^
|
||||||
= note: BACKTRACE (of the first span):
|
= note: BACKTRACE (of the first span):
|
||||||
= note: inside `main` at $DIR/out_of_bounds_ptr_1.rs:LL:CC
|
= note: inside `main` at $DIR/ptr_offset_out_of_bounds.rs:LL:CC
|
||||||
|
|
||||||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let v = [0i8; 4];
|
let v = [0i8; 4];
|
||||||
let x = &v as *const i8;
|
let x = &v as *const i8;
|
||||||
let x = unsafe { x.offset(-1) }; //~ERROR: expected a pointer to 1 byte of memory
|
let x = unsafe { x.offset(-1) }; //~ERROR: expected a pointer to the end of 1 byte of memory
|
||||||
panic!("this should never print: {:?}", x);
|
panic!("this should never print: {:?}", x);
|
||||||
}
|
}
|
@ -1,18 +1,18 @@
|
|||||||
error: Undefined Behavior: out-of-bounds pointer arithmetic: expected a pointer to 1 byte of memory, but got ALLOC-0x1 which points to before the beginning of the allocation
|
error: Undefined Behavior: out-of-bounds pointer arithmetic: expected a pointer to the end of 1 byte of memory, but got ALLOC which is at the beginning of the allocation
|
||||||
--> $DIR/out_of_bounds_ptr_3.rs:LL:CC
|
--> $DIR/ptr_offset_out_of_bounds_neg.rs:LL:CC
|
||||||
|
|
|
|
||||||
LL | let x = unsafe { x.offset(-1) };
|
LL | let x = unsafe { x.offset(-1) };
|
||||||
| ^^^^^^^^^^^^ out-of-bounds pointer arithmetic: expected a pointer to 1 byte of memory, but got ALLOC-0x1 which points to before the beginning of the allocation
|
| ^^^^^^^^^^^^ out-of-bounds pointer arithmetic: expected a pointer to the end of 1 byte of memory, but got ALLOC which is at the beginning of the allocation
|
||||||
|
|
|
|
||||||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||||
help: ALLOC was allocated here:
|
help: ALLOC was allocated here:
|
||||||
--> $DIR/out_of_bounds_ptr_3.rs:LL:CC
|
--> $DIR/ptr_offset_out_of_bounds_neg.rs:LL:CC
|
||||||
|
|
|
|
||||||
LL | let v = [0i8; 4];
|
LL | let v = [0i8; 4];
|
||||||
| ^
|
| ^
|
||||||
= note: BACKTRACE (of the first span):
|
= note: BACKTRACE (of the first span):
|
||||||
= note: inside `main` at $DIR/out_of_bounds_ptr_3.rs:LL:CC
|
= note: inside `main` at $DIR/ptr_offset_out_of_bounds_neg.rs:LL:CC
|
||||||
|
|
||||||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
||||||
|
|
@ -1,5 +1,8 @@
|
|||||||
|
//@normalize-stderr-test: "\d+ bytes" -> "$$BYTES bytes"
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let v = [1i8, 2];
|
let v = [0i8; 4];
|
||||||
let x = &v[1] as *const i8;
|
let x = &v as *const i8;
|
||||||
let _val = unsafe { x.offset(isize::MIN) }; //~ERROR: overflowing in-bounds pointer arithmetic
|
let x = unsafe { x.offset(isize::MIN) }; //~ERROR: out-of-bounds pointer arithmetic
|
||||||
|
panic!("this should never print: {:?}", x);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
error: Undefined Behavior: overflowing in-bounds pointer arithmetic
|
error: Undefined Behavior: out-of-bounds pointer arithmetic: expected a pointer to the end of $BYTES bytes of memory, but got ALLOC which is at the beginning of the allocation
|
||||||
--> $DIR/ptr_offset_overflow.rs:LL:CC
|
--> $DIR/ptr_offset_overflow.rs:LL:CC
|
||||||
|
|
|
|
||||||
LL | let _val = unsafe { x.offset(isize::MIN) };
|
LL | let x = unsafe { x.offset(isize::MIN) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ overflowing in-bounds pointer arithmetic
|
| ^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: expected a pointer to the end of $BYTES bytes of memory, but got ALLOC which is at the beginning of the allocation
|
||||||
|
|
|
|
||||||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||||
= note: BACKTRACE:
|
help: ALLOC was allocated here:
|
||||||
|
--> $DIR/ptr_offset_overflow.rs:LL:CC
|
||||||
|
|
|
||||||
|
LL | let v = [0i8; 4];
|
||||||
|
| ^
|
||||||
|
= note: BACKTRACE (of the first span):
|
||||||
= note: inside `main` at $DIR/ptr_offset_overflow.rs:LL:CC
|
= note: inside `main` at $DIR/ptr_offset_overflow.rs:LL:CC
|
||||||
|
|
||||||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
||||||
|
@ -118,7 +118,7 @@ LL | pub static R1: &[()] = unsafe { from_ptr_range(ptr::null()..ptr::null()) };
|
|||||||
error[E0080]: could not evaluate static initializer
|
error[E0080]: could not evaluate static initializer
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: out-of-bounds pointer arithmetic: expected a pointer to 8 bytes of memory, but got ALLOC10 and there are only 4 bytes starting at that pointer
|
= note: out-of-bounds pointer arithmetic: expected a pointer to 8 bytes of memory, but got ALLOC10 which is only 4 bytes from the end of the allocation
|
||||||
|
|
|
|
||||||
note: inside `std::ptr::const_ptr::<impl *const u32>::add`
|
note: inside `std::ptr::const_ptr::<impl *const u32>::add`
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
@ -177,7 +177,7 @@ LL | pub static R7: &[u16] = unsafe {
|
|||||||
error[E0080]: could not evaluate static initializer
|
error[E0080]: could not evaluate static initializer
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: out-of-bounds pointer arithmetic: expected a pointer to 8 bytes of memory, but got ALLOC11+0x1 and there are only 7 bytes starting at that pointer
|
= note: out-of-bounds pointer arithmetic: expected a pointer to 8 bytes of memory, but got ALLOC11+0x1 which is only 7 bytes from the end of the allocation
|
||||||
|
|
|
|
||||||
note: inside `std::ptr::const_ptr::<impl *const u64>::add`
|
note: inside `std::ptr::const_ptr::<impl *const u64>::add`
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
@ -20,13 +20,13 @@ error[E0080]: evaluation of constant value failed
|
|||||||
--> $DIR/const-compare-bytes-ub.rs:22:9
|
--> $DIR/const-compare-bytes-ub.rs:22:9
|
||||||
|
|
|
|
||||||
LL | compare_bytes([1, 2, 3].as_ptr(), [1, 2, 3, 4].as_ptr(), 4)
|
LL | compare_bytes([1, 2, 3].as_ptr(), [1, 2, 3, 4].as_ptr(), 4)
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: expected a pointer to 4 bytes of memory, but got ALLOC0 and there are only 3 bytes starting at that pointer
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: expected a pointer to 4 bytes of memory, but got ALLOC0 which is only 3 bytes from the end of the allocation
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/const-compare-bytes-ub.rs:26:9
|
--> $DIR/const-compare-bytes-ub.rs:26:9
|
||||||
|
|
|
|
||||||
LL | compare_bytes([1, 2, 3, 4].as_ptr(), [1, 2, 3].as_ptr(), 4)
|
LL | compare_bytes([1, 2, 3, 4].as_ptr(), [1, 2, 3].as_ptr(), 4)
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: expected a pointer to 4 bytes of memory, but got ALLOC1 and there are only 3 bytes starting at that pointer
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: expected a pointer to 4 bytes of memory, but got ALLOC1 which is only 3 bytes from the end of the allocation
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/const-compare-bytes-ub.rs:30:9
|
--> $DIR/const-compare-bytes-ub.rs:30:9
|
||||||
|
@ -35,7 +35,7 @@ error[E0080]: evaluation of constant value failed
|
|||||||
--> $DIR/raw-pointer-ub.rs:41:16
|
--> $DIR/raw-pointer-ub.rs:41:16
|
||||||
|
|
|
|
||||||
LL | let _val = *ptr;
|
LL | let _val = *ptr;
|
||||||
| ^^^^ memory access failed: expected a pointer to 8 bytes of memory, but got ALLOC0 and there are only 4 bytes starting at that pointer
|
| ^^^^ memory access failed: expected a pointer to 8 bytes of memory, but got ALLOC0 which is only 4 bytes from the end of the allocation
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ error[E0080]: evaluation of constant value failed
|
|||||||
--> $DIR/ub-nonnull.rs:20:29
|
--> $DIR/ub-nonnull.rs:20:29
|
||||||
|
|
|
|
||||||
LL | let out_of_bounds_ptr = &ptr[255];
|
LL | let out_of_bounds_ptr = &ptr[255];
|
||||||
| ^^^^^^^^^ out-of-bounds pointer arithmetic: expected a pointer to 255 bytes of memory, but got ALLOC1 and there are only 1 bytes starting at that pointer
|
| ^^^^^^^^^ out-of-bounds pointer arithmetic: expected a pointer to 255 bytes of memory, but got ALLOC1 which is only 1 byte from the end of the allocation
|
||||||
|
|
||||||
error[E0080]: it is undefined behavior to use this value
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/ub-nonnull.rs:24:1
|
--> $DIR/ub-nonnull.rs:24:1
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//@ normalize-stderr-test: "to \d+ bytes of memory" -> "to $$BYTES bytes of memory"
|
//@ normalize-stderr-test: "\d+ bytes" -> "$$BYTES bytes"
|
||||||
#![feature(const_ptr_sub_ptr)]
|
#![feature(const_ptr_sub_ptr)]
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ const OUT_OF_BOUNDS_2: isize = {
|
|||||||
let end_ptr = (start_ptr).wrapping_add(length);
|
let end_ptr = (start_ptr).wrapping_add(length);
|
||||||
// Second ptr is out of bounds
|
// Second ptr is out of bounds
|
||||||
unsafe { ptr_offset_from(start_ptr, end_ptr) } //~ERROR evaluation of constant value failed
|
unsafe { ptr_offset_from(start_ptr, end_ptr) } //~ERROR evaluation of constant value failed
|
||||||
//~| expected a pointer to 10 bytes of memory
|
//~| expected a pointer to the end of 10 bytes of memory
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const DIFFERENT_ALLOC_UNSIGNED: usize = {
|
pub const DIFFERENT_ALLOC_UNSIGNED: usize = {
|
||||||
|
@ -27,19 +27,19 @@ error[E0080]: evaluation of constant value failed
|
|||||||
--> $DIR/offset_from_ub.rs:39:14
|
--> $DIR/offset_from_ub.rs:39:14
|
||||||
|
|
|
|
||||||
LL | unsafe { ptr_offset_from(ptr2, ptr1) }
|
LL | unsafe { ptr_offset_from(ptr2, ptr1) }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds `offset_from`: expected a pointer to $BYTES bytes of memory, but got 0x8[noalloc] which is a dangling pointer (it has no provenance)
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds `offset_from` origin: expected a pointer to $BYTES bytes of memory, but got 0x8[noalloc] which is a dangling pointer (it has no provenance)
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/offset_from_ub.rs:48:14
|
--> $DIR/offset_from_ub.rs:48:14
|
||||||
|
|
|
|
||||||
LL | unsafe { ptr_offset_from(end_ptr, start_ptr) }
|
LL | unsafe { ptr_offset_from(end_ptr, start_ptr) }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds `offset_from`: expected a pointer to $BYTES bytes of memory, but got ALLOC0 and there are only 4 bytes starting at that pointer
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds `offset_from` origin: expected a pointer to $BYTES bytes of memory, but got ALLOC0 which is only $BYTES bytes from the end of the allocation
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/offset_from_ub.rs:57:14
|
--> $DIR/offset_from_ub.rs:57:14
|
||||||
|
|
|
|
||||||
LL | unsafe { ptr_offset_from(start_ptr, end_ptr) }
|
LL | unsafe { ptr_offset_from(start_ptr, end_ptr) }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds `offset_from`: expected a pointer to $BYTES bytes of memory, but got ALLOC1 and there are only 4 bytes starting at that pointer
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds `offset_from` origin: expected a pointer to the end of $BYTES bytes of memory, but got ALLOC1+0xa which does not have enough space to the beginning of the allocation
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/offset_from_ub.rs:66:14
|
--> $DIR/offset_from_ub.rs:66:14
|
||||||
@ -80,7 +80,7 @@ LL | unsafe { ptr_offset_from_unsigned(ptr2, ptr1) }
|
|||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: out-of-bounds `offset_from`: expected a pointer to $BYTES bytes of memory, but got a null pointer
|
= note: out-of-bounds `offset_from` origin: expected a pointer to $BYTES bytes of memory, but got a null pointer
|
||||||
|
|
|
|
||||||
note: inside `std::ptr::const_ptr::<impl *const u8>::offset_from`
|
note: inside `std::ptr::const_ptr::<impl *const u8>::offset_from`
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
@ -2,7 +2,7 @@ use std::ptr;
|
|||||||
|
|
||||||
//@ normalize-stderr-test: "0xf+" -> "0xf..f"
|
//@ normalize-stderr-test: "0xf+" -> "0xf..f"
|
||||||
//@ normalize-stderr-test: "0x7f+" -> "0x7f..f"
|
//@ normalize-stderr-test: "0x7f+" -> "0x7f..f"
|
||||||
//@ normalize-stderr-test: "to \d+ bytes of memory" -> "to $$BYTES bytes of memory"
|
//@ normalize-stderr-test: "\d+ bytes" -> "$$BYTES bytes"
|
||||||
|
|
||||||
|
|
||||||
pub const BEFORE_START: *const u8 = unsafe { (&0u8 as *const u8).offset(-1) }; //~NOTE
|
pub const BEFORE_START: *const u8 = unsafe { (&0u8 as *const u8).offset(-1) }; //~NOTE
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: overflowing in-bounds pointer arithmetic
|
= note: out-of-bounds pointer arithmetic: expected a pointer to the end of 1 byte of memory, but got ALLOC0 which is at the beginning of the allocation
|
||||||
|
|
|
|
||||||
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
@ -14,7 +14,7 @@ LL | pub const BEFORE_START: *const u8 = unsafe { (&0u8 as *const u8).offset(-1)
|
|||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: out-of-bounds pointer arithmetic: expected a pointer to $BYTES bytes of memory, but got ALLOC0 and there are only 1 bytes starting at that pointer
|
= note: out-of-bounds pointer arithmetic: expected a pointer to $BYTES bytes of memory, but got ALLOC1 which is only 1 byte from the end of the allocation
|
||||||
|
|
|
|
||||||
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
@ -27,7 +27,7 @@ LL | pub const AFTER_END: *const u8 = unsafe { (&0u8 as *const u8).offset(2) };
|
|||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: out-of-bounds pointer arithmetic: expected a pointer to $BYTES bytes of memory, but got ALLOC1 and there are only 100 bytes starting at that pointer
|
= note: out-of-bounds pointer arithmetic: expected a pointer to $BYTES bytes of memory, but got ALLOC2 which is only $BYTES bytes from the end of the allocation
|
||||||
|
|
|
|
||||||
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
@ -40,7 +40,7 @@ LL | pub const AFTER_ARRAY: *const u8 = unsafe { [0u8; 100].as_ptr().offset(101)
|
|||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: overflowing in-bounds pointer arithmetic
|
= note: overflowing pointer arithmetic: the total offset in bytes does not fit in an `isize`
|
||||||
|
|
|
|
||||||
note: inside `std::ptr::const_ptr::<impl *const u16>::offset`
|
note: inside `std::ptr::const_ptr::<impl *const u16>::offset`
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
@ -53,7 +53,7 @@ LL | pub const OVERFLOW: *const u16 = unsafe { [0u16; 1].as_ptr().offset(isize::
|
|||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: overflowing in-bounds pointer arithmetic
|
= note: overflowing pointer arithmetic: the total offset in bytes does not fit in an `isize`
|
||||||
|
|
|
|
||||||
note: inside `std::ptr::const_ptr::<impl *const u16>::offset`
|
note: inside `std::ptr::const_ptr::<impl *const u16>::offset`
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
@ -66,7 +66,7 @@ LL | pub const UNDERFLOW: *const u16 = unsafe { [0u16; 1].as_ptr().offset(isize:
|
|||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: overflowing in-bounds pointer arithmetic
|
= note: out-of-bounds pointer arithmetic: expected a pointer to $BYTES bytes of memory, but got 0xf..f[noalloc] which is a dangling pointer (it has no provenance)
|
||||||
|
|
|
|
||||||
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
@ -79,7 +79,7 @@ LL | pub const OVERFLOW_ADDRESS_SPACE: *const u8 = unsafe { (usize::MAX as *cons
|
|||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: overflowing in-bounds pointer arithmetic
|
= note: out-of-bounds pointer arithmetic: expected a pointer to the end of $BYTES bytes of memory, but got 0x1[noalloc] which is a dangling pointer (it has no provenance)
|
||||||
|
|
|
|
||||||
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
@ -92,7 +92,7 @@ LL | pub const UNDERFLOW_ADDRESS_SPACE: *const u8 = unsafe { (1 as *const u8).of
|
|||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: out-of-bounds pointer arithmetic: expected a pointer to $BYTES bytes of memory, but got ALLOC2-0x4 which points to before the beginning of the allocation
|
= note: out-of-bounds pointer arithmetic: expected a pointer to the end of $BYTES bytes of memory, but got ALLOC3-0x2 which points to before the beginning of the allocation
|
||||||
|
|
|
|
||||||
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
@ -105,7 +105,7 @@ LL | pub const NEGATIVE_OFFSET: *const u8 = unsafe { [0u8; 1].as_ptr().wrapping_
|
|||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: out-of-bounds pointer arithmetic: expected a pointer to 1 byte of memory, but got ALLOC3 which is at or beyond the end of the allocation of size 0 bytes
|
= note: out-of-bounds pointer arithmetic: expected a pointer to 1 byte of memory, but got ALLOC4 which is at or beyond the end of the allocation of size $BYTES bytes
|
||||||
|
|
|
|
||||||
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
@ -131,7 +131,7 @@ LL | pub const DANGLING: *const u8 = unsafe { ptr::NonNull::<u8>::dangling().as_
|
|||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: out-of-bounds pointer arithmetic: expected a pointer to $BYTES bytes of memory, but got 0x7f..f[noalloc] which is a dangling pointer (it has no provenance)
|
= note: out-of-bounds pointer arithmetic: expected a pointer to the end of $BYTES bytes of memory, but got 0xf..f[noalloc] which is a dangling pointer (it has no provenance)
|
||||||
|
|
|
|
||||||
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
note: inside `std::ptr::const_ptr::<impl *const u8>::offset`
|
||||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||||
|
@ -7,7 +7,7 @@ LL | let _ = box ();
|
|||||||
help: use `Box::new()` instead
|
help: use `Box::new()` instead
|
||||||
|
|
|
|
||||||
LL | let _ = Box::new(());
|
LL | let _ = Box::new(());
|
||||||
| ~~~~~~~~~~~~
|
| ~~~~~~~~~ +
|
||||||
|
|
||||||
error: `box_syntax` has been removed
|
error: `box_syntax` has been removed
|
||||||
--> $DIR/removed-syntax-box.rs:10:13
|
--> $DIR/removed-syntax-box.rs:10:13
|
||||||
@ -18,7 +18,7 @@ LL | let _ = box 1;
|
|||||||
help: use `Box::new()` instead
|
help: use `Box::new()` instead
|
||||||
|
|
|
|
||||||
LL | let _ = Box::new(1);
|
LL | let _ = Box::new(1);
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~ +
|
||||||
|
|
||||||
error: `box_syntax` has been removed
|
error: `box_syntax` has been removed
|
||||||
--> $DIR/removed-syntax-box.rs:11:13
|
--> $DIR/removed-syntax-box.rs:11:13
|
||||||
@ -29,7 +29,7 @@ LL | let _ = box T { a: 12, b: 18 };
|
|||||||
help: use `Box::new()` instead
|
help: use `Box::new()` instead
|
||||||
|
|
|
|
||||||
LL | let _ = Box::new(T { a: 12, b: 18 });
|
LL | let _ = Box::new(T { a: 12, b: 18 });
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~ +
|
||||||
|
|
||||||
error: `box_syntax` has been removed
|
error: `box_syntax` has been removed
|
||||||
--> $DIR/removed-syntax-box.rs:12:13
|
--> $DIR/removed-syntax-box.rs:12:13
|
||||||
@ -40,7 +40,7 @@ LL | let _ = box [5; 30];
|
|||||||
help: use `Box::new()` instead
|
help: use `Box::new()` instead
|
||||||
|
|
|
|
||||||
LL | let _ = Box::new([5; 30]);
|
LL | let _ = Box::new([5; 30]);
|
||||||
| ~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~ +
|
||||||
|
|
||||||
error: `box_syntax` has been removed
|
error: `box_syntax` has been removed
|
||||||
--> $DIR/removed-syntax-box.rs:13:22
|
--> $DIR/removed-syntax-box.rs:13:22
|
||||||
@ -51,7 +51,7 @@ LL | let _: Box<()> = box ();
|
|||||||
help: use `Box::new()` instead
|
help: use `Box::new()` instead
|
||||||
|
|
|
|
||||||
LL | let _: Box<()> = Box::new(());
|
LL | let _: Box<()> = Box::new(());
|
||||||
| ~~~~~~~~~~~~
|
| ~~~~~~~~~ +
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user