From 7bfda59fe274035bd9cb393da9a285c40f306dea Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 5 Jun 2017 17:14:48 -0700 Subject: [PATCH] don't bother inserting integer relocations into the relocation table --- src/memory.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/memory.rs b/src/memory.rs index 24ac27f8fa3..32763d47d17 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -620,7 +620,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> { if size == 0 { return Ok(&[]); } - if self.has_non_int_relocations(ptr, size)? { + if self.relocations(ptr, size)?.count() != 0 { return Err(EvalError::ReadPointerAsBytes); } self.check_defined(ptr, size)?; @@ -718,7 +718,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> { let offset = ptr.offset as usize; match alloc.bytes[offset..].iter().position(|&c| c == 0) { Some(size) => { - if self.has_non_int_relocations(ptr, (size + 1) as u64)? { + if self.relocations(ptr, (size + 1) as u64)?.count() != 0 { return Err(EvalError::ReadPointerAsBytes); } self.check_defined(ptr, (size + 1) as u64)?; @@ -761,7 +761,9 @@ impl<'a, 'tcx> Memory<'a, 'tcx> { pub fn write_ptr(&mut self, dest: Pointer, ptr: Pointer) -> EvalResult<'tcx> { self.write_usize(dest, ptr.offset as u64)?; - self.get_mut(dest.alloc_id)?.relocations.insert(dest.offset, ptr.alloc_id); + if ptr.alloc_id != NEVER_ALLOC_ID { + self.get_mut(dest.alloc_id)?.relocations.insert(dest.offset, ptr.alloc_id); + } Ok(()) } @@ -902,12 +904,6 @@ impl<'a, 'tcx> Memory<'a, 'tcx> { Ok(self.get(ptr.alloc_id)?.relocations.range(start..end)) } - fn has_non_int_relocations(&self, ptr: Pointer, size: u64) - -> EvalResult<'tcx, bool> - { - Ok(self.relocations(ptr, size)?.any(|(_, &alloc_id)| alloc_id != NEVER_ALLOC_ID)) - } - fn clear_relocations(&mut self, ptr: Pointer, size: u64) -> EvalResult<'tcx> { // Find all relocations overlapping the given range. let keys: Vec<_> = self.relocations(ptr, size)?.map(|(&k, _)| k).collect();