Skip to content

Commit ba0bab3

Browse files
committed
make sure we only guess field alignment at offset 0
1 parent a6622c2 commit ba0bab3

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/librustc_mir/interpret/eval_context.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,12 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
374374
let (unsized_size, unsized_align) = match self.size_and_align_of(metadata, field)? {
375375
Some(size_and_align) => size_and_align,
376376
None => {
377-
// A field with extern type. If this field is at offset 0 and the sized
378-
// part makes no alignment constraints, we behave like the underlying
379-
// extern type.
377+
// A field with extern type. If this field is at offset 0, we behave
378+
// like the underlying extern type.
380379
// FIXME: Once we have made decisions for how to handle size and alignment
381380
// of `extern type`, this should be adapted. It is just a temporary hack
382381
// to get some code to work that probably ought to work.
383-
if sized_size == Size::ZERO && sized_align.abi() == 1 {
382+
if sized_size == Size::ZERO {
384383
return Ok(None)
385384
} else {
386385
bug!("Fields cannot be extern types, unless they are at offset 0")

src/librustc_mir/interpret/place.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,17 @@ where
353353
// Offset may need adjustment for unsized fields
354354
let (meta, offset) = if field_layout.is_unsized() {
355355
// re-use parent metadata to determine dynamic field layout
356-
let align = self.size_and_align_of(base.meta, field_layout)?
357-
.map(|(_, align)| align)
358-
// If this is an extern type, we fall back to its static alignment.
359-
// FIXME: Once we have made decisions for how to handle size and alignment
360-
// of `extern type`, this should be adapted. It is just a temporary hack
361-
// to get some code to work that probably ought to work.
362-
.unwrap_or_else(|| base.layout.align);
356+
let align = match self.size_and_align_of(base.meta, field_layout)? {
357+
Some((_, align)) => align,
358+
None if offset == Size::ZERO =>
359+
// An extern type at offset 0, we fall back to its static alignment.
360+
// FIXME: Once we have made decisions for how to handle size and alignment
361+
// of `extern type`, this should be adapted. It is just a temporary hack
362+
// to get some code to work that probably ought to work.
363+
field_layout.align,
364+
None =>
365+
bug!("Cannot compute offset for extern type field at non-0 offset"),
366+
};
363367
(base.meta, offset.abi_align(align))
364368
} else {
365369
// base.meta could be present; we might be accessing a sized field of an unsized

0 commit comments

Comments
 (0)