Skip to content

Commit 4fec615

Browse files
committed
fix error reporting in validation
1 parent 899bc14 commit 4fec615

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/librustc_mir/interpret/validity.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc::ty::layout::{self, Size, Primitive};
55
use rustc::ty::{self, Ty};
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc::mir::interpret::{
8-
Scalar, AllocType, EvalResult, ScalarMaybeUndef,
8+
Scalar, AllocType, EvalResult, ScalarMaybeUndef, EvalErrorKind
99
};
1010

1111
use super::{
@@ -285,15 +285,22 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
285285
// This is a fat pointer.
286286
let ptr = match self.ref_to_mplace(self.read_value(dest.into())?) {
287287
Ok(ptr) => ptr,
288-
Err(ReadPointerAsBytes) =>
289-
return validation_failure!("fat pointer length is not a valid integer", path),
290-
Err(ReadBytesAsPointer) =>
291-
return validation_failure!("fat pointer vtable is not a valid pointer", path),
292-
Err(err) => return Err(err),
288+
Err(err) => match err.kind {
289+
EvalErrorKind::ReadPointerAsBytes =>
290+
return validation_failure!(
291+
"fat pointer length is not a valid integer", path
292+
),
293+
EvalErrorKind::ReadBytesAsPointer =>
294+
return validation_failure!(
295+
"fat pointer vtable is not a valid pointer", path
296+
),
297+
_ => return Err(err),
298+
}
293299
};
294300
let unpacked_ptr = self.unpack_unsized_mplace(ptr)?;
295301
// for safe ptrs, recursively check it
296302
if !dest.layout.ty.is_unsafe_ptr() {
303+
trace!("Recursing below fat ptr {:?} (unpacked: {:?})", ptr, unpacked_ptr);
297304
if seen.insert(unpacked_ptr) {
298305
todo.push((unpacked_ptr, path_clone_and_deref(path)));
299306
}

src/test/ui/union-ub-fat-ptr.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ error[E0080]: this constant likely exhibits undefined behavior
5858
--> $DIR/union-ub-fat-ptr.rs:104:1
5959
|
6060
LL | const F: &Trait = unsafe { DynTransmute { bad: BadDynRepr { ptr: &92, vtable: 3 } }.rust};
61-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered fat pointer length is not a valid integer
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered fat pointer vtable is not a valid pointer
6262
|
6363
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
6464

0 commit comments

Comments
 (0)