From 212f233b7d548c54ddec73142dfce1ee96a0c5c9 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 13 Jun 2019 12:26:10 -0500 Subject: [PATCH] Replace to_bits by force_bits and move size as parameter --- src/librustc_mir/interpret/eval_context.rs | 8 ++++++-- src/librustc_mir/interpret/memory.rs | 8 ++++++-- src/librustc_mir/interpret/operator.rs | 2 +- src/librustc_mir/interpret/place.rs | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 793759c2465a0..17a39988217de 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -783,7 +783,11 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tc } #[inline(always)] - pub fn force_bits(&self, scalar: Scalar) -> InterpResult<'tcx, u128> { - self.memory.force_bits(scalar) + pub fn force_bits( + &self, + scalar: Scalar, + size: Size + ) -> InterpResult<'tcx, u128> { + self.memory.force_bits(scalar, size) } } diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 6dd0c9f7319b3..3922793a27c60 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -890,8 +890,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { } } - pub fn force_bits(&self, scalar: Scalar) -> InterpResult<'tcx, u128> { - match scalar.to_bits_or_ptr(self.pointer_size(), self) { + pub fn force_bits( + &self, + scalar: Scalar, + size: Size + ) -> InterpResult<'tcx, u128> { + match scalar.to_bits_or_ptr(size, self) { Ok(bits) => Ok(bits), Err(ptr) => Ok(M::ptr_to_int(ptr, &self.extra)? as u128) } diff --git a/src/librustc_mir/interpret/operator.rs b/src/librustc_mir/interpret/operator.rs index db7da9359de7b..c6801efa9c4c8 100644 --- a/src/librustc_mir/interpret/operator.rs +++ b/src/librustc_mir/interpret/operator.rs @@ -347,7 +347,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M> } _ => { assert!(layout.ty.is_integral()); - let val = val.to_bits(layout.size)?; + let val = self.force_bits(val, layout.size)?; let res = match un_op { Not => !val, Neg => { diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index e05ed0906bab0..6582d70339bfd 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -470,7 +470,7 @@ where let layout = self.layout_of(self.tcx.types.usize)?; let n = self.access_local(self.frame(), local, Some(layout))?; let n = self.read_scalar(n)?; - let n = n.to_bits(self.tcx.data_layout.pointer_size)?; + let n = self.force_bits(n.not_undef()?, self.tcx.data_layout.pointer_size)?; self.mplace_field(base, u64::try_from(n).unwrap())? }