Skip to content

Commit 68ba6cd

Browse files
committed
fix for new Align type
1 parent 3798a8e commit 68ba6cd

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

src/fn_call.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
124124
if size == 0 {
125125
self.write_null(dest)?;
126126
} else {
127-
let align = self.tcx.data_layout.pointer_align;
127+
let align = self.tcx.data_layout.pointer_align.abi;
128128
let ptr = self.memory_mut().allocate(Size::from_bytes(size), align, MiriMemoryKind::C.into())?;
129129
self.write_scalar(Scalar::Ptr(ptr.with_default_tag()), dest)?;
130130
}
@@ -153,7 +153,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
153153
let ptr = self.memory_mut()
154154
.allocate(
155155
Size::from_bytes(size),
156-
Align::from_bytes(align, align).unwrap(),
156+
Align::from_bytes(align).unwrap(),
157157
MiriMemoryKind::Rust.into()
158158
)?
159159
.with_default_tag();
@@ -171,7 +171,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
171171
let ptr = self.memory_mut()
172172
.allocate(
173173
Size::from_bytes(size),
174-
Align::from_bytes(align, align).unwrap(),
174+
Align::from_bytes(align).unwrap(),
175175
MiriMemoryKind::Rust.into()
176176
)?
177177
.with_default_tag();
@@ -190,7 +190,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
190190
}
191191
self.memory_mut().deallocate(
192192
ptr,
193-
Some((Size::from_bytes(old_size), Align::from_bytes(align, align).unwrap())),
193+
Some((Size::from_bytes(old_size), Align::from_bytes(align).unwrap())),
194194
MiriMemoryKind::Rust.into(),
195195
)?;
196196
}
@@ -208,9 +208,9 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
208208
let new_ptr = self.memory_mut().reallocate(
209209
ptr,
210210
Size::from_bytes(old_size),
211-
Align::from_bytes(align, align).unwrap(),
211+
Align::from_bytes(align).unwrap(),
212212
Size::from_bytes(new_size),
213-
Align::from_bytes(align, align).unwrap(),
213+
Align::from_bytes(align).unwrap(),
214214
MiriMemoryKind::Rust.into(),
215215
)?;
216216
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
394394
// +1 for the null terminator
395395
let value_copy = self.memory_mut().allocate(
396396
Size::from_bytes((value.len() + 1) as u64),
397-
Align::from_bytes(1, 1).unwrap(),
397+
Align::from_bytes(1).unwrap(),
398398
MiriMemoryKind::Env.into(),
399399
)?.with_default_tag();
400400
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
513513
}
514514
self.memory_mut().write_scalar(
515515
key_ptr,
516-
key_layout.align,
516+
key_layout.align.abi,
517517
Scalar::from_uint(key, key_layout.size).into(),
518518
key_layout.size,
519519
)?;

src/helpers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
130130
unsafe_cell_action: |place| {
131131
trace!("unsafe_cell_action on {:?}", place.ptr);
132132
// We need a size to go on.
133-
let (unsafe_cell_size, _) = self.size_and_align_of_mplace(place)?
133+
let unsafe_cell_size = self.size_and_align_of_mplace(place)?
134+
.map(|(size, _)| size)
134135
// for extern types, just cover what we can
135-
.unwrap_or_else(|| place.layout.size_and_align());
136+
.unwrap_or_else(|| place.layout.size);
136137
// Now handle this `UnsafeCell`, unless it is empty.
137138
if unsafe_cell_size != Size::ZERO {
138139
unsafe_cell_action(place.ptr, unsafe_cell_size)

src/intrinsic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
152152
let elem_layout = self.layout_of(elem_ty)?;
153153
let elem_size = elem_layout.size.bytes();
154154
let count = self.read_scalar(args[2])?.to_usize(self)?;
155-
let elem_align = elem_layout.align;
155+
let elem_align = elem_layout.align.abi;
156156
// erase tags: this is a raw ptr operation
157157
let src = self.read_scalar(args[0])?.not_undef()?;
158158
let dest = self.read_scalar(args[1])?.not_undef()?;
@@ -272,7 +272,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
272272
"pref_align_of" => {
273273
let ty = substs.type_at(0);
274274
let layout = self.layout_of(ty)?;
275-
let align = layout.align.pref();
275+
let align = layout.align.pref.bytes();
276276
let ptr_size = self.pointer_size();
277277
let align_val = Scalar::from_uint(align as u128, ptr_size);
278278
self.write_scalar(align_val, dest)?;
@@ -364,7 +364,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
364364
.expect("size_of_val called on extern type");
365365
let ptr_size = self.pointer_size();
366366
self.write_scalar(
367-
Scalar::from_uint(align.abi(), ptr_size),
367+
Scalar::from_uint(align.bytes(), ptr_size),
368368
dest,
369369
)?;
370370
}
@@ -438,7 +438,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
438438
let val_byte = self.read_scalar(args[1])?.to_u8()?;
439439
let ptr = self.read_scalar(args[0])?.not_undef()?;
440440
let count = self.read_scalar(args[2])?.to_usize(self)?;
441-
self.memory().check_align(ptr, ty_layout.align)?;
441+
self.memory().check_align(ptr, ty_layout.align.abi)?;
442442
self.memory_mut().write_repeat(ptr, val_byte, ty_layout.size * count)?;
443443
}
444444

src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
397397

398398
// Second argument: align
399399
let arg = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?;
400-
let align = layout.align.abi();
400+
let align = layout.align.abi.bytes();
401401
ecx.write_scalar(Scalar::from_uint(align, arg.layout.size), arg)?;
402402

403403
// No more arguments
@@ -419,7 +419,7 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
419419
"__cxa_thread_atexit_impl" => {
420420
// This should be all-zero, pointer-sized
421421
let data = vec![0; tcx.data_layout.pointer_size.bytes() as usize];
422-
Allocation::from_bytes(&data[..], tcx.data_layout.pointer_align)
422+
Allocation::from_bytes(&data[..], tcx.data_layout.pointer_align.abi)
423423
}
424424
_ => return err!(Unimplemented(
425425
format!("can't access foreign static: {}", link_name),
@@ -458,9 +458,9 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
458458
place: MPlaceTy<'tcx, Borrow>,
459459
mutability: Option<hir::Mutability>,
460460
) -> EvalResult<'tcx, Scalar<Borrow>> {
461-
let (size, _) = ecx.size_and_align_of_mplace(place)?
461+
let size = ecx.size_and_align_of_mplace(place)?.map(|(size, _)| size)
462462
// for extern types, just cover what we can
463-
.unwrap_or_else(|| place.layout.size_and_align());
463+
.unwrap_or_else(|| place.layout.size);
464464
if !ecx.tcx.sess.opts.debugging_opts.mir_emit_retag ||
465465
!Self::enforce_validity(ecx) || size == Size::ZERO
466466
{
@@ -498,9 +498,9 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
498498
// This is deliberately NOT `deref_operand` as we do not want `tag_dereference`
499499
// to be called! That would kill the original tag if we got a raw ptr.
500500
let place = ecx.ref_to_mplace(ecx.read_immediate(ptr)?)?;
501-
let (size, _) = ecx.size_and_align_of_mplace(place)?
501+
let size = ecx.size_and_align_of_mplace(place)?.map(|(size, _)| size)
502502
// for extern types, just cover what we can
503-
.unwrap_or_else(|| place.layout.size_and_align());
503+
.unwrap_or_else(|| place.layout.size);
504504
if !ecx.tcx.sess.opts.debugging_opts.mir_emit_retag ||
505505
!ecx.machine.validate || size == Size::ZERO
506506
{

src/operator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
166166
let (alloc_size, alloc_align) = self.memory().get_size_and_align(ptr.alloc_id);
167167

168168
// Case II: Alignment gives it away
169-
if ptr.offset.bytes() % alloc_align.abi() == 0 {
169+
if ptr.offset.bytes() % alloc_align.bytes() == 0 {
170170
// The offset maintains the allocation alignment, so we know `base+offset`
171171
// is aligned by `alloc_align`.
172172
// FIXME: We could be even more general, e.g. offset 2 into a 4-aligned
173173
// allocation cannot equal 3.
174-
if bits % alloc_align.abi() != 0 {
174+
if bits % alloc_align.bytes() != 0 {
175175
// The integer is *not* aligned. So they cannot be equal.
176176
return Ok(false);
177177
}
@@ -226,7 +226,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
226226
map_to_primval(left.overflowing_offset(Size::from_bytes(right as u64), self)),
227227

228228
BitAnd if !signed => {
229-
let ptr_base_align = self.memory().get(left.alloc_id)?.align.abi();
229+
let ptr_base_align = self.memory().get(left.alloc_id)?.align.bytes();
230230
let base_mask = {
231231
// FIXME: Use interpret::truncate, once that takes a Size instead of a Layout
232232
let shift = 128 - self.memory().pointer_size().bits();
@@ -259,7 +259,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
259259
Rem if !signed => {
260260
// Doing modulo a divisor of the alignment is allowed.
261261
// (Intuition: Modulo a divisor leaks less information.)
262-
let ptr_base_align = self.memory().get(left.alloc_id)?.align.abi();
262+
let ptr_base_align = self.memory().get(left.alloc_id)?.align.bytes();
263263
let right = right as u64;
264264
let ptr_size = self.memory().pointer_size().bytes() as u8;
265265
if right == 1 {

0 commit comments

Comments
 (0)