Skip to content

Commit 0682894

Browse files
committed
more precise error for 'based on misaligned pointer' case
1 parent b3d640a commit 0682894

31 files changed

+112
-91
lines changed

compiler/rustc_const_eval/messages.ftl

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
const_eval_address_space_full =
22
there are no more free addresses in the address space
3-
const_eval_align_check_failed = accessing memory with alignment {$has}, but alignment {$required} is required
3+
44
const_eval_align_offset_invalid_align =
55
`align_offset` called with non-power-of-two align: {$target_align}
66
77
const_eval_alignment_check_failed =
8-
accessing memory with alignment {$has}, but alignment {$required} is required
8+
{$msg ->
9+
[AccessedPtr] accessing memory
10+
*[other] accessing memory based on pointer
11+
} with alignment {$has}, but alignment {$required} is required
12+
913
const_eval_already_reported =
1014
an error has already been reported elsewhere (this should not usually be printed)
1115
const_eval_assume_false =

compiler/rustc_const_eval/src/errors.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,6 @@ pub struct LiveDrop<'tcx> {
390390
pub dropped_at: Option<Span>,
391391
}
392392

393-
#[derive(LintDiagnostic)]
394-
#[diag(const_eval_align_check_failed)]
395-
pub struct AlignmentCheckFailed {
396-
pub has: u64,
397-
pub required: u64,
398-
#[subdiagnostic]
399-
pub frames: Vec<FrameNote>,
400-
}
401-
402393
#[derive(Diagnostic)]
403394
#[diag(const_eval_error, code = "E0080")]
404395
pub struct ConstEvalError {
@@ -568,9 +559,10 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
568559

569560
builder.set_arg("bad_pointer_message", bad_pointer_message(msg, handler));
570561
}
571-
AlignmentCheckFailed(Misalignment { required, has }) => {
562+
AlignmentCheckFailed(Misalignment { required, has }, msg) => {
572563
builder.set_arg("required", required.bytes());
573564
builder.set_arg("has", has.bytes());
565+
builder.set_arg("msg", format!("{msg:?}"));
574566
}
575567
WriteToReadOnly(alloc) | DerefFunctionPointer(alloc) | DerefVTablePointer(alloc) => {
576568
builder.set_arg("allocation", alloc);

compiler/rustc_const_eval/src/interpret/memory.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use rustc_target::abi::{Align, HasDataLayout, Size};
2121
use crate::fluent_generated as fluent;
2222

2323
use super::{
24-
alloc_range, AllocBytes, AllocId, AllocMap, AllocRange, Allocation, CheckInAllocMsg,
25-
GlobalAlloc, InterpCx, InterpResult, Machine, MayLeak, Misalignment, Pointer,
24+
alloc_range, AllocBytes, AllocId, AllocMap, AllocRange, Allocation, CheckAlignMsg,
25+
CheckInAllocMsg, GlobalAlloc, InterpCx, InterpResult, Machine, MayLeak, Misalignment, Pointer,
2626
PointerArithmetic, Provenance, Scalar,
2727
};
2828

@@ -425,7 +425,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
425425
}
426426
// Must be aligned.
427427
if M::enforce_alignment(self) && align.bytes() > 1 {
428-
self.check_misalign(Self::offset_misalignment(addr, align))?;
428+
self.check_misalign(
429+
Self::offset_misalignment(addr, align),
430+
CheckAlignMsg::AccessedPtr,
431+
)?;
429432
}
430433
None
431434
}
@@ -449,7 +452,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
449452
// Test align. Check this last; if both bounds and alignment are violated
450453
// we want the error to be about the bounds.
451454
if M::enforce_alignment(self) && align.bytes() > 1 {
452-
self.check_misalign(self.alloc_misalignment(ptr, offset, align, alloc_align))?;
455+
self.check_misalign(
456+
self.alloc_misalignment(ptr, offset, align, alloc_align),
457+
CheckAlignMsg::AccessedPtr,
458+
)?;
453459
}
454460

