2018-11-02 09:33:26 +01:00
|
|
|
use std::fmt::Write;
|
2018-11-03 12:44:10 +01:00
|
|
|
use std::ops::RangeInclusive;
|
2018-08-17 12:18:02 +02:00
|
|
|
|
2019-05-22 19:25:39 +10:00
|
|
|
use syntax_pos::symbol::{sym, Symbol};
|
2018-11-26 20:58:59 +02:00
|
|
|
use rustc::hir;
|
2019-08-25 14:47:01 +02:00
|
|
|
use rustc::ty::layout::{self, Size, TyLayout, LayoutOf, VariantIdx};
|
2018-11-02 09:33:26 +01:00
|
|
|
use rustc::ty;
|
2018-08-17 12:18:02 +02:00
|
|
|
use rustc_data_structures::fx::FxHashSet;
|
|
|
|
|
2019-02-10 14:59:13 +01:00
|
|
|
use std::hash::Hash;
|
|
|
|
|
2018-08-17 12:18:02 +02:00
|
|
|
use super::{
|
2019-07-31 12:48:54 +05:30
|
|
|
GlobalAlloc, InterpResult,
|
2019-08-25 13:57:46 +02:00
|
|
|
Scalar, OpTy, Machine, InterpCx, ValueVisitor, MPlaceTy,
|
2018-08-17 12:18:02 +02:00
|
|
|
};
|
|
|
|
|
2019-07-31 12:48:54 +05:30
|
|
|
macro_rules! throw_validation_failure {
|
2018-08-17 12:18:02 +02:00
|
|
|
($what:expr, $where:expr, $details:expr) => {{
|
2018-10-31 16:46:33 +01:00
|
|
|
let where_ = path_format(&$where);
|
2018-08-18 13:46:52 +02:00
|
|
|
let where_ = if where_.is_empty() {
|
2018-08-17 12:18:02 +02:00
|
|
|
String::new()
|
|
|
|
} else {
|
2018-08-18 13:46:52 +02:00
|
|
|
format!(" at {}", where_)
|
2018-08-17 12:18:02 +02:00
|
|
|
};
|
2019-07-30 20:18:50 +05:30
|
|
|
throw_unsup!(ValidationFailure(format!(
|
2018-08-17 12:18:02 +02:00
|
|
|
"encountered {}{}, but expected {}",
|
|
|
|
$what, where_, $details,
|
2019-07-29 13:06:42 +05:30
|
|
|
)))
|
2018-08-17 12:18:02 +02:00
|
|
|
}};
|
|
|
|
($what:expr, $where:expr) => {{
|
2018-10-31 16:46:33 +01:00
|
|
|
let where_ = path_format(&$where);
|
2018-08-18 13:46:52 +02:00
|
|
|
let where_ = if where_.is_empty() {
|
2018-08-17 12:18:02 +02:00
|
|
|
String::new()
|
|
|
|
} else {
|
2018-08-18 13:46:52 +02:00
|
|
|
format!(" at {}", where_)
|
2018-08-17 12:18:02 +02:00
|
|
|
};
|
2019-07-30 20:18:50 +05:30
|
|
|
throw_unsup!(ValidationFailure(format!(
|
2018-08-17 12:18:02 +02:00
|
|
|
"encountered {}{}",
|
|
|
|
$what, where_,
|
2019-07-29 13:06:42 +05:30
|
|
|
)))
|
2018-08-17 12:18:02 +02:00
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2018-10-02 17:02:58 +02:00
|
|
|
macro_rules! try_validation {
|
2018-10-02 18:07:40 +02:00
|
|
|
($e:expr, $what:expr, $where:expr, $details:expr) => {{
|
|
|
|
match $e {
|
|
|
|
Ok(x) => x,
|
2019-07-31 12:48:54 +05:30
|
|
|
Err(_) => throw_validation_failure!($what, $where, $details),
|
2018-10-02 18:07:40 +02:00
|
|
|
}
|
|
|
|
}};
|
|
|
|
|
2018-10-02 17:02:58 +02:00
|
|
|
($e:expr, $what:expr, $where:expr) => {{
|
|
|
|
match $e {
|
|
|
|
Ok(x) => x,
|
2019-07-31 12:48:54 +05:30
|
|
|
Err(_) => throw_validation_failure!($what, $where),
|
2018-10-02 17:02:58 +02:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2018-11-12 13:05:20 -05:00
|
|
|
/// We want to show a nice path to the invalid field for diagnostics,
|
2018-08-18 13:46:52 +02:00
|
|
|
/// but avoid string operations in the happy case where no error happens.
|
|
|
|
/// So we track a `Vec<PathElem>` where `PathElem` contains all the data we
|
|
|
|
/// need to later print something for the user.
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
|
|
pub enum PathElem {
|
|
|
|
Field(Symbol),
|
2018-11-07 16:45:07 +01:00
|
|
|
Variant(Symbol),
|
2019-05-05 22:53:56 +02:00
|
|
|
GeneratorState(VariantIdx),
|
2018-08-18 13:46:52 +02:00
|
|
|
ClosureVar(Symbol),
|
|
|
|
ArrayElem(usize),
|
|
|
|
TupleElem(usize),
|
|
|
|
Deref,
|
|
|
|
Tag,
|
2018-10-31 18:44:00 +01:00
|
|
|
DynDowncast,
|
2018-08-18 13:46:52 +02:00
|
|
|
}
|
|
|
|
|
2018-10-02 16:06:50 +02:00
|
|
|
/// State for tracking recursive validation of references
|
2019-02-10 14:59:13 +01:00
|
|
|
pub struct RefTracking<T, PATH = ()> {
|
2019-02-15 21:05:47 +01:00
|
|
|
pub seen: FxHashSet<T>,
|
2019-02-10 14:59:13 +01:00
|
|
|
pub todo: Vec<(T, PATH)>,
|
2018-10-02 16:06:50 +02:00
|
|
|
}
|
|
|
|
|
2019-02-10 14:59:13 +01:00
|
|
|
impl<T: Copy + Eq + Hash + std::fmt::Debug, PATH: Default> RefTracking<T, PATH> {
|
|
|
|
pub fn empty() -> Self {
|
|
|
|
RefTracking {
|
|
|
|
seen: FxHashSet::default(),
|
|
|
|
todo: vec![],
|
|
|
|
}
|
|
|
|
}
|
2019-02-15 21:05:47 +01:00
|
|
|
pub fn new(op: T) -> Self {
|
2019-02-10 14:59:13 +01:00
|
|
|
let mut ref_tracking_for_consts = RefTracking {
|
2018-10-16 10:44:26 +02:00
|
|
|
seen: FxHashSet::default(),
|
2019-02-10 14:59:13 +01:00
|
|
|
todo: vec![(op, PATH::default())],
|
2018-10-02 16:06:50 +02:00
|
|
|
};
|
2019-02-10 14:59:13 +01:00
|
|
|
ref_tracking_for_consts.seen.insert(op);
|
|
|
|
ref_tracking_for_consts
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn track(&mut self, op: T, path: impl FnOnce() -> PATH) {
|
|
|
|
if self.seen.insert(op) {
|
|
|
|
trace!("Recursing below ptr {:#?}", op);
|
|
|
|
let path = path();
|
|
|
|
// Remember to come back to this later.
|
|
|
|
self.todo.push((op, path));
|
|
|
|
}
|
2018-10-02 16:06:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-18 13:46:52 +02:00
|
|
|
/// Format a path
|
|
|
|
fn path_format(path: &Vec<PathElem>) -> String {
|
|
|
|
use self::PathElem::*;
|
|
|
|
|
|
|
|
let mut out = String::new();
|
|
|
|
for elem in path.iter() {
|
|
|
|
match elem {
|
2018-10-31 18:44:00 +01:00
|
|
|
Field(name) => write!(out, ".{}", name),
|
2018-11-07 16:45:07 +01:00
|
|
|
Variant(name) => write!(out, ".<downcast-variant({})>", name),
|
2019-05-05 22:53:56 +02:00
|
|
|
GeneratorState(idx) => write!(out, ".<generator-state({})>", idx.index()),
|
2018-10-31 18:44:00 +01:00
|
|
|
ClosureVar(name) => write!(out, ".<closure-var({})>", name),
|
|
|
|
TupleElem(idx) => write!(out, ".{}", idx),
|
|
|
|
ArrayElem(idx) => write!(out, "[{}]", idx),
|
2018-08-18 13:46:52 +02:00
|
|
|
Deref =>
|
|
|
|
// This does not match Rust syntax, but it is more readable for long paths -- and
|
|
|
|
// some of the other items here also are not Rust syntax. Actually we can't
|
|
|
|
// even use the usual syntax because we are just showing the projections,
|
|
|
|
// not the root.
|
2018-10-31 18:44:00 +01:00
|
|
|
write!(out, ".<deref>"),
|
|
|
|
Tag => write!(out, ".<enum-tag>"),
|
|
|
|
DynDowncast => write!(out, ".<dyn-downcast>"),
|
|
|
|
}.unwrap()
|
2018-08-18 13:46:52 +02:00
|
|
|
}
|
|
|
|
out
|
|
|
|
}
|
|
|
|
|
2018-11-03 12:44:10 +01:00
|
|
|
// Test if a range that wraps at overflow contains `test`
|
|
|
|
fn wrapping_range_contains(r: &RangeInclusive<u128>, test: u128) -> bool {
|
|
|
|
let (lo, hi) = r.clone().into_inner();
|
|
|
|
if lo > hi {
|
|
|
|
// Wrapped
|
|
|
|
(..=hi).contains(&test) || (lo..).contains(&test)
|
|
|
|
} else {
|
|
|
|
// Normal
|
|
|
|
r.contains(&test)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Formats such that a sentence like "expected something {}" to mean
|
|
|
|
// "expected something <in the given range>" makes sense.
|
|
|
|
fn wrapping_range_format(r: &RangeInclusive<u128>, max_hi: u128) -> String {
|
|
|
|
let (lo, hi) = r.clone().into_inner();
|
|
|
|
debug_assert!(hi <= max_hi);
|
|
|
|
if lo > hi {
|
|
|
|
format!("less or equal to {}, or greater or equal to {}", hi, lo)
|
2019-07-01 19:19:19 +02:00
|
|
|
} else if lo == hi {
|
|
|
|
format!("equal to {}", lo)
|
|
|
|
} else if lo == 0 {
|
|
|
|
debug_assert!(hi < max_hi, "should not be printing if the range covers everything");
|
|
|
|
format!("less or equal to {}", hi)
|
|
|
|
} else if hi == max_hi {
|
|
|
|
debug_assert!(lo > 0, "should not be printing if the range covers everything");
|
|
|
|
format!("greater or equal to {}", lo)
|
2018-11-03 12:44:10 +01:00
|
|
|
} else {
|
2019-07-01 19:19:19 +02:00
|
|
|
format!("in the range {:?}", r)
|
2018-11-03 12:44:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 22:03:44 +03:00
|
|
|
struct ValidityVisitor<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> {
|
2018-10-31 16:46:33 +01:00
|
|
|
/// The `path` may be pushed to, but the part that is present when a function
|
|
|
|
/// starts must not be changed! `visit_fields` and `visit_array` rely on
|
|
|
|
/// this stack discipline.
|
|
|
|
path: Vec<PathElem>,
|
2019-02-10 14:59:13 +01:00
|
|
|
ref_tracking_for_consts: Option<&'rt mut RefTracking<
|
|
|
|
MPlaceTy<'tcx, M::PointerTag>,
|
|
|
|
Vec<PathElem>,
|
|
|
|
>>,
|
2019-06-27 11:36:01 +02:00
|
|
|
ecx: &'rt InterpCx<'mir, 'tcx, M>,
|
2018-10-31 16:46:33 +01:00
|
|
|
}
|
|
|
|
|
2019-06-11 22:03:44 +03:00
|
|
|
impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M> {
|
2018-11-08 17:06:27 +01:00
|
|
|
fn aggregate_field_path_elem(
|
2018-10-31 18:44:00 +01:00
|
|
|
&mut self,
|
|
|
|
layout: TyLayout<'tcx>,
|
|
|
|
field: usize,
|
2018-11-08 17:06:27 +01:00
|
|
|
) -> PathElem {
|
|
|
|
match layout.ty.sty {
|
2018-10-31 18:44:00 +01:00
|
|
|
// generators and closures.
|
|
|
|
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
|
2018-11-26 20:58:59 +02:00
|
|
|
let mut name = None;
|
|
|
|
if def_id.is_local() {
|
|
|
|
let tables = self.ecx.tcx.typeck_tables_of(def_id);
|
|
|
|
if let Some(upvars) = tables.upvar_list.get(&def_id) {
|
2019-05-04 03:57:46 +03:00
|
|
|
// Sometimes the index is beyond the number of upvars (seen
|
2018-11-26 20:58:59 +02:00
|
|
|
// for a generator).
|
2019-05-14 19:42:57 +03:00
|
|
|
if let Some((&var_hir_id, _)) = upvars.get_index(field) {
|
2019-06-20 10:39:19 +02:00
|
|
|
let node = self.ecx.tcx.hir().get(var_hir_id);
|
2019-06-14 12:28:47 +02:00
|
|
|
if let hir::Node::Binding(pat) = node {
|
2018-11-26 20:58:59 +02:00
|
|
|
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
|
|
|
|
name = Some(ident.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-31 18:44:00 +01:00
|
|
|
}
|
2018-11-26 20:58:59 +02:00
|
|
|
|
|
|
|
PathElem::ClosureVar(name.unwrap_or_else(|| {
|
|
|
|
// Fall back to showing the field index.
|
2019-05-22 19:25:39 +10:00
|
|
|
sym::integer(field)
|
2018-11-26 20:58:59 +02:00
|
|
|
}))
|
2018-10-31 18:44:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// tuples
|
|
|
|
ty::Tuple(_) => PathElem::TupleElem(field),
|
|
|
|
|
|
|
|
// enums
|
|
|
|
ty::Adt(def, ..) if def.is_enum() => {
|
2018-11-01 13:53:21 +01:00
|
|
|
// we might be projecting *to* a variant, or to a field *in*a variant.
|
|
|
|
match layout.variants {
|
|
|
|
layout::Variants::Single { index } =>
|
|
|
|
// Inside a variant
|
|
|
|
PathElem::Field(def.variants[index].fields[field].ident.name),
|
2018-11-08 17:06:27 +01:00
|
|
|
_ => bug!(),
|
2018-11-01 13:53:21 +01:00
|
|
|
}
|
2018-10-31 18:44:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// other ADTs
|
|
|
|
ty::Adt(def, _) => PathElem::Field(def.non_enum_variant().fields[field].ident.name),
|
|
|
|
|
|
|
|
// arrays/slices
|
|
|
|
ty::Array(..) | ty::Slice(..) => PathElem::ArrayElem(field),
|
|
|
|
|
|
|
|
// dyn traits
|
|
|
|
ty::Dynamic(..) => PathElem::DynDowncast,
|
|
|
|
|
|
|
|
// nothing else has an aggregate layout
|
|
|
|
_ => bug!("aggregate_field_path_elem: got non-aggregate type {:?}", layout.ty),
|
2018-11-08 17:06:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_elem(
|
|
|
|
&mut self,
|
|
|
|
new_op: OpTy<'tcx, M::PointerTag>,
|
|
|
|
elem: PathElem,
|
2019-06-07 18:56:27 +02:00
|
|
|
) -> InterpResult<'tcx> {
|
2018-11-08 17:06:27 +01:00
|
|
|
// Remember the old state
|
|
|
|
let path_len = self.path.len();
|
|
|
|
// Perform operation
|
2018-10-31 18:44:00 +01:00
|
|
|
self.path.push(elem);
|
2018-11-08 17:06:27 +01:00
|
|
|
self.visit_value(new_op)?;
|
|
|
|
// Undo changes
|
|
|
|
self.path.truncate(path_len);
|
|
|
|
Ok(())
|
2018-10-31 16:46:33 +01:00
|
|
|
}
|
2019-08-25 13:57:46 +02:00
|
|
|
|
|
|
|
fn check_wide_ptr_meta(
|
|
|
|
&mut self,
|
|
|
|
meta: Option<Scalar<M::PointerTag>>,
|
|
|
|
pointee: TyLayout<'tcx>,
|
|
|
|
) -> InterpResult<'tcx> {
|
|
|
|
let tail = self.ecx.tcx.struct_tail_erasing_lifetimes(pointee.ty, self.ecx.param_env);
|
|
|
|
match tail.sty {
|
|
|
|
ty::Dynamic(..) => {
|
|
|
|
let vtable = meta.unwrap();
|
|
|
|
try_validation!(
|
|
|
|
self.ecx.memory.check_ptr_access(
|
|
|
|
vtable,
|
|
|
|
3*self.ecx.tcx.data_layout.pointer_size, // drop, size, align
|
|
|
|
self.ecx.tcx.data_layout.pointer_align.abi,
|
|
|
|
),
|
|
|
|
"dangling or unaligned vtable pointer in wide pointer or too small vtable",
|
|
|
|
self.path
|
|
|
|
);
|
|
|
|
try_validation!(self.ecx.read_drop_type_from_vtable(vtable),
|
|
|
|
"invalid drop fn in vtable", self.path);
|
|
|
|
try_validation!(self.ecx.read_size_and_align_from_vtable(vtable),
|
|
|
|
"invalid size or align in vtable", self.path);
|
|
|
|
// FIXME: More checks for the vtable.
|
|
|
|
}
|
|
|
|
ty::Slice(..) | ty::Str => {
|
2019-08-25 14:47:01 +02:00
|
|
|
let len = try_validation!(meta.unwrap().to_usize(self.ecx),
|
2019-08-25 13:57:46 +02:00
|
|
|
"non-integer slice length in wide pointer", self.path);
|
2019-08-25 14:47:01 +02:00
|
|
|
// check max slice length
|
|
|
|
let elem_size = match tail.sty {
|
|
|
|
ty::Str => Size::from_bytes(1),
|
|
|
|
ty::Slice(ty) => self.ecx.layout_of(ty)?.size,
|
|
|
|
_ => bug!("It cannot be another type"),
|
|
|
|
};
|
|
|
|
if elem_size.checked_mul(len, &*self.ecx.tcx).is_none() {
|
|
|
|
throw_validation_failure!(
|
|
|
|
"too large slice (longer than isize::MAX bytes)",
|
|
|
|
self.path
|
|
|
|
);
|
|
|
|
}
|
2019-08-25 13:57:46 +02:00
|
|
|
}
|
|
|
|
ty::Foreign(..) => {
|
|
|
|
// Unsized, but not wide.
|
|
|
|
}
|
|
|
|
_ =>
|
|
|
|
bug!("Unexpected unsized type tail: {:?}", tail),
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2018-10-31 16:46:33 +01:00
|
|
|
}
|
|
|
|
|
2019-06-12 00:11:55 +03:00
|
|
|
impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
|
|
|
|
for ValidityVisitor<'rt, 'mir, 'tcx, M>
|
2018-10-31 16:46:33 +01:00
|
|
|
{
|
2018-10-31 18:44:00 +01:00
|
|
|
type V = OpTy<'tcx, M::PointerTag>;
|
|
|
|
|
2018-10-31 16:46:33 +01:00
|
|
|
#[inline(always)]
|
2019-06-27 11:36:01 +02:00
|
|
|
fn ecx(&self) -> &InterpCx<'mir, 'tcx, M> {
|
2018-11-02 14:06:43 +01:00
|
|
|
&self.ecx
|
2018-10-31 18:44:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2018-11-01 13:11:23 +01:00
|
|
|
fn visit_field(
|
2018-10-31 18:44:00 +01:00
|
|
|
&mut self,
|
2018-11-02 09:33:26 +01:00
|
|
|
old_op: OpTy<'tcx, M::PointerTag>,
|
2018-10-31 18:44:00 +01:00
|
|
|
field: usize,
|
2018-11-02 09:33:26 +01:00
|
|
|
new_op: OpTy<'tcx, M::PointerTag>
|
2019-06-07 18:56:27 +02:00
|
|
|
) -> InterpResult<'tcx> {
|
2018-11-08 17:06:27 +01:00
|
|
|
let elem = self.aggregate_field_path_elem(old_op.layout, field);
|
|
|
|
self.visit_elem(new_op, elem)
|
2018-10-31 16:46:33 +01:00
|
|
|
}
|
|
|
|
|
2018-11-07 16:45:07 +01:00
|
|
|
#[inline]
|
|
|
|
fn visit_variant(
|
|
|
|
&mut self,
|
|
|
|
old_op: OpTy<'tcx, M::PointerTag>,
|
|
|
|
variant_id: VariantIdx,
|
|
|
|
new_op: OpTy<'tcx, M::PointerTag>
|
2019-06-07 18:56:27 +02:00
|
|
|
) -> InterpResult<'tcx> {
|
2019-05-04 13:49:04 +02:00
|
|
|
let name = match old_op.layout.ty.sty {
|
|
|
|
ty::Adt(adt, _) => PathElem::Variant(adt.variants[variant_id].ident.name),
|
|
|
|
// Generators also have variants
|
2019-05-05 22:53:56 +02:00
|
|
|
ty::Generator(..) => PathElem::GeneratorState(variant_id),
|
2019-05-04 13:49:04 +02:00
|
|
|
_ => bug!("Unexpected type with variant: {:?}", old_op.layout.ty),
|
2019-05-04 13:14:56 +02:00
|
|
|
};
|
|
|
|
self.visit_elem(new_op, name)
|
2018-11-07 16:45:07 +01:00
|
|
|
}
|
|
|
|
|
2018-11-01 13:53:21 +01:00
|
|
|
#[inline]
|
2019-06-07 18:56:27 +02:00
|
|
|
fn visit_value(&mut self, op: OpTy<'tcx, M::PointerTag>) -> InterpResult<'tcx>
|
2018-10-31 16:46:33 +01:00
|
|
|
{
|
2018-11-02 09:33:26 +01:00
|
|
|
trace!("visit_value: {:?}, {:?}", *op, op.layout);
|
2018-11-02 10:01:22 +01:00
|
|
|
// Translate some possible errors to something nicer.
|
2018-11-02 09:33:26 +01:00
|
|
|
match self.walk_value(op) {
|
2018-11-01 13:53:21 +01:00
|
|
|
Ok(()) => Ok(()),
|
|
|
|
Err(err) => match err.kind {
|
2019-07-31 12:48:54 +05:30
|
|
|
err_unsup!(InvalidDiscriminant(val)) =>
|
|
|
|
throw_validation_failure!(
|
2018-11-01 14:14:51 +01:00
|
|
|
val, self.path, "a valid enum discriminant"
|
2018-10-31 16:46:33 +01:00
|
|
|
),
|
2019-07-31 12:48:54 +05:30
|
|
|
err_unsup!(ReadPointerAsBytes) =>
|
|
|
|
throw_validation_failure!(
|
2018-11-12 10:32:23 +01:00
|
|
|
"a pointer", self.path, "plain (non-pointer) bytes"
|
2018-11-02 10:01:22 +01:00
|
|
|
),
|
2018-11-01 13:53:21 +01:00
|
|
|
_ => Err(err),
|
2018-10-31 16:46:33 +01:00
|
|
|
}
|
2018-11-01 13:53:21 +01:00
|
|
|
}
|
2018-10-31 16:46:33 +01:00
|
|
|
}
|
|
|
|
|
2019-06-07 18:56:27 +02:00
|
|
|
fn visit_primitive(&mut self, value: OpTy<'tcx, M::PointerTag>) -> InterpResult<'tcx>
|
2018-10-31 16:46:33 +01:00
|
|
|
{
|
2018-11-13 12:44:40 +01:00
|
|
|
let value = self.ecx.read_immediate(value)?;
|
2018-10-02 18:07:40 +02:00
|
|
|
// Go over all the primitive types
|
2018-10-08 13:41:16 +02:00
|
|
|
let ty = value.layout.ty;
|
|
|
|
match ty.sty {
|
2018-10-02 18:07:40 +02:00
|
|
|
ty::Bool => {
|
2018-10-03 11:38:16 +02:00
|
|
|
let value = value.to_scalar_or_undef();
|
2018-10-02 18:07:40 +02:00
|
|
|
try_validation!(value.to_bool(),
|
2018-11-01 14:14:51 +01:00
|
|
|
value, self.path, "a boolean");
|
2018-10-02 18:07:40 +02:00
|
|
|
},
|
2018-08-22 11:54:46 +01:00
|
|
|
ty::Char => {
|
2018-10-03 11:38:16 +02:00
|
|
|
let value = value.to_scalar_or_undef();
|
2018-10-02 18:07:40 +02:00
|
|
|
try_validation!(value.to_char(),
|
2018-11-01 14:14:51 +01:00
|
|
|
value, self.path, "a valid unicode codepoint");
|
2018-10-02 18:07:40 +02:00
|
|
|
},
|
2018-10-03 11:38:16 +02:00
|
|
|
ty::Float(_) | ty::Int(_) | ty::Uint(_) => {
|
2018-10-16 08:37:27 +02:00
|
|
|
// NOTE: Keep this in sync with the array optimization for int/float
|
|
|
|
// types below!
|
2018-10-03 11:38:16 +02:00
|
|
|
let size = value.layout.size;
|
|
|
|
let value = value.to_scalar_or_undef();
|
2019-02-10 14:59:13 +01:00
|
|
|
if self.ref_tracking_for_consts.is_some() {
|
2018-10-03 11:38:16 +02:00
|
|
|
// Integers/floats in CTFE: Must be scalar bits, pointers are dangerous
|
|
|
|
try_validation!(value.to_bits(size),
|
2018-11-12 10:32:23 +01:00
|
|
|
value, self.path, "initialized plain (non-pointer) bytes");
|
2018-10-03 08:59:27 +02:00
|
|
|
} else {
|
2018-10-03 11:38:16 +02:00
|
|
|
// At run-time, for now, we accept *anything* for these types, including
|
|
|
|
// undef. We should fix that, but let's start low.
|
|
|
|
}
|
|
|
|
}
|
2018-10-19 17:11:23 +02:00
|
|
|
ty::RawPtr(..) => {
|
2019-08-25 14:26:56 +02:00
|
|
|
// Check pointer part.
|
2019-02-10 14:59:13 +01:00
|
|
|
if self.ref_tracking_for_consts.is_some() {
|
2018-11-17 14:05:00 +01:00
|
|
|
// Integers/floats in CTFE: For consistency with integers, we do not
|
|
|
|
// accept undef.
|
|
|
|
let _ptr = try_validation!(value.to_scalar_ptr(),
|
|
|
|
"undefined address in raw pointer", self.path);
|
|
|
|
} else {
|
|
|
|
// Remain consistent with `usize`: Accept anything.
|
|
|
|
}
|
2019-08-25 14:26:56 +02:00
|
|
|
|
|
|
|
// Check metadata.
|
|
|
|
let meta = try_validation!(value.to_meta(),
|
|
|
|
"uninitialized data in wide pointer metadata", self.path);
|
|
|
|
let layout = self.ecx.layout_of(value.layout.ty.builtin_deref(true).unwrap().ty)?;
|
|
|
|
if layout.is_unsized() {
|
|
|
|
self.check_wide_ptr_meta(meta, layout)?;
|
|
|
|
}
|
2018-10-19 17:11:23 +02:00
|
|
|
}
|
|
|
|
_ if ty.is_box() || ty.is_region_ptr() => {
|
2019-08-25 13:57:46 +02:00
|
|
|
// Handle wide pointers.
|
2018-10-03 11:38:16 +02:00
|
|
|
// Check metadata early, for better diagnostics
|
2018-10-19 17:11:23 +02:00
|
|
|
let ptr = try_validation!(value.to_scalar_ptr(),
|
2018-10-31 16:46:33 +01:00
|
|
|
"undefined address in pointer", self.path);
|
2018-10-19 17:11:23 +02:00
|
|
|
let meta = try_validation!(value.to_meta(),
|
2019-08-25 13:57:46 +02:00
|
|
|
"uninitialized data in wide pointer metadata", self.path);
|
2018-11-02 09:33:26 +01:00
|
|
|
let layout = self.ecx.layout_of(value.layout.ty.builtin_deref(true).unwrap().ty)?;
|
2018-10-19 17:11:23 +02:00
|
|
|
if layout.is_unsized() {
|
2019-08-25 13:57:46 +02:00
|
|
|
self.check_wide_ptr_meta(meta, layout)?;
|
2018-10-03 11:38:16 +02:00
|
|
|
}
|
2019-06-23 14:26:36 +02:00
|
|
|
// Make sure this is dereferencable and all.
|
2018-11-02 09:33:26 +01:00
|
|
|
let (size, align) = self.ecx.size_and_align_of(meta, layout)?
|
2018-10-19 17:11:23 +02:00
|
|
|
// for the purpose of validity, consider foreign types to have
|
|
|
|
// alignment and size determined by the layout (size will be 0,
|
|
|
|
// alignment should take attributes into account).
|
2018-09-09 01:16:45 +03:00
|
|
|
.unwrap_or_else(|| (layout.size, layout.align.abi));
|
2019-07-29 15:27:01 +02:00
|
|
|
let ptr: Option<_> = match
|
|
|
|
self.ecx.memory.check_ptr_access_align(ptr, size, Some(align))
|
|
|
|
{
|
2019-06-23 14:26:36 +02:00
|
|
|
Ok(ptr) => ptr,
|
2018-10-19 17:11:23 +02:00
|
|
|
Err(err) => {
|
2019-06-23 18:00:07 +02:00
|
|
|
info!(
|
|
|
|
"{:?} did not pass access check for size {:?}, align {:?}",
|
|
|
|
ptr, size, align
|
|
|
|
);
|
2018-10-19 17:11:23 +02:00
|
|
|
match err.kind {
|
2019-07-31 12:48:54 +05:30
|
|
|
err_unsup!(InvalidNullPointerUsage) =>
|
|
|
|
throw_validation_failure!("NULL reference", self.path),
|
|
|
|
err_unsup!(AlignmentCheckFailed { required, has }) =>
|
|
|
|
throw_validation_failure!(format!("unaligned reference \
|
2019-02-22 16:36:39 -05:00
|
|
|
(required {} byte alignment but found {})",
|
2019-02-22 15:49:07 -05:00
|
|
|
required.bytes(), has.bytes()), self.path),
|
2019-07-31 12:48:54 +05:30
|
|
|
err_unsup!(ReadBytesAsPointer) =>
|
|
|
|
throw_validation_failure!(
|
2019-07-14 11:39:10 +02:00
|
|
|
"dangling reference (created from integer)",
|
2019-06-23 18:00:07 +02:00
|
|
|
self.path
|
|
|
|
),
|
2018-10-03 11:38:16 +02:00
|
|
|
_ =>
|
2019-07-31 12:48:54 +05:30
|
|
|
throw_validation_failure!(
|
2019-07-14 11:39:10 +02:00
|
|
|
"dangling reference (not entirely in bounds)",
|
2018-10-31 16:46:33 +01:00
|
|
|
self.path
|
2018-10-03 11:38:16 +02:00
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
2019-06-23 14:26:36 +02:00
|
|
|
};
|
2018-10-19 17:11:23 +02:00
|
|
|
// Recursive checking
|
2019-02-10 14:59:13 +01:00
|
|
|
if let Some(ref mut ref_tracking) = self.ref_tracking_for_consts {
|
2018-11-07 10:07:50 +01:00
|
|
|
let place = self.ecx.ref_to_mplace(value)?;
|
2019-06-23 14:26:36 +02:00
|
|
|
if let Some(ptr) = ptr { // not a ZST
|
2018-10-19 17:11:23 +02:00
|
|
|
// Skip validation entirely for some external statics
|
2018-11-02 09:33:26 +01:00
|
|
|
let alloc_kind = self.ecx.tcx.alloc_map.lock().get(ptr.alloc_id);
|
2019-05-30 13:05:05 +02:00
|
|
|
if let Some(GlobalAlloc::Static(did)) = alloc_kind {
|
2018-10-19 17:11:23 +02:00
|
|
|
// `extern static` cannot be validated as they have no body.
|
|
|
|
// FIXME: Statics from other crates are also skipped.
|
|
|
|
// They might be checked at a different type, but for now we
|
|
|
|
// want to avoid recursing too deeply. This is not sound!
|
2018-11-02 09:33:26 +01:00
|
|
|
if !did.is_local() || self.ecx.tcx.is_foreign_item(did) {
|
2018-10-19 17:11:23 +02:00
|
|
|
return Ok(());
|
2018-10-03 12:34:10 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-03 11:38:16 +02:00
|
|
|
}
|
2019-07-06 12:46:08 +02:00
|
|
|
// Proceed recursively even for ZST, no reason to skip them!
|
|
|
|
// `!` is a ZST and we want to validate it.
|
|
|
|
// Normalize before handing `place` to tracking because that will
|
|
|
|
// check for duplicates.
|
2019-07-06 14:19:04 +02:00
|
|
|
let place = if size.bytes() > 0 {
|
|
|
|
self.ecx.force_mplace_ptr(place)
|
|
|
|
.expect("we already bounds-checked")
|
|
|
|
} else {
|
|
|
|
place
|
|
|
|
};
|
2019-02-10 14:59:13 +01:00
|
|
|
let path = &self.path;
|
|
|
|
ref_tracking.track(place, || {
|
2018-10-31 18:44:00 +01:00
|
|
|
// We need to clone the path anyway, make sure it gets created
|
|
|
|
// with enough space for the additional `Deref`.
|
2019-02-10 14:59:13 +01:00
|
|
|
let mut new_path = Vec::with_capacity(path.len() + 1);
|
|
|
|
new_path.clone_from(path);
|
2018-10-31 18:44:00 +01:00
|
|
|
new_path.push(PathElem::Deref);
|
2019-02-10 14:59:13 +01:00
|
|
|
new_path
|
|
|
|
});
|
2018-10-03 08:59:27 +02:00
|
|
|
}
|
2018-08-17 12:18:02 +02:00
|
|
|
}
|
2018-10-02 18:07:40 +02:00
|
|
|
ty::FnPtr(_sig) => {
|
2018-10-03 11:38:16 +02:00
|
|
|
let value = value.to_scalar_or_undef();
|
2019-07-01 11:16:18 +02:00
|
|
|
let _fn = try_validation!(
|
|
|
|
value.not_undef().and_then(|ptr| self.ecx.memory.get_fn(ptr)),
|
|
|
|
value, self.path, "a function pointer"
|
|
|
|
);
|
2018-10-03 08:45:16 +02:00
|
|
|
// FIXME: Check if the signature matches
|
2018-10-02 18:07:40 +02:00
|
|
|
}
|
2018-10-03 11:38:16 +02:00
|
|
|
// This should be all the primitive types
|
|
|
|
_ => bug!("Unexpected primitive type {}", value.layout.ty)
|
2018-08-17 12:18:02 +02:00
|
|
|
}
|
2018-10-02 18:07:40 +02:00
|
|
|
Ok(())
|
2018-08-17 12:18:02 +02:00
|
|
|
}
|
|
|
|
|
2019-06-07 18:56:27 +02:00
|
|
|
fn visit_uninhabited(&mut self) -> InterpResult<'tcx>
|
2018-10-31 18:44:00 +01:00
|
|
|
{
|
2019-07-31 12:48:54 +05:30
|
|
|
throw_validation_failure!("a value of an uninhabited type", self.path)
|
2018-10-31 18:44:00 +01:00
|
|
|
}
|
|
|
|
|
2018-11-02 09:33:26 +01:00
|
|
|
fn visit_scalar(
|
|
|
|
&mut self,
|
|
|
|
op: OpTy<'tcx, M::PointerTag>,
|
|
|
|
layout: &layout::Scalar,
|
2019-06-07 18:56:27 +02:00
|
|
|
) -> InterpResult<'tcx> {
|
2018-11-02 10:01:22 +01:00
|
|
|
let value = self.ecx.read_scalar(op)?;
|
2018-10-31 16:46:33 +01:00
|
|
|
// Determine the allowed range
|
2018-10-02 20:05:12 +02:00
|
|
|
let (lo, hi) = layout.valid_range.clone().into_inner();
|
2018-10-31 16:46:33 +01:00
|
|
|
// `max_hi` is as big as the size fits
|
2018-11-02 09:33:26 +01:00
|
|
|
let max_hi = u128::max_value() >> (128 - op.layout.size.bits());
|
2018-10-03 11:38:16 +02:00
|
|
|
assert!(hi <= max_hi);
|
2018-10-29 21:31:22 +01:00
|
|
|
// We could also write `(hi + 1) % (max_hi + 1) == lo` but `max_hi + 1` overflows for `u128`
|
2018-10-29 15:22:47 +01:00
|
|
|
if (lo == 0 && hi == max_hi) || (hi + 1 == lo) {
|
2018-10-02 20:05:12 +02:00
|
|
|
// Nothing to check
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
// At least one value is excluded. Get the bits.
|
|
|
|
let value = try_validation!(value.not_undef(),
|
2019-01-21 14:48:07 +00:00
|
|
|
value,
|
|
|
|
self.path,
|
|
|
|
format!(
|
|
|
|
"something {}",
|
|
|
|
wrapping_range_format(&layout.valid_range, max_hi),
|
|
|
|
)
|
|
|
|
);
|
2019-05-26 14:13:12 +02:00
|
|
|
let bits = match value.to_bits_or_ptr(op.layout.size, self.ecx) {
|
|
|
|
Err(ptr) => {
|
2018-10-03 11:38:16 +02:00
|
|
|
if lo == 1 && hi == max_hi {
|
2019-06-23 14:26:36 +02:00
|
|
|
// Only NULL is the niche. So make sure the ptr is NOT NULL.
|
|
|
|
if self.ecx.memory.ptr_may_be_null(ptr) {
|
2019-07-31 12:48:54 +05:30
|
|
|
throw_validation_failure!(
|
2019-07-01 19:11:32 +02:00
|
|
|
"a potentially NULL pointer",
|
|
|
|
self.path,
|
|
|
|
format!(
|
|
|
|
"something that cannot possibly fail to be {}",
|
|
|
|
wrapping_range_format(&layout.valid_range, max_hi)
|
|
|
|
)
|
2019-07-30 20:18:50 +05:30
|
|
|
)
|
2018-10-03 11:38:16 +02:00
|
|
|
}
|
|
|
|
return Ok(());
|
|
|
|
} else {
|
2019-07-01 11:26:28 +02:00
|
|
|
// Conservatively, we reject, because the pointer *could* have a bad
|
2018-10-03 11:38:16 +02:00
|
|
|
// value.
|
2019-07-31 12:48:54 +05:30
|
|
|
throw_validation_failure!(
|
2018-10-03 11:38:16 +02:00
|
|
|
"a pointer",
|
2018-10-31 16:46:33 +01:00
|
|
|
self.path,
|
2018-10-03 11:38:16 +02:00
|
|
|
format!(
|
2018-11-03 12:44:10 +01:00
|
|
|
"something that cannot possibly fail to be {}",
|
|
|
|
wrapping_range_format(&layout.valid_range, max_hi)
|
2018-10-03 11:38:16 +02:00
|
|
|
)
|
2019-07-30 20:18:50 +05:30
|
|
|
)
|
2018-10-03 11:38:16 +02:00
|
|
|
}
|
2018-10-02 20:05:12 +02:00
|
|
|
}
|
2019-05-26 14:13:12 +02:00
|
|
|
Ok(data) =>
|
2019-05-25 10:59:09 +02:00
|
|
|
data
|
2018-10-02 20:05:12 +02:00
|
|
|
};
|
|
|
|
// Now compare. This is slightly subtle because this is a special "wrap-around" range.
|
2018-11-03 12:44:10 +01:00
|
|
|
if wrapping_range_contains(&layout.valid_range, bits) {
|
|
|
|
Ok(())
|
2018-10-02 20:05:12 +02:00
|
|
|
} else {
|
2019-07-31 12:48:54 +05:30
|
|
|
throw_validation_failure!(
|
2018-11-03 12:44:10 +01:00
|
|
|
bits,
|
|
|
|
self.path,
|
|
|
|
format!("something {}", wrapping_range_format(&layout.valid_range, max_hi))
|
|
|
|
)
|
2018-10-02 16:06:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-02 10:52:07 +01:00
|
|
|
fn visit_aggregate(
|
|
|
|
&mut self,
|
|
|
|
op: OpTy<'tcx, M::PointerTag>,
|
2019-06-07 18:56:27 +02:00
|
|
|
fields: impl Iterator<Item=InterpResult<'tcx, Self::V>>,
|
|
|
|
) -> InterpResult<'tcx> {
|
2018-11-02 09:33:26 +01:00
|
|
|
match op.layout.ty.sty {
|
2018-10-31 18:44:00 +01:00
|
|
|
ty::Str => {
|
2019-07-06 12:46:08 +02:00
|
|
|
let mplace = op.assert_mem_place(); // strings are never immediate
|
2018-11-02 09:33:26 +01:00
|
|
|
try_validation!(self.ecx.read_str(mplace),
|
2018-10-31 18:44:00 +01:00
|
|
|
"uninitialized or non-UTF-8 data in str", self.path);
|
|
|
|
}
|
2018-10-31 16:46:33 +01:00
|
|
|
ty::Array(tys, ..) | ty::Slice(tys) if {
|
|
|
|
// This optimization applies only for integer and floating point types
|
|
|
|
// (i.e., types that can hold arbitrary bytes).
|
|
|
|
match tys.sty {
|
|
|
|
ty::Int(..) | ty::Uint(..) | ty::Float(..) => true,
|
|
|
|
_ => false,
|
2018-10-03 11:38:16 +02:00
|
|
|
}
|
2018-10-31 16:46:33 +01:00
|
|
|
} => {
|
2018-11-14 13:28:38 +01:00
|
|
|
// bailing out for zsts is ok, since the array element type can only be int/float
|
2018-11-14 11:45:10 +01:00
|
|
|
if op.layout.is_zst() {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
// non-ZST array cannot be immediate, slices are never immediate
|
2019-07-06 12:46:08 +02:00
|
|
|
let mplace = op.assert_mem_place();
|
2018-10-31 16:46:33 +01:00
|
|
|
// This is the length of the array/slice.
|
2018-11-02 09:33:26 +01:00
|
|
|
let len = mplace.len(self.ecx)?;
|
2018-11-14 11:45:10 +01:00
|
|
|
// zero length slices have nothing to be checked
|
|
|
|
if len == 0 {
|
|
|
|
return Ok(());
|
|
|
|
}
|
2018-10-31 16:46:33 +01:00
|
|
|
// This is the element type size.
|
2018-11-02 09:33:26 +01:00
|
|
|
let ty_size = self.ecx.layout_of(tys)?.size;
|
2018-10-31 16:46:33 +01:00
|
|
|
// This is the size in bytes of the whole array.
|
|
|
|
let size = ty_size * len;
|
2019-07-06 14:19:04 +02:00
|
|
|
// Size is not 0, get a pointer.
|
|
|
|
let ptr = self.ecx.force_ptr(mplace.ptr)?;
|
2018-11-12 13:26:53 +01:00
|
|
|
|
2018-10-31 16:46:33 +01:00
|
|
|
// NOTE: Keep this in sync with the handling of integer and float
|
|
|
|
// types above, in `visit_primitive`.
|
|
|
|
// In run-time mode, we accept pointers in here. This is actually more
|
2018-11-27 02:59:49 +00:00
|
|
|
// permissive than a per-element check would be, e.g., we accept
|
2018-10-31 16:46:33 +01:00
|
|
|
// an &[u8] that contains a pointer even though bytewise checking would
|
|
|
|
// reject it. However, that's good: We don't inherently want
|
|
|
|
// to reject those pointers, we just do not have the machinery to
|
|
|
|
// talk about parts of a pointer.
|
|
|
|
// We also accept undef, for consistency with the type-based checks.
|
2018-11-12 13:26:53 +01:00
|
|
|
match self.ecx.memory.get(ptr.alloc_id)?.check_bytes(
|
|
|
|
self.ecx,
|
|
|
|
ptr,
|
2018-10-31 16:46:33 +01:00
|
|
|
size,
|
2019-02-10 14:59:13 +01:00
|
|
|
/*allow_ptr_and_undef*/ self.ref_tracking_for_consts.is_none(),
|
2018-10-31 16:46:33 +01:00
|
|
|
) {
|
|
|
|
// In the happy case, we needn't check anything else.
|
2018-11-02 08:17:40 +01:00
|
|
|
Ok(()) => {},
|
2018-10-31 16:46:33 +01:00
|
|
|
// Some error happened, try to provide a more detailed description.
|
|
|
|
Err(err) => {
|
|
|
|
// For some errors we might be able to provide extra information
|
|
|
|
match err.kind {
|
2019-07-31 12:48:54 +05:30
|
|
|
err_unsup!(ReadUndefBytes(offset)) => {
|
2018-10-31 16:46:33 +01:00
|
|
|
// Some byte was undefined, determine which
|
|
|
|
// element that byte belongs to so we can
|
|
|
|
// provide an index.
|
|
|
|
let i = (offset.bytes() / ty_size.bytes()) as usize;
|
|
|
|
self.path.push(PathElem::ArrayElem(i));
|
|
|
|
|
2019-07-31 12:48:54 +05:30
|
|
|
throw_validation_failure!("undefined bytes", self.path)
|
2018-10-31 16:46:33 +01:00
|
|
|
},
|
|
|
|
// Other errors shouldn't be possible
|
|
|
|
_ => return Err(err),
|
2018-08-25 14:36:24 +02:00
|
|
|
}
|
2018-08-24 15:27:05 +02:00
|
|
|
}
|
2018-08-17 12:18:02 +02:00
|
|
|
}
|
2018-10-31 16:46:33 +01:00
|
|
|
}
|
2018-11-02 08:17:40 +01:00
|
|
|
_ => {
|
2018-11-02 10:52:07 +01:00
|
|
|
self.walk_aggregate(op, fields)? // default handler
|
2018-11-02 08:17:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
2018-08-17 12:18:02 +02:00
|
|
|
}
|
2018-10-31 16:46:33 +01:00
|
|
|
}
|
2018-08-17 12:18:02 +02:00
|
|
|
|
2019-06-27 11:36:01 +02:00
|
|
|
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
2019-02-08 14:53:55 +01:00
|
|
|
/// This function checks the data at `op`. `op` is assumed to cover valid memory if it
|
2018-10-31 16:46:33 +01:00
|
|
|
/// is an indirect operand.
|
|
|
|
/// It will error if the bits at the destination do not match the ones described by the layout.
|
|
|
|
///
|
2019-02-10 14:59:13 +01:00
|
|
|
/// `ref_tracking_for_consts` can be `None` to avoid recursive checking below references.
|
2018-10-31 16:46:33 +01:00
|
|
|
/// This also toggles between "run-time" (no recursion) and "compile-time" (with recursion)
|
2019-02-10 14:59:13 +01:00
|
|
|
/// validation (e.g., pointer values are fine in integers at runtime) and various other const
|
2019-07-06 12:46:08 +02:00
|
|
|
/// specific validation checks.
|
2018-10-31 16:46:33 +01:00
|
|
|
pub fn validate_operand(
|
2018-11-02 14:06:43 +01:00
|
|
|
&self,
|
2018-10-31 16:46:33 +01:00
|
|
|
op: OpTy<'tcx, M::PointerTag>,
|
|
|
|
path: Vec<PathElem>,
|
2019-02-10 14:59:13 +01:00
|
|
|
ref_tracking_for_consts: Option<&mut RefTracking<
|
|
|
|
MPlaceTy<'tcx, M::PointerTag>,
|
|
|
|
Vec<PathElem>,
|
|
|
|
>>,
|
2019-06-07 18:56:27 +02:00
|
|
|
) -> InterpResult<'tcx> {
|
2018-10-31 16:46:33 +01:00
|
|
|
trace!("validate_operand: {:?}, {:?}", *op, op.layout.ty);
|
2018-08-17 12:18:02 +02:00
|
|
|
|
2018-10-31 16:46:33 +01:00
|
|
|
// Construct a visitor
|
|
|
|
let mut visitor = ValidityVisitor {
|
|
|
|
path,
|
2019-02-10 14:59:13 +01:00
|
|
|
ref_tracking_for_consts,
|
2018-11-02 09:33:26 +01:00
|
|
|
ecx: self,
|
2018-10-31 16:46:33 +01:00
|
|
|
};
|
2018-08-17 12:18:02 +02:00
|
|
|
|
2019-07-06 14:19:04 +02:00
|
|
|
// Try to cast to ptr *once* instead of all the time.
|
|
|
|
let op = self.force_op_ptr(op).unwrap_or(op);
|
|
|
|
|
2018-10-31 16:46:33 +01:00
|
|
|
// Run it
|
2018-11-02 09:33:26 +01:00
|
|
|
visitor.visit_value(op)
|
2018-08-17 12:18:02 +02:00
|
|
|
}
|
|
|
|
}
|