Skip to content

Commit 1f73d8d

Browse files
authored
Rollup merge of #71972 - RalfJung:miri-validity-error-refine, r=oli-obk
use hex for pointers in Miri error messages Also refine vtable error message: distinguish between "drop fn does not point to a function" and "drop fn points to a function with the wrong signature".
2 parents 586a585 + d1ea287 commit 1f73d8d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/librustc_mir/interpret/validity.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
321321
try_validation!(
322322
self.ecx.read_drop_type_from_vtable(vtable),
323323
self.path,
324-
err_ub!(InvalidDropFn(..)) |
325324
err_ub!(DanglingIntPointer(..)) |
326325
err_ub!(InvalidFunctionPointer(..)) |
327326
err_unsup!(ReadBytesAsPointer) =>
328-
{ "invalid drop function pointer in vtable" },
327+
{ "invalid drop function pointer in vtable (not pointing to a function)" },
328+
err_ub!(InvalidDropFn(..)) =>
329+
{ "invalid drop function pointer in vtable (function has incompatible signature)" },
329330
);
330331
try_validation!(
331332
self.ecx.read_size_and_align_from_vtable(vtable),
@@ -400,7 +401,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
400401
err_ub!(DanglingIntPointer(0, _)) =>
401402
{ "a NULL {}", kind },
402403
err_ub!(DanglingIntPointer(i, _)) =>
403-
{ "a dangling {} (address {} is unallocated)", kind, i },
404+
{ "a dangling {} (address 0x{:x} is unallocated)", kind, i },
404405
err_ub!(PointerOutOfBounds { .. }) =>
405406
{ "a dangling {} (going beyond the bounds of its allocation)", kind },
406407
err_unsup!(ReadBytesAsPointer) =>

src/test/ui/consts/const-eval/ub-wide-ptr.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,23 @@ error[E0080]: it is undefined behavior to use this value
170170
--> $DIR/ub-wide-ptr.rs:109:1
171171
|
172172
LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) };
173-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable
173+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable (not pointing to a function)
174174
|
175175
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
176176

177177
error[E0080]: it is undefined behavior to use this value
178178
--> $DIR/ub-wide-ptr.rs:111:1
179179
|
180180
LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) };
181-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable
181+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable (not pointing to a function)
182182
|
183183
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
184184

185185
error[E0080]: it is undefined behavior to use this value
186186
--> $DIR/ub-wide-ptr.rs:113:1
187187
|
188188
LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: &dyn Trait = unsafe { mem::transmute((&92u8, &[&42u8; 8])) };
189-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable
189+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable (not pointing to a function)
190190
|
191191
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
192192

0 commit comments

Comments
 (0)