455461
// 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> {
460466
}
461467

462468
#[inline(always)]
463-
pub(super) fn check_misalign(&self, misaligned: Option<Misalignment>) -> InterpResult<'tcx> {
469+
pub(super) fn check_misalign(
470+
&self,
471+
misaligned: Option<Misalignment>,
472+
msg: CheckAlignMsg,
473+
) -> InterpResult<'tcx> {
464474
if let Some(misaligned) = misaligned {
465-
throw_ub!(AlignmentCheckFailed(misaligned))
475+
throw_ub!(AlignmentCheckFailed(misaligned, msg))
466476
}
467477
Ok(())
468478
}

compiler/rustc_const_eval/src/interpret/place.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use rustc_middle::ty::Ty;
1515
use rustc_target::abi::{Abi, Align, FieldIdx, HasDataLayout, Size, FIRST_VARIANT};
1616

1717
use super::{
18-
alloc_range, mir_assign_valid_types, AllocId, AllocRef, AllocRefMut, ImmTy, Immediate,
19-
InterpCx, InterpResult, Machine, MemoryKind, Misalignment, OffsetMode, OpTy, Operand, Pointer,
20-
PointerArithmetic, Projectable, Provenance, Readable, Scalar,
18+
alloc_range, mir_assign_valid_types, AllocId, AllocRef, AllocRefMut, CheckAlignMsg, ImmTy,
19+
Immediate, InterpCx, InterpResult, Machine, MemoryKind, Misalignment, OffsetMode, OpTy,
20+
Operand, Pointer, PointerArithmetic, Projectable, Provenance, Readable, Scalar,
2121
};
2222

2323
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
@@ -461,7 +461,7 @@ where
461461
// We check alignment separately, and *after* checking everything else.
462462
// If an access is both OOB and misaligned, we want to see the bounds error.
463463
let a = self.get_ptr_alloc(mplace.ptr(), size, Align::ONE)?;
464-
self.check_misalign(mplace.mplace.misaligned)?;
464+
self.check_misalign(mplace.mplace.misaligned, CheckAlignMsg::BasedOn)?;
465465
Ok(a)
466466
}
467467

@@ -477,7 +477,7 @@ where
477477
// We check alignment separately, and raise that error *after* checking everything else.
478478
// If an access is both OOB and misaligned, we want to see the bounds error.
479479
// However we have to call `check_misalign` first to make the borrow checker happy.
480-
let misalign_err = self.check_misalign(mplace.mplace.misaligned);
480+
let misalign_err = self.check_misalign(mplace.mplace.misaligned, CheckAlignMsg::BasedOn);
481481
let a = self.get_ptr_alloc_mut(mplace.ptr(), size, Align::ONE)?;
482482
misalign_err?;
483483
Ok(a)
@@ -881,8 +881,8 @@ where
881881
dest_size,
882882
/*nonoverlapping*/ true,
883883
)?;
884-
self.check_misalign(src.mplace.misaligned)?;
885-
self.check_misalign(dest.mplace.misaligned)?;
884+
self.check_misalign(src.mplace.misaligned, CheckAlignMsg::BasedOn)?;
885+
self.check_misalign(dest.mplace.misaligned, CheckAlignMsg::BasedOn)?;
886886
Ok(())
887887
}
888888

