Skip to content

Commit 129b914

Browse files
committed
int_align has no dynamic error case
1 parent e53e9b9 commit 129b914

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/librustc_mir/interpret/memory.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
11741174
pub fn read_primval(&self, ptr: MemoryPointer, size: u64, signed: bool) -> EvalResult<'tcx, PrimVal> {
11751175
self.check_relocation_edges(ptr, size)?; // Make sure we don't read part of a pointer as a pointer
11761176
let endianess = self.endianess();
1177-
let bytes = self.get_bytes_unchecked(ptr, size, self.int_align(size)?)?;
1177+
let bytes = self.get_bytes_unchecked(ptr, size, self.int_align(size))?;
11781178
// Undef check happens *after* we established that the alignment is correct.
11791179
// We must not return Ok() for unaligned pointers!
11801180
if self.check_defined(ptr, size).is_err() {
@@ -1207,7 +1207,6 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
12071207
}
12081208

12091209
pub fn write_primval(&mut self, ptr: MemoryPointer, val: PrimVal, size: u64, signed: bool) -> EvalResult<'tcx> {
1210-
let align = self.int_align(size)?;
12111210
let endianess = self.endianess();
12121211

12131212
let bytes = match val {
@@ -1237,6 +1236,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
12371236
};
12381237

12391238
{
1239+
let align = self.int_align(size);
12401240
let dst = self.get_bytes_mut(ptr, size, align)?;
12411241
if signed {
12421242
write_target_int(endianess, dst, bytes as i128).unwrap();
@@ -1264,15 +1264,15 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
12641264
self.write_primval(ptr, val, ptr_size, false)
12651265
}
12661266

1267-
fn int_align(&self, size: u64) -> EvalResult<'tcx, u64> {
1267+
fn int_align(&self, size: u64) -> u64 {
12681268
// We assume pointer-sized integers have the same alignment as pointers.
1269-
// We also assume singed and unsigned integers of the same size have the same alignment.
1269+
// We also assume signed and unsigned integers of the same size have the same alignment.
12701270
match size {
1271-
1 => Ok(self.layout.i8_align.abi()),
1272-
2 => Ok(self.layout.i16_align.abi()),
1273-
4 => Ok(self.layout.i32_align.abi()),
1274-
8 => Ok(self.layout.i64_align.abi()),
1275-
16 => Ok(self.layout.i128_align.abi()),
1271+
1 => self.layout.i8_align.abi(),
1272+
2 => self.layout.i16_align.abi(),
1273+
4 => self.layout.i32_align.abi(),
1274+
8 => self.layout.i64_align.abi(),
1275+
16 => self.layout.i128_align.abi(),
12761276
_ => bug!("bad integer size: {}", size),
12771277
}
12781278
}

0 commit comments

Comments
 (0)