1
Fork 0

on a signed deref check, mention the right pointer in the error

This commit is contained in:
Ralf Jung 2024-07-29 16:40:21 +02:00
parent 70591dc15d
commit de78cb56b2
34 changed files with 192 additions and 141 deletions

View file

@ -334,14 +334,15 @@ pub enum UndefinedBehaviorInfo<'tcx> {
alloc_size: Size,
ptr_offset: i64,
/// The size of the memory range that was expected to be in-bounds.
inbounds_size: Size,
inbounds_size: i64,
msg: CheckInAllocMsg,
},
/// Using an integer as a pointer in the wrong way.
DanglingIntPointer {
addr: u64,
/// The size of the memory range that was expected to be in-bounds (or 0 if we don't know).
inbounds_size: Size,
/// The size of the memory range that was expected to be in-bounds (or 0 if we need an
/// allocation but not any actual memory there, e.g. for function pointers).
inbounds_size: i64,
msg: CheckInAllocMsg,
},
/// Used a pointer with bad alignment.

View file

@ -181,12 +181,9 @@ impl Provenance for CtfeProvenance {
fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Print AllocId.
fmt::Debug::fmt(&ptr.provenance.alloc_id(), f)?; // propagates `alternate` flag
// Print offset only if it is non-zero. Print it signed.
let signed_offset = ptr.offset.bytes() as i64;
if signed_offset > 0 {
write!(f, "+{:#x}", signed_offset)?;
} else if signed_offset < 0 {
write!(f, "-{:#x}", signed_offset.unsigned_abs())?;
// Print offset only if it is non-zero.
if ptr.offset.bytes() > 0 {
write!(f, "+{:#x}", ptr.offset.bytes())?;
}
// Print immutable status.
if ptr.provenance.immutable() {