more precise error for 'based on misaligned pointer' case
This commit is contained in:
parent
cbf47a17d2
commit
e24835c6e0
31 changed files with 112 additions and 91 deletions
|
@ -1,11 +1,15 @@
|
|||
const_eval_address_space_full =
|
||||
there are no more free addresses in the address space
|
||||
const_eval_align_check_failed = accessing memory with alignment {$has}, but alignment {$required} is required
|
||||
|
||||
const_eval_align_offset_invalid_align =
|
||||
`align_offset` called with non-power-of-two align: {$target_align}
|
||||
|
||||
const_eval_alignment_check_failed =
|
||||
accessing memory with alignment {$has}, but alignment {$required} is required
|
||||
{$msg ->
|
||||
[AccessedPtr] accessing memory
|
||||
*[other] accessing memory based on pointer
|
||||
} with alignment {$has}, but alignment {$required} is required
|
||||
|
||||
const_eval_already_reported =
|
||||
an error has already been reported elsewhere (this should not usually be printed)
|
||||
const_eval_assume_false =
|
||||
|
|
|
@ -390,15 +390,6 @@ pub struct LiveDrop<'tcx> {
|
|||
pub dropped_at: Option<Span>,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(const_eval_align_check_failed)]
|
||||
pub struct AlignmentCheckFailed {
|
||||
pub has: u64,
|
||||
pub required: u64,
|
||||
#[subdiagnostic]
|
||||
pub frames: Vec<FrameNote>,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(const_eval_error, code = "E0080")]
|
||||
pub struct ConstEvalError {
|
||||
|
@ -568,9 +559,10 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
|
|||
|
||||
builder.set_arg("bad_pointer_message", bad_pointer_message(msg, handler));
|
||||
}
|
||||
AlignmentCheckFailed(Misalignment { required, has }) => {
|
||||
AlignmentCheckFailed(Misalignment { required, has }, msg) => {
|
||||
builder.set_arg("required", required.bytes());
|
||||
builder.set_arg("has", has.bytes());
|
||||
builder.set_arg("msg", format!("{msg:?}"));
|
||||
}
|
||||
WriteToReadOnly(alloc) | DerefFunctionPointer(alloc) | DerefVTablePointer(alloc) => {
|
||||
builder.set_arg("allocation", alloc);
|
||||
|
|
|
@ -21,8 +21,8 @@ use rustc_target::abi::{Align, HasDataLayout, Size};
|
|||
use crate::fluent_generated as fluent;
|
||||
|
||||
use super::{
|
||||
alloc_range, AllocBytes, AllocId, AllocMap, AllocRange, Allocation, CheckInAllocMsg,
|
||||
GlobalAlloc, InterpCx, InterpResult, Machine, MayLeak, Misalignment, Pointer,
|
||||
alloc_range, AllocBytes, AllocId, AllocMap, AllocRange, Allocation, CheckAlignMsg,
|
||||
CheckInAllocMsg, GlobalAlloc, InterpCx, InterpResult, Machine, MayLeak, Misalignment, Pointer,
|
||||
PointerArithmetic, Provenance, Scalar,
|
||||
};
|
||||
|
||||
|
@ -425,7 +425,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
}
|
||||
// Must be aligned.
|
||||
if M::enforce_alignment(self) && align.bytes() > 1 {
|
||||
self.check_misalign(Self::offset_misalignment(addr, align))?;
|
||||
self.check_misalign(
|
||||
Self::offset_misalignment(addr, align),
|
||||
CheckAlignMsg::AccessedPtr,
|
||||
)?;
|
||||
}
|
||||
None
|
||||
}
|
||||
|
@ -449,7 +452,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
// Test align. Check this last; if both bounds and alignment are violated
|
||||
// we want the error to be about the bounds.
|
||||
if M::enforce_alignment(self) && align.bytes() > 1 {
|
||||
self.check_misalign(self.alloc_misalignment(ptr, offset, align, alloc_align))?;
|
||||
self.check_misalign(
|
||||
self.alloc_misalignment(ptr, offset, align, alloc_align),
|
||||
CheckAlignMsg::AccessedPtr,
|
||||
)?;
|
||||
}
|
||||
|
||||
// We can still be zero-sized in this branch, in which case we have to
|
||||
|
@ -460,9 +466,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(super) fn check_misalign(&self, misaligned: Option<Misalignment>) -> InterpResult<'tcx> {
|
||||
pub(super) fn check_misalign(
|
||||
&self,
|
||||
misaligned: Option<Misalignment>,
|
||||
msg: CheckAlignMsg,
|
||||
) -> InterpResult<'tcx> {
|
||||
if let Some(misaligned) = misaligned {
|
||||
throw_ub!(AlignmentCheckFailed(misaligned))
|
||||
throw_ub!(AlignmentCheckFailed(misaligned, msg))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -15,9 +15,9 @@ use rustc_middle::ty::Ty;
|
|||
use rustc_target::abi::{Abi, Align, FieldIdx, HasDataLayout, Size, FIRST_VARIANT};
|
||||
|
||||
use super::{
|
||||
alloc_range, mir_assign_valid_types, AllocId, AllocRef, AllocRefMut, ImmTy, Immediate,
|
||||
InterpCx, InterpResult, Machine, MemoryKind, Misalignment, OffsetMode, OpTy, Operand, Pointer,
|
||||
PointerArithmetic, Projectable, Provenance, Readable, Scalar,
|
||||
alloc_range, mir_assign_valid_types, AllocId, AllocRef, AllocRefMut, CheckAlignMsg, ImmTy,
|
||||
Immediate, InterpCx, InterpResult, Machine, MemoryKind, Misalignment, OffsetMode, OpTy,
|
||||
Operand, Pointer, PointerArithmetic, Projectable, Provenance, Readable, Scalar,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
|
||||
|
@ -461,7 +461,7 @@ where
|
|||
// We check alignment separately, and *after* checking everything else.
|
||||
// If an access is both OOB and misaligned, we want to see the bounds error.
|
||||
let a = self.get_ptr_alloc(mplace.ptr(), size, Align::ONE)?;
|
||||
self.check_misalign(mplace.mplace.misaligned)?;
|
||||
self.check_misalign(mplace.mplace.misaligned, CheckAlignMsg::BasedOn)?;
|
||||
Ok(a)
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,7 @@ where
|
|||
// We check alignment separately, and raise that error *after* checking everything else.
|
||||
// If an access is both OOB and misaligned, we want to see the bounds error.
|
||||
// However we have to call `check_misalign` first to make the borrow checker happy.
|
||||
let misalign_err = self.check_misalign(mplace.mplace.misaligned);
|
||||
let misalign_err = self.check_misalign(mplace.mplace.misaligned, CheckAlignMsg::BasedOn);
|
||||
let a = self.get_ptr_alloc_mut(mplace.ptr(), size, Align::ONE)?;
|
||||
misalign_err?;
|
||||
Ok(a)
|
||||
|
@ -881,8 +881,8 @@ where
|
|||
dest_size,
|
||||
/*nonoverlapping*/ true,
|
||||
)?;
|
||||
self.check_misalign(src.mplace.misaligned)?;
|
||||
self.check_misalign(dest.mplace.misaligned)?;
|
||||
self.check_misalign(src.mplace.misaligned, CheckAlignMsg::BasedOn)?;
|
||||
self.check_misalign(dest.mplace.misaligned, CheckAlignMsg::BasedOn)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -385,7 +385,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
|||
CheckInAllocMsg::InboundsTest, // will anyway be replaced by validity message
|
||||
),
|
||||
self.path,
|
||||
Ub(AlignmentCheckFailed(Misalignment { required, has })) => UnalignedPtr {
|
||||
Ub(AlignmentCheckFailed(Misalignment { required, has }, _msg)) => UnalignedPtr {
|
||||
ptr_kind,
|
||||
required_bytes: required.bytes(),
|
||||
found_bytes: has.bytes()
|
||||
|
|
|
@ -216,7 +216,7 @@ pub enum InvalidProgramInfo<'tcx> {
|
|||
}
|
||||
|
||||
/// Details of why a pointer had to be in-bounds.
|
||||
#[derive(Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum CheckInAllocMsg {
|
||||
/// We are access memory.
|
||||
MemoryAccessTest,
|
||||
|
@ -228,7 +228,16 @@ pub enum CheckInAllocMsg {
|
|||
InboundsTest,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
|
||||
/// Details of which pointer is not aligned.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum CheckAlignMsg {
|
||||
/// The accessed pointer did not have proper alignment.
|
||||
AccessedPtr,
|
||||
/// The access ocurred with a place that was based on a misaligned pointer.
|
||||
BasedOn,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum InvalidMetaKind {
|
||||
/// Size of a `[T]` is too big
|
||||
SliceTooBig,
|
||||
|
@ -329,7 +338,7 @@ pub enum UndefinedBehaviorInfo<'tcx> {
|
|||
/// Using an integer as a pointer in the wrong way.
|
||||
DanglingIntPointer(u64, CheckInAllocMsg),
|
||||
/// Used a pointer with bad alignment.
|
||||
AlignmentCheckFailed(Misalignment),
|
||||
AlignmentCheckFailed(Misalignment, CheckAlignMsg),
|
||||
/// Writing to read-only memory.
|
||||
WriteToReadOnly(AllocId),
|
||||
/// Trying to access the data behind a function pointer.
|
||||
|
|
|
@ -142,11 +142,12 @@ use crate::ty::GenericArgKind;
|
|||
use crate::ty::{self, Instance, Ty, TyCtxt};
|
||||
|
||||
pub use self::error::{
|
||||
struct_error, BadBytesAccess, CheckInAllocMsg, ErrorHandled, EvalToAllocationRawResult,
|
||||
EvalToConstValueResult, EvalToValTreeResult, ExpectedKind, InterpError, InterpErrorInfo,
|
||||
InterpResult, InvalidMetaKind, InvalidProgramInfo, MachineStopType, Misalignment, PointerKind,
|
||||
ReportedErrorInfo, ResourceExhaustionInfo, ScalarSizeMismatch, UndefinedBehaviorInfo,
|
||||
UnsupportedOpInfo, ValidationErrorInfo, ValidationErrorKind,
|
||||
struct_error, BadBytesAccess, CheckAlignMsg, CheckInAllocMsg, ErrorHandled,
|
||||
EvalToAllocationRawResult, EvalToConstValueResult, EvalToValTreeResult, ExpectedKind,
|
||||
InterpError, InterpErrorInfo, InterpResult, InvalidMetaKind, InvalidProgramInfo,
|
||||
MachineStopType, Misalignment, PointerKind, ReportedErrorInfo, ResourceExhaustionInfo,
|
||||
ScalarSizeMismatch, UndefinedBehaviorInfo, UnsupportedOpInfo, ValidationErrorInfo,
|
||||
ValidationErrorKind,
|
||||
};
|
||||
|
||||
pub use self::value::Scalar;
|
||||
|
|
|
@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const-ub-checks.rs:LL:CC
|
||||
|
|
||||
LL | ptr.read();
|
||||
| ^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
| ^^^^^^^^^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
|
||||
note: erroneous constant encountered
|
||||
--> $DIR/const-ub-checks.rs:LL:CC
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#![feature(pointer_byte_offsets)]
|
||||
|
||||
fn main() {
|
||||
let v: Vec<u16> = vec![1, 2];
|
||||
// This read is also misaligned. We make sure that the OOB message has priority.
|
||||
let x = unsafe { *v.as_ptr().wrapping_byte_add(5) }; //~ ERROR: out-of-bounds
|
||||
panic!("this should never print: {}", x);
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
error: Undefined Behavior: memory access failed: ALLOC has size 2, so pointer to 1 byte starting at offset 5 is out-of-bounds
|
||||
--> $DIR/out_of_bounds_read1.rs:LL:CC
|
||||
error: Undefined Behavior: memory access failed: ALLOC has size 4, so pointer to 2 bytes starting at offset 5 is out-of-bounds
|
||||
--> $DIR/out_of_bounds_read.rs:LL:CC
|
||||
|
|
||||
LL | let x = unsafe { *v.as_ptr().wrapping_offset(5) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has size 2, so pointer to 1 byte starting at offset 5 is out-of-bounds
|
||||
LL | let x = unsafe { *v.as_ptr().wrapping_byte_add(5) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has size 4, so pointer to 2 bytes starting at offset 5 is out-of-bounds
|
||||
|
|
||||
= 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: ALLOC was allocated here:
|
||||
--> $DIR/out_of_bounds_read1.rs:LL:CC
|
||||
--> $DIR/out_of_bounds_read.rs:LL:CC
|
||||
|
|
||||
LL | let v: Vec<u8> = vec![1, 2];
|
||||
LL | let v: Vec<u16> = vec![1, 2];
|
||||
| ^^^^^^^^^^
|
||||
= note: BACKTRACE (of the first span):
|
||||
= note: inside `main` at $DIR/out_of_bounds_read1.rs:LL:CC
|
||||
= note: inside `main` at $DIR/out_of_bounds_read.rs:LL:CC
|
||||
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
|
@ -1,5 +0,0 @@
|
|||
fn main() {
|
||||
let v: Vec<u8> = vec![1, 2];
|
||||
let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR: out-of-bounds
|
||||
panic!("this should never print: {}", x);
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
fn main() {
|
||||
let v: Vec<u8> = vec![1, 2];
|
||||
let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR: out-of-bounds
|
||||
panic!("this should never print: {}", x);
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#![feature(pointer_byte_offsets)]
|
||||
|
||||
fn main() {
|
||||
let mut v: Vec<u16> = vec![1, 2];
|
||||
// This read is also misaligned. We make sure that the OOB message has priority.
|
||||
unsafe { *v.as_mut_ptr().wrapping_byte_add(5) = 0 }; //~ ERROR: out-of-bounds
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
error: Undefined Behavior: memory access failed: ALLOC has size 2, so pointer to 1 byte starting at offset 5 is out-of-bounds
|
||||
--> $DIR/out_of_bounds_read2.rs:LL:CC
|
||||
error: Undefined Behavior: memory access failed: ALLOC has size 4, so pointer to 2 bytes starting at offset 5 is out-of-bounds
|
||||
--> $DIR/out_of_bounds_write.rs:LL:CC
|
||||
|
|
||||
LL | let x = unsafe { *v.as_ptr().wrapping_offset(5) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has size 2, so pointer to 1 byte starting at offset 5 is out-of-bounds
|
||||
LL | unsafe { *v.as_mut_ptr().wrapping_byte_add(5) = 0 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has size 4, so pointer to 2 bytes starting at offset 5 is out-of-bounds
|
||||
|
|
||||
= 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: ALLOC was allocated here:
|
||||
--> $DIR/out_of_bounds_read2.rs:LL:CC
|
||||
--> $DIR/out_of_bounds_write.rs:LL:CC
|
||||
|
|
||||
LL | let v: Vec<u8> = vec![1, 2];
|
||||
LL | let mut v: Vec<u16> = vec![1, 2];
|
||||
| ^^^^^^^^^^
|
||||
= note: BACKTRACE (of the first span):
|
||||
= note: inside `main` at $DIR/out_of_bounds_read2.rs:LL:CC
|
||||
= note: inside `main` at $DIR/out_of_bounds_write.rs:LL:CC
|
||||
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
|
@ -1,8 +1,8 @@
|
|||
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
--> $DIR/alignment.rs:LL:CC
|
||||
|
|
||||
LL | *(x_ptr as *mut u32) = 42; *(x_ptr.add(1) as *mut u32) = 42;
|
||||
| ^ accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
| ^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
|
|
||||
= 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
|
||||
|
|
|
@ -8,7 +8,7 @@ pub struct S {
|
|||
}
|
||||
|
||||
unsafe fn foo(x: *const S) -> u8 {
|
||||
unsafe { (*x).x } //~ERROR: accessing memory with alignment 1, but alignment 4 is required
|
||||
unsafe { (*x).x } //~ERROR: based on pointer with alignment 1, but alignment 4 is required
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
--> $DIR/field_requires_parent_struct_alignment.rs:LL:CC
|
||||
|
|
||||
LL | unsafe { (*x).x }
|
||||
| ^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
| ^^^^^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
|
|
||||
= 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
|
||||
|
|
|
@ -15,7 +15,7 @@ pub struct Packed {
|
|||
}
|
||||
|
||||
unsafe fn foo(x: *const Aligned) -> u8 {
|
||||
unsafe { (*x).packed.x } //~ERROR: accessing memory with alignment 1, but alignment 16 is required
|
||||
unsafe { (*x).packed.x } //~ERROR: based on pointer with alignment 1, but alignment 16 is required
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
--> $DIR/field_requires_parent_struct_alignment2.rs:LL:CC
|
||||
|
|
||||
LL | unsafe { (*x).packed.x }
|
||||
| ^^^^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
| ^^^^^^^^^^^^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
|
|
||||
= 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
|
||||
|
|
|
@ -12,6 +12,6 @@ fn main() {
|
|||
// Manually make sure the pointer is properly aligned.
|
||||
let base_addr_aligned = if base_addr % 2 == 0 { base_addr } else { base_addr + 1 };
|
||||
let u16_ptr = base_addr_aligned as *mut u16;
|
||||
unsafe { *u16_ptr = 2 }; //~ERROR: memory with alignment 1, but alignment 2 is required
|
||||
unsafe { *u16_ptr = 2 }; //~ERROR: with alignment 1, but alignment 2 is required
|
||||
println!("{:?}", x);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
--> $DIR/intptrcast_alignment_check.rs:LL:CC
|
||||
|
|
||||
LL | unsafe { *u16_ptr = 2 };
|
||||
| ^^^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
| ^^^^^^^^^^^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
|
|
||||
= help: this usually indicates that your program performed an invalid operation and caused Undefined Behavior
|
||||
= help: but due to `-Zmiri-symbolic-alignment-check`, alignment errors can also be false positives
|
||||
|
|
|
@ -7,6 +7,6 @@ fn main() {
|
|||
let x = [2u16, 3, 4]; // Make it big enough so we don't get an out-of-bounds error.
|
||||
let x = &x[0] as *const _ as *const u32;
|
||||
// This must fail because alignment is violated: the allocation's base is not sufficiently aligned.
|
||||
let _x = unsafe { *x }; //~ERROR: memory with alignment 2, but alignment 4 is required
|
||||
let _x = unsafe { *x }; //~ERROR: with alignment 2, but alignment 4 is required
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
--> $DIR/unaligned_ptr1.rs:LL:CC
|
||||
|
|
||||
LL | let _x = unsafe { *x };
|
||||
| ^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
| ^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
|
|
||||
= 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
|
||||
|
|
|
@ -8,5 +8,5 @@ fn main() {
|
|||
let x = (x.as_ptr() as *const u8).wrapping_offset(3) as *const u32;
|
||||
// This must fail because alignment is violated: the offset is not sufficiently aligned.
|
||||
// Also make the offset not a power of 2, that used to ICE.
|
||||
let _x = unsafe { *x }; //~ERROR: memory with alignment 1, but alignment 4 is required
|
||||
let _x = unsafe { *x }; //~ERROR: with alignment 1, but alignment 4 is required
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
--> $DIR/unaligned_ptr2.rs:LL:CC
|
||||
|
|
||||
LL | let _x = unsafe { *x };
|
||||
| ^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
| ^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
|
|
||||
= 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
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
--> $DIR/unaligned_ptr3.rs:LL:CC
|
||||
|
|
||||
LL | let _x = unsafe { *x };
|
||||
| ^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
| ^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
|
|
||||
= 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
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
--> $DIR/unaligned_ptr4.rs:LL:CC
|
||||
|
|
||||
LL | let _val = unsafe { *ptr };
|
||||
| ^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
| ^^^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
|
|
||||
= 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
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
--> $DIR/unaligned_ptr_zst.rs:LL:CC
|
||||
|
|
||||
LL | let _x = unsafe { *x };
|
||||
| ^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
|
||||
| ^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
|
||||
|
|
||||
= 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
|
||||
|
|
|
@ -7,14 +7,14 @@ const MISALIGNED_LOAD: () = unsafe {
|
|||
let mem = [0u32; 8];
|
||||
let ptr = mem.as_ptr().byte_add(1);
|
||||
let _val = *ptr; //~ERROR: evaluation of constant value failed
|
||||
//~^NOTE: accessing memory with alignment 1, but alignment 4 is required
|
||||
//~^NOTE: based on pointer with alignment 1, but alignment 4 is required
|
||||
};
|
||||
|
||||
const MISALIGNED_STORE: () = unsafe {
|
||||
let mut mem = [0u32; 8];
|
||||
let ptr = mem.as_mut_ptr().byte_add(1);
|
||||
*ptr = 0; //~ERROR: evaluation of constant value failed
|
||||
//~^NOTE: accessing memory with alignment 1, but alignment 4 is required
|
||||
//~^NOTE: based on pointer with alignment 1, but alignment 4 is required
|
||||
};
|
||||
|
||||
const MISALIGNED_COPY: () = unsafe {
|
||||
|
@ -34,7 +34,7 @@ const MISALIGNED_FIELD: () = unsafe {
|
|||
let ptr = mem.as_ptr().cast::<Aligned>();
|
||||
// Accessing an f32 field but we still require the alignment of the pointer type.
|
||||
let _val = (*ptr).0; //~ERROR: evaluation of constant value failed
|
||||
//~^NOTE: accessing memory with alignment 4, but alignment 16 is required
|
||||
//~^NOTE: based on pointer with alignment 4, but alignment 16 is required
|
||||
};
|
||||
|
||||
const OOB: () = unsafe {
|
||||
|
|
|
@ -2,13 +2,13 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/raw-pointer-ub.rs:9:16
|
||||
|
|
||||
LL | let _val = *ptr;
|
||||
| ^^^^ accessing memory with alignment 1, but alignment 4 is required
|
||||
| ^^^^ accessing memory based on pointer with alignment 1, but alignment 4 is required
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/raw-pointer-ub.rs:16:5
|
||||
|
|
||||
LL | *ptr = 0;
|
||||
| ^^^^^^^^ accessing memory with alignment 1, but alignment 4 is required
|
||||
| ^^^^^^^^ accessing memory based on pointer with alignment 1, but alignment 4 is required
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
|
||||
|
@ -29,7 +29,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/raw-pointer-ub.rs:36:16
|
||||
|
|
||||
LL | let _val = (*ptr).0;
|
||||
| ^^^^^^^^ accessing memory with alignment 4, but alignment 16 is required
|
||||
| ^^^^^^^^ accessing memory based on pointer with alignment 4, but alignment 16 is required
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/raw-pointer-ub.rs:43:16
|
||||
|
|
|
@ -151,7 +151,7 @@ LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
|
|||
error[E0080]: evaluation of constant value failed
|
||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
|
|
||||
= note: accessing memory with alignment 1, but alignment 4 is required
|
||||
= note: accessing memory based on pointer with alignment 1, but alignment 4 is required
|
||||
|
|
||||
note: inside `std::ptr::read::<u32>`
|
||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue