diff options
| author | Ralf Jung <post@ralfj.de> | 2018-08-22 12:02:09 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2018-08-22 13:08:40 +0200 |
| commit | 4fec615ebf604cf7ef952770650d93ad5b7b784e (patch) | |
| tree | aaff5c3f29f4d161fb65f0c3c878ad522a7beb16 | |
| parent | 899bc14cc08777bd6c5738c5697082b1cfbc7755 (diff) | |
| download | rust-4fec615ebf604cf7ef952770650d93ad5b7b784e.tar.gz rust-4fec615ebf604cf7ef952770650d93ad5b7b784e.zip | |
fix error reporting in validation
| -rw-r--r-- | src/librustc_mir/interpret/validity.rs | 19 | ||||
| -rw-r--r-- | src/test/ui/union-ub-fat-ptr.stderr | 2 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index 5eb32cd7eac..8f0e8196605 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -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::{ @@ -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))); } diff --git a/src/test/ui/union-ub-fat-ptr.stderr b/src/test/ui/union-ub-fat-ptr.stderr index 85a514ea99e..cc22422304d 100644 --- a/src/test/ui/union-ub-fat-ptr.stderr +++ b/src/test/ui/union-ub-fat-ptr.stderr @@ -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 |
