From 68ba6cdbaa758484f56d8c7f5628ccfcb772756e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 23 Nov 2018 09:46:51 +0100 Subject: [PATCH 1/2] fix for new Align type --- src/fn_call.rs | 16 ++++++++-------- src/helpers.rs | 5 +++-- src/intrinsic.rs | 8 ++++---- src/lib.rs | 12 ++++++------ src/operator.rs | 8 ++++---- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/fn_call.rs b/src/fn_call.rs index 5fc706c04d80..e64d4f695487 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -124,7 +124,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo if size == 0 { self.write_null(dest)?; } else { - let align = self.tcx.data_layout.pointer_align; + let align = self.tcx.data_layout.pointer_align.abi; let ptr = self.memory_mut().allocate(Size::from_bytes(size), align, MiriMemoryKind::C.into())?; self.write_scalar(Scalar::Ptr(ptr.with_default_tag()), dest)?; } @@ -153,7 +153,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo let ptr = self.memory_mut() .allocate( Size::from_bytes(size), - Align::from_bytes(align, align).unwrap(), + Align::from_bytes(align).unwrap(), MiriMemoryKind::Rust.into() )? .with_default_tag(); @@ -171,7 +171,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo let ptr = self.memory_mut() .allocate( Size::from_bytes(size), - Align::from_bytes(align, align).unwrap(), + Align::from_bytes(align).unwrap(), MiriMemoryKind::Rust.into() )? .with_default_tag(); @@ -190,7 +190,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo } self.memory_mut().deallocate( ptr, - Some((Size::from_bytes(old_size), Align::from_bytes(align, align).unwrap())), + Some((Size::from_bytes(old_size), Align::from_bytes(align).unwrap())), MiriMemoryKind::Rust.into(), )?; } @@ -208,9 +208,9 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo let new_ptr = self.memory_mut().reallocate( ptr, Size::from_bytes(old_size), - Align::from_bytes(align, align).unwrap(), + Align::from_bytes(align).unwrap(), Size::from_bytes(new_size), - Align::from_bytes(align, align).unwrap(), + Align::from_bytes(align).unwrap(), MiriMemoryKind::Rust.into(), )?; self.write_scalar(Scalar::Ptr(new_ptr.with_default_tag()), dest)?; @@ -394,7 +394,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo // +1 for the null terminator let value_copy = self.memory_mut().allocate( Size::from_bytes((value.len() + 1) as u64), - Align::from_bytes(1, 1).unwrap(), + Align::from_bytes(1).unwrap(), MiriMemoryKind::Env.into(), )?.with_default_tag(); self.memory_mut().write_bytes(value_copy.into(), &value)?; @@ -513,7 +513,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo } self.memory_mut().write_scalar( key_ptr, - key_layout.align, + key_layout.align.abi, Scalar::from_uint(key, key_layout.size).into(), key_layout.size, )?; diff --git a/src/helpers.rs b/src/helpers.rs index 85329ddcf17f..2b1a28fe9e0d 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -130,9 +130,10 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super: unsafe_cell_action: |place| { trace!("unsafe_cell_action on {:?}", place.ptr); // We need a size to go on. - let (unsafe_cell_size, _) = self.size_and_align_of_mplace(place)? + let unsafe_cell_size = self.size_and_align_of_mplace(place)? + .map(|(size, _)| size) // for extern types, just cover what we can - .unwrap_or_else(|| place.layout.size_and_align()); + .unwrap_or_else(|| place.layout.size); // Now handle this `UnsafeCell`, unless it is empty. if unsafe_cell_size != Size::ZERO { unsafe_cell_action(place.ptr, unsafe_cell_size) diff --git a/src/intrinsic.rs b/src/intrinsic.rs index 6d5ac8d88bae..66dab00e0975 100644 --- a/src/intrinsic.rs +++ b/src/intrinsic.rs @@ -152,7 +152,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, ' let elem_layout = self.layout_of(elem_ty)?; let elem_size = elem_layout.size.bytes(); let count = self.read_scalar(args[2])?.to_usize(self)?; - let elem_align = elem_layout.align; + let elem_align = elem_layout.align.abi; // erase tags: this is a raw ptr operation let src = self.read_scalar(args[0])?.not_undef()?; let dest = self.read_scalar(args[1])?.not_undef()?; @@ -272,7 +272,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, ' "pref_align_of" => { let ty = substs.type_at(0); let layout = self.layout_of(ty)?; - let align = layout.align.pref(); + let align = layout.align.pref.bytes(); let ptr_size = self.pointer_size(); let align_val = Scalar::from_uint(align as u128, ptr_size); self.write_scalar(align_val, dest)?; @@ -364,7 +364,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, ' .expect("size_of_val called on extern type"); let ptr_size = self.pointer_size(); self.write_scalar( - Scalar::from_uint(align.abi(), ptr_size), + Scalar::from_uint(align.bytes(), ptr_size), dest, )?; } @@ -438,7 +438,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, ' let val_byte = self.read_scalar(args[1])?.to_u8()?; let ptr = self.read_scalar(args[0])?.not_undef()?; let count = self.read_scalar(args[2])?.to_usize(self)?; - self.memory().check_align(ptr, ty_layout.align)?; + self.memory().check_align(ptr, ty_layout.align.abi)?; self.memory_mut().write_repeat(ptr, val_byte, ty_layout.size * count)?; } diff --git a/src/lib.rs b/src/lib.rs index 8eae6418fa7c..10a1405b2a62 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -397,7 +397,7 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> { // Second argument: align let arg = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?; - let align = layout.align.abi(); + let align = layout.align.abi.bytes(); ecx.write_scalar(Scalar::from_uint(align, arg.layout.size), arg)?; // No more arguments @@ -419,7 +419,7 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> { "__cxa_thread_atexit_impl" => { // This should be all-zero, pointer-sized let data = vec![0; tcx.data_layout.pointer_size.bytes() as usize]; - Allocation::from_bytes(&data[..], tcx.data_layout.pointer_align) + Allocation::from_bytes(&data[..], tcx.data_layout.pointer_align.abi) } _ => return err!(Unimplemented( format!("can't access foreign static: {}", link_name), @@ -458,9 +458,9 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> { place: MPlaceTy<'tcx, Borrow>, mutability: Option, ) -> EvalResult<'tcx, Scalar> { - let (size, _) = ecx.size_and_align_of_mplace(place)? + let size = ecx.size_and_align_of_mplace(place)?.map(|(size, _)| size) // for extern types, just cover what we can - .unwrap_or_else(|| place.layout.size_and_align()); + .unwrap_or_else(|| place.layout.size); if !ecx.tcx.sess.opts.debugging_opts.mir_emit_retag || !Self::enforce_validity(ecx) || size == Size::ZERO { @@ -498,9 +498,9 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> { // This is deliberately NOT `deref_operand` as we do not want `tag_dereference` // to be called! That would kill the original tag if we got a raw ptr. let place = ecx.ref_to_mplace(ecx.read_immediate(ptr)?)?; - let (size, _) = ecx.size_and_align_of_mplace(place)? + let size = ecx.size_and_align_of_mplace(place)?.map(|(size, _)| size) // for extern types, just cover what we can - .unwrap_or_else(|| place.layout.size_and_align()); + .unwrap_or_else(|| place.layout.size); if !ecx.tcx.sess.opts.debugging_opts.mir_emit_retag || !ecx.machine.validate || size == Size::ZERO { diff --git a/src/operator.rs b/src/operator.rs index be05c2259957..2f3a0de999ad 100644 --- a/src/operator.rs +++ b/src/operator.rs @@ -166,12 +166,12 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, ' let (alloc_size, alloc_align) = self.memory().get_size_and_align(ptr.alloc_id); // Case II: Alignment gives it away - if ptr.offset.bytes() % alloc_align.abi() == 0 { + if ptr.offset.bytes() % alloc_align.bytes() == 0 { // The offset maintains the allocation alignment, so we know `base+offset` // is aligned by `alloc_align`. // FIXME: We could be even more general, e.g. offset 2 into a 4-aligned // allocation cannot equal 3. - if bits % alloc_align.abi() != 0 { + if bits % alloc_align.bytes() != 0 { // The integer is *not* aligned. So they cannot be equal. return Ok(false); } @@ -226,7 +226,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, ' map_to_primval(left.overflowing_offset(Size::from_bytes(right as u64), self)), BitAnd if !signed => { - let ptr_base_align = self.memory().get(left.alloc_id)?.align.abi(); + let ptr_base_align = self.memory().get(left.alloc_id)?.align.bytes(); let base_mask = { // FIXME: Use interpret::truncate, once that takes a Size instead of a Layout let shift = 128 - self.memory().pointer_size().bits(); @@ -259,7 +259,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, ' Rem if !signed => { // Doing modulo a divisor of the alignment is allowed. // (Intuition: Modulo a divisor leaks less information.) - let ptr_base_align = self.memory().get(left.alloc_id)?.align.abi(); + let ptr_base_align = self.memory().get(left.alloc_id)?.align.bytes(); let right = right as u64; let ptr_size = self.memory().pointer_size().bytes() as u8; if right == 1 { From 82d4146a6c3fec5d0f87e3df6423f123dec784f6 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 24 Nov 2018 11:58:28 +0100 Subject: [PATCH 2/2] bump Rust --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index 23a0fa102b00..5bdac314d169 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -nightly-2018-11-22 +nightly-2018-11-24