From 14b16dcf45d00875e87e609362efb7d7d6cd84c3 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 26 May 2017 10:19:38 -0700 Subject: [PATCH] use proper span for TLS dtors; fix some nits --- src/memory.rs | 1 - src/step.rs | 7 +++---- src/terminator/mod.rs | 12 ++++++------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/memory.rs b/src/memory.rs index 0280ad4c379b..bfdc45c921d1 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -100,7 +100,6 @@ pub fn never_ptr() -> Self { } pub fn is_null_ptr(&self) -> bool { - // FIXME: Is this the right way? return *self == Pointer::from_int(0) } } diff --git a/src/step.rs b/src/step.rs index 658a3445c433..84f849c61225 100644 --- a/src/step.rs +++ b/src/step.rs @@ -14,7 +14,7 @@ use lvalue::{Global, GlobalId, Lvalue}; use value::{Value, PrimVal}; use memory::Pointer; -use syntax::codemap::{Span, DUMMY_SP}; +use syntax::codemap::Span; impl<'a, 'tcx> EvalContext<'a, 'tcx> { pub fn inc_step_counter_and_check_limit(&mut self, n: u64) -> EvalResult<'tcx> { @@ -36,10 +36,9 @@ pub fn step(&mut self) -> EvalResult<'tcx, bool> { trace!("Running TLS dtor {:?} on {:?}", instance, ptr); // TODO: Potientiually, this has to support all the other possible instances? See eval_fn_call in terminator/mod.rs let mir = self.load_mir(instance.def)?; - // FIXME: Are these the right dummy values? self.push_stack_frame( instance, - DUMMY_SP, + mir.span, mir, Lvalue::from_ptr(Pointer::zst_ptr()), StackPopCleanup::None, @@ -51,7 +50,7 @@ pub fn step(&mut self) -> EvalResult<'tcx, bool> { } else { return Err(EvalError::AbiViolation("TLS dtor does not take enough arguments.".to_owned())); } - + return Ok(true); } return Ok(false); diff --git a/src/terminator/mod.rs b/src/terminator/mod.rs index aaf03ea665f6..9d55b9720bb5 100644 --- a/src/terminator/mod.rs +++ b/src/terminator/mod.rs @@ -1,6 +1,6 @@ use rustc::hir::def_id::DefId; use rustc::mir; -use rustc::ty::{self, TypeVariants, Ty, TyS, TypeAndMut}; +use rustc::ty::{self, TypeVariants, Ty, TypeAndMut}; use rustc::ty::layout::Layout; use syntax::codemap::Span; use syntax::attr; @@ -600,19 +600,19 @@ fn call_c_abi( let key_ptr = args[0].read_ptr(&self.memory)?; // Extract the function type out of the signature (that seems easier than constructing it ourselves...) - // FIXME: Or should we instead construct the type we expect it to have? - let dtor_fn_ty = match self.operand_ty(&arg_operands[1]) { - &TyS { sty: TypeVariants::TyAdt(_, ref substs), .. } => { + let dtor_fn_ty = match self.operand_ty(&arg_operands[1]).sty { + TypeVariants::TyAdt(_, ref substs) => { substs.type_at(0) } _ => return Err(EvalError::AbiViolation("Wrong signature used for pthread_key_create: Second argument must be option of a function pointer.".to_owned())) }; let dtor_ptr = self.value_to_primval(args[1], dtor_fn_ty)?.to_ptr()?; + // TODO: The null-pointer case here is entirely untested let dtor = if dtor_ptr.is_null_ptr() { None } else { Some(self.memory.get_fn(dtor_ptr.alloc_id)?) }; // Figure out how large a pthread TLS key actually is. This is libc::pthread_key_t. - let key_size = match self.operand_ty(&arg_operands[0]) { - &TyS { sty: TypeVariants::TyRawPtr(TypeAndMut { ty, .. }), .. } => { + let key_size = match self.operand_ty(&arg_operands[0]).sty { + TypeVariants::TyRawPtr(TypeAndMut { ty, .. }) => { let layout = self.type_layout(ty)?; layout.size(&self.tcx.data_layout) }