Skip to content

Commit

Permalink
Rollup merge of rust-lang#58615 - RalfJung:ref-to-place-alignment, r=…
Browse files Browse the repository at this point in the history
…oli-obk

miri: explain why we use static alignment in ref-to-place conversion

@eddyb @oli-obk do you think this makes sense? Or should we use the run-time alignment (`align_of_val`)? I am a bit worried about custom DSTs, but that affects way more areas of Miri so I'd ignore them for now.

r? @oli-obk
  • Loading branch information
Centril authored Feb 22, 2019
2 parents 30b69c5 + b01f81b commit 0f3bbbc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/librustc_mir/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ where

let mplace = MemPlace {
ptr: val.to_scalar_ptr()?,
// We could use the run-time alignment here. For now, we do not, because
// the point of tracking the alignment here is to make sure that the *static*
// alignment information emitted with the loads is correct. The run-time
// alignment can only be more restrictive.
align: layout.align.abi,
meta: val.to_meta()?,
};
Expand Down Expand Up @@ -385,9 +389,11 @@ where
// above). In that case, all fields are equal.
let field_layout = base.layout.field(self, usize::try_from(field).unwrap_or(0))?;

// Offset may need adjustment for unsized fields
// Offset may need adjustment for unsized fields.
let (meta, offset) = if field_layout.is_unsized() {
// re-use parent metadata to determine dynamic field layout
// Re-use parent metadata to determine dynamic field layout.
// With custom DSTS, this *will* execute user-defined code, but the same
// happens at run-time so that's okay.
let align = match self.size_and_align_of(base.meta, field_layout)? {
Some((_, align)) => align,
None if offset == Size::ZERO =>
Expand Down

0 comments on commit 0f3bbbc

Please sign in to comment.