From 769a2b5c813fc476e69ac21b13b42a2fa96f3dfe Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 13 Jul 2017 23:34:08 -0700 Subject: [PATCH] Handle trait objects. Only very superficial checking of the vtable for now. (88) --- src/librustc_mir/interpret/validation.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/interpret/validation.rs b/src/librustc_mir/interpret/validation.rs index 0e8e456e363..7506ecdedbd 100644 --- a/src/librustc_mir/interpret/validation.rs +++ b/src/librustc_mir/interpret/validation.rs @@ -71,7 +71,7 @@ pub(super) fn validate(&mut self, lvalue: Lvalue<'tcx>, ty: Ty<'tcx>, mut vctx: TyBool | TyFloat(_) | TyChar | TyStr | TyRef(..) | TyFnPtr(..) | TyNever => true, TyAdt(adt, _) if adt.is_box() => true, - TySlice(_) | TyAdt(_, _) | TyTuple(..) | TyClosure(..) | TyArray(..) => false, + TySlice(_) | TyAdt(_, _) | TyTuple(..) | TyClosure(..) | TyArray(..) | TyDynamic(..) => false, TyParam(_) | TyInfer(_) => bug!("I got an incomplete type for validation"), _ => return Err(EvalError::Unimplemented(format!("Unimplemented type encountered when checking validity."))), }; @@ -178,6 +178,20 @@ pub(super) fn validate(&mut self, lvalue: Lvalue<'tcx>, ty: Ty<'tcx>, mut vctx: } Ok(()) } + TyDynamic(_data, _region) => { + // Check that this is a valid vtable + let vtable = match lvalue { + Lvalue::Ptr { extra: LvalueExtra::Vtable(vtable), .. } => vtable, + _ => bug!("acquire_valid of a TyDynamic given non-trait-object lvalue: {:?}", lvalue), + }; + self.read_size_and_align_from_vtable(vtable)?; + // TODO: Check that the vtable contains all the function pointers we expect it to have. + // TODO: Is there anything we can/should validate here? Trait objects cannot have any operations performed + // on them directly. We cannot, in general, even acquire any locks as the trait object *could* + // contain an UnsafeCell. If we call functions to get access to data, we will validate + // their return values. So, it doesn't seem like there's anything to do. + Ok(()) + } TyAdt(adt, subst) => { if Some(adt.did) == self.tcx.lang_items.unsafe_cell_type() { // No locks for unsafe cells. Also no other validation, the only field is private anyway. -- 2.44.0