compiler/rustc_const_eval/src/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
385385
CheckInAllocMsg::InboundsTest, // will anyway be replaced by validity message
386386
),
387387
self.path,
388-
Ub(AlignmentCheckFailed(Misalignment { required, has })) => UnalignedPtr {
388+
Ub(AlignmentCheckFailed(Misalignment { required, has }, _msg)) => UnalignedPtr {
389389
ptr_kind,
390390
required_bytes: required.bytes(),
391391
found_bytes: has.bytes()

compiler/rustc_middle/src/mir/interpret/error.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub enum InvalidProgramInfo<'tcx> {
216216
}
217217

218218
/// Details of why a pointer had to be in-bounds.
219-
#[derive(Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
219+
#[derive(Debug, Copy, Clone)]
220220
pub enum CheckInAllocMsg {
221221
/// We are access memory.
222222
MemoryAccessTest,
@@ -228,7 +228,16 @@ pub enum CheckInAllocMsg {
228228
InboundsTest,
229229
}
230230

231-
#[derive(Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
231+
/// Details of which pointer is not aligned.
232+
#[derive(Debug, Copy, Clone)]
233+
pub enum CheckAlignMsg {
234+
/// The accessed pointer did not have proper alignment.
235+
AccessedPtr,
236+
/// The access ocurred with a place that was based on a misaligned pointer.
237+
BasedOn,
238+
}
239+
240+
#[derive(Debug, Copy, Clone)]
232241
pub enum InvalidMetaKind {
233242
/// Size of a `[T]` is too big
234243
SliceTooBig,
@@ -329,7 +338,7 @@ pub enum UndefinedBehaviorInfo<'tcx> {
329338
/// Using an integer as a pointer in the wrong way.
330339
DanglingIntPointer(u64, CheckInAllocMsg),
331340
/// Used a pointer with bad alignment.
332-
AlignmentCheckFailed(Misalignment),
341+
AlignmentCheckFailed(Misalignment, CheckAlignMsg),
333342
/// Writing to read-only memory.
334343
WriteToReadOnly(AllocId),
335344
/// Trying to access the data behind a function pointer.

compiler/rustc_middle/src/mir/interpret/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,12 @@ use crate::ty::GenericArgKind;
142142
use crate::ty::{self, Instance, Ty, TyCtxt};
143143

144144
pub use self::error::{
145-
struct_error, BadBytesAccess, CheckInAllocMsg, ErrorHandled, EvalToAllocationRawResult,
146-
EvalToConstValueResult, EvalToValTreeResult, ExpectedKind, InterpError, InterpErrorInfo,
147-
InterpResult, InvalidMetaKind, InvalidProgramInfo, MachineStopType, Misalignment, PointerKind,
148-
ReportedErrorInfo, ResourceExhaustionInfo, ScalarSizeMismatch, UndefinedBehaviorInfo,
149-
UnsupportedOpInfo, ValidationErrorInfo, ValidationErrorKind,
145+
struct_error, BadBytesAccess, CheckAlignMsg, CheckInAllocMsg, ErrorHandled,
146+
EvalToAllocationRawResult, EvalToConstValueResult, EvalToValTreeResult, ExpectedKind,
147+
InterpError, InterpErrorInfo, InterpResult, InvalidMetaKind, InvalidProgramInfo,
148+
MachineStopType, Misalignment, PointerKind, ReportedErrorInfo, ResourceExhaustionInfo,
149+
ScalarSizeMismatch, UndefinedBehaviorInfo, UnsupportedOpInfo, ValidationErrorInfo,
150+
ValidationErrorKind,
150151
};
151152

152153
pub use self::value::Scalar;

src/tools/miri/tests/fail/const-ub-checks.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
22
--> $DIR/const-ub-checks.rs:LL:CC
33
|
44
LL | ptr.read();
5-
| ^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
5+
| ^^^^^^^^^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
66

77
note: erroneous constant encountered
88
--> $DIR/const-ub-checks.rs:LL:CC
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(pointer_byte_offsets)]
2+
3+
fn main() {
4+
let v: Vec<u16> = vec![1, 2];
5+
// This read is also misaligned. We make sure that the OOB message has priority.
6+
let x = unsafe { *v.as_ptr().wrapping_byte_add(5) }; //~ ERROR: out-of-bounds
7+
panic!("this should never print: {}", x);
8+
}

src/tools/miri/tests/fail/dangling_pointers/out_of_bounds_read1.stderr renamed to src/tools/miri/tests/fail/dangling_pointers/out_of_bounds_read.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
error: Undefined Behavior: memory access failed: ALLOC has size 2, so pointer to 1 byte starting at offset 5 is out-of-bounds
2-
--> $DIR/out_of_bounds_read1.rs:LL:CC
1+
error: Undefined Behavior: memory access failed: ALLOC has size 4, so pointer to 2 bytes starting at offset 5 is out-of-bounds
2+
--> $DIR/out_of_bounds_read.rs:LL:CC
33
|
4-
LL | let x = unsafe { *v.as_ptr().wrapping_offset(5) };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has size 2, so pointer to 1 byte starting at offset 5 is out-of-bounds
4+
LL | let x = unsafe { *v.as_ptr().wrapping_byte_add(5) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has size 4, so pointer to 2 bytes starting at offset 5 is out-of-bounds
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
help: ALLOC was allocated here:
10-
--> $DIR/out_of_bounds_read1.rs:LL:CC
10+
--> $DIR/out_of_bounds_read.rs:LL:CC
1111
|
12-
LL | let v: Vec<u8> = vec![1, 2];
13-
| ^^^^^^^^^^
12+
LL | let v: Vec<u16> = vec![1, 2];
13+
| ^^^^^^^^^^
1414
= note: BACKTRACE (of the first span):
15-
= note: inside `main` at $DIR/out_of_bounds_read1.rs:LL:CC
15+
= note: inside `main` at $DIR/out_of_bounds_read.rs:LL:CC
1616
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
1717

1818
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

src/tools/miri/tests/fail/dangling_pointers/out_of_bounds_read1.rs

-5
This file was deleted.

src/tools/miri/tests/fail/dangling_pointers/out_of_bounds_read2.rs

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(pointer_byte_offsets)]
2+
3+
fn main() {
4+
let mut v: Vec<u16> = vec![1, 2];
5+
// This read is also misaligned. We make sure that the OOB message has priority.
6+
unsafe { *v.as_mut_ptr().wrapping_byte_add(5) = 0 }; //~ ERROR: out-of-bounds
7+
}

src/tools/miri/tests/fail/dangling_pointers/out_of_bounds_read2.stderr renamed to src/tools/miri/tests/fail/dangling_pointers/out_of_bounds_write.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
error: Undefined Behavior: memory access failed: ALLOC has size 2, so pointer to 1 byte starting at offset 5 is out-of-bounds
2-
--> $DIR/out_of_bounds_read2.rs:LL:CC
1+
error: Undefined Behavior: memory access failed: ALLOC has size 4, so pointer to 2 bytes starting at offset 5 is out-of-bounds
2+
--> $DIR/out_of_bounds_write.rs:LL:CC
33
|
4-
LL | let x = unsafe { *v.as_ptr().wrapping_offset(5) };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has size 2, so pointer to 1 byte starting at offset 5 is out-of-bounds
4+
LL | unsafe { *v.as_mut_ptr().wrapping_byte_add(5) = 0 };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: ALLOC has size 4, so pointer to 2 bytes starting at offset 5 is out-of-bounds
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
help: ALLOC was allocated here:
10-
--> $DIR/out_of_bounds_read2.rs:LL:CC
10+
--> $DIR/out_of_bounds_write.rs:LL:CC
1111
|
12-
LL | let v: Vec<u8> = vec![1, 2];
13-
| ^^^^^^^^^^
12+
LL | let mut v: Vec<u16> = vec![1, 2];
13+
| ^^^^^^^^^^
1414
= note: BACKTRACE (of the first span):
15-
= note: inside `main` at $DIR/out_of_bounds_read2.rs:LL:CC
15+
= note: inside `main` at $DIR/out_of_bounds_write.rs:LL:CC
1616
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
1717

1818
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

src/tools/miri/tests/fail/unaligned_pointers/alignment.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
1+
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
22
--> $DIR/alignment.rs:LL:CC
33
|
44
LL | *(x_ptr as *mut u32) = 42; *(x_ptr.add(1) as *mut u32) = 42;
5-
| ^ accessing memory with alignment ALIGN, but alignment ALIGN is required
5+
| ^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/unaligned_pointers/field_requires_parent_struct_alignment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct S {
88
}
99

1010
unsafe fn foo(x: *const S) -> u8 {
11-
unsafe { (*x).x } //~ERROR: accessing memory with alignment 1, but alignment 4 is required
11+
unsafe { (*x).x } //~ERROR: based on pointer with alignment 1, but alignment 4 is required
1212
}
1313

1414
fn main() {

src/tools/miri/tests/fail/unaligned_pointers/field_requires_parent_struct_alignment.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
1+
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
22
--> $DIR/field_requires_parent_struct_alignment.rs:LL:CC
33
|
44
LL | unsafe { (*x).x }
5-
| ^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
5+
| ^^^^^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/unaligned_pointers/field_requires_parent_struct_alignment2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct Packed {
1515
}
1616

1717
unsafe fn foo(x: *const Aligned) -> u8 {
18-
unsafe { (*x).packed.x } //~ERROR: accessing memory with alignment 1, but alignment 16 is required
18+
unsafe { (*x).packed.x } //~ERROR: based on pointer with alignment 1, but alignment 16 is required
1919
}
2020

2121
fn main() {

src/tools/miri/tests/fail/unaligned_pointers/field_requires_parent_struct_alignment2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
1+
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
22
--> $DIR/field_requires_parent_struct_alignment2.rs:LL:CC
33
|
44
LL | unsafe { (*x).packed.x }
5-
| ^^^^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
5+
| ^^^^^^^^^^^^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/unaligned_pointers/intptrcast_alignment_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ fn main() {
1212
// Manually make sure the pointer is properly aligned.
1313
let base_addr_aligned = if base_addr % 2 == 0 { base_addr } else { base_addr + 1 };
1414
let u16_ptr = base_addr_aligned as *mut u16;
15-
unsafe { *u16_ptr = 2 }; //~ERROR: memory with alignment 1, but alignment 2 is required
15+
unsafe { *u16_ptr = 2 }; //~ERROR: with alignment 1, but alignment 2 is required
1616
println!("{:?}", x);
1717
}

src/tools/miri/tests/fail/unaligned_pointers/intptrcast_alignment_check.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
1+
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
22
--> $DIR/intptrcast_alignment_check.rs:LL:CC
33
|
44
LL | unsafe { *u16_ptr = 2 };
5-
| ^^^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
5+
| ^^^^^^^^^^^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
66
|
77
= help: this usually indicates that your program performed an invalid operation and caused Undefined Behavior
88
= help: but due to `-Zmiri-symbolic-alignment-check`, alignment errors can also be false positives

src/tools/miri/tests/fail/unaligned_pointers/unaligned_ptr1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ fn main() {
77
let x = [2u16, 3, 4]; // Make it big enough so we don't get an out-of-bounds error.
88
let x = &x[0] as *const _ as *const u32;
99
// This must fail because alignment is violated: the allocation's base is not sufficiently aligned.
10-
let _x = unsafe { *x }; //~ERROR: memory with alignment 2, but alignment 4 is required
10+
let _x = unsafe { *x }; //~ERROR: with alignment 2, but alignment 4 is required
1111
}
1212
}

src/tools/miri/tests/fail/unaligned_pointers/unaligned_ptr1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
1+
error: Undefined Behavior: accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
22
--> $DIR/unaligned_ptr1.rs:LL:CC
33
|
44
LL | let _x = unsafe { *x };
5-
| ^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
5+
| ^^ accessing memory based on pointer with alignment ALIGN, but alignment ALIGN is required
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/unaligned_pointers/unaligned_ptr2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ fn main() {
88
let x = (x.as_ptr() as *const u8).wrapping_offset(3) as *const u32;
99
// This must fail because alignment is violated: the offset is not sufficiently aligned.
1010
// Also make the offset not a power of 2, that used to ICE.
11-
let _x = unsafe { *x }; //~ERROR: memory with alignment 1, but alignment 4 is required
11+
let _x = unsafe { *x }; //~ERROR: with alignment 1, but alignment 4 is required
1212
}

0 commit comments

Comments
 (0)