- debug_assert_eq!(base_addr % align.bytes(), 0); // sanity check
- Ok(base_addr + ptr.offset.bytes())
+ // Sanity check that the base address is aligned.
+ debug_assert_eq!(base_addr % align.bytes(), 0);
+ // Add offset with the right kind of pointer-overflowing arithmetic.
+ let dl = memory.data_layout();
+ Ok(dl.overflowing_offset(base_addr, ptr.offset.bytes()).0)