Skip to content

Commit

Permalink
fix error reporting in validation
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 22, 2018
1 parent 899bc14 commit 4fec615
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc::ty::layout::{self, Size, Primitive};
use rustc::ty::{self, Ty};
use rustc_data_structures::fx::FxHashSet;
use rustc::mir::interpret::{
Scalar, AllocType, EvalResult, ScalarMaybeUndef,
Scalar, AllocType, EvalResult, ScalarMaybeUndef, EvalErrorKind
};

use super::{
Expand Down Expand Up @@ -285,15 +285,22 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
// This is a fat pointer.
let ptr = match self.ref_to_mplace(self.read_value(dest.into())?) {
Ok(ptr) => ptr,
Err(ReadPointerAsBytes) =>
return validation_failure!("fat pointer length is not a valid integer", path),
Err(ReadBytesAsPointer) =>
return validation_failure!("fat pointer vtable is not a valid pointer", path),
Err(err) => return Err(err),
Err(err) => match err.kind {
EvalErrorKind::ReadPointerAsBytes =>
return validation_failure!(
"fat pointer length is not a valid integer", path
),
EvalErrorKind::ReadBytesAsPointer =>
return validation_failure!(
"fat pointer vtable is not a valid pointer", path
),
_ => return Err(err),
}
};
let unpacked_ptr = self.unpack_unsized_mplace(ptr)?;
// for safe ptrs, recursively check it
if !dest.layout.ty.is_unsafe_ptr() {
trace!("Recursing below fat ptr {:?} (unpacked: {:?})", ptr, unpacked_ptr);
if seen.insert(unpacked_ptr) {
todo.push((unpacked_ptr, path_clone_and_deref(path)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/union-ub-fat-ptr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ error[E0080]: this constant likely exhibits undefined behavior
--> $DIR/union-ub-fat-ptr.rs:104:1
|
LL | const F: &Trait = unsafe { DynTransmute { bad: BadDynRepr { ptr: &92, vtable: 3 } }.rust};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered fat pointer length is not a valid integer
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered fat pointer vtable is not a valid pointer
|
= 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

Expand Down

0 comments on commit 4fec615

Please sign in to comment.