miri: lift restriction on extern types being the only field in a struct
This commit is contained in:
parent
c5ecc15704
commit
fd47d247d8
3 changed files with 69 additions and 27 deletions
|
@ -616,19 +616,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
match self.size_and_align_of(metadata, &field)? {
|
||||
Some(size_and_align) => size_and_align,
|
||||
None => {
|
||||
// A field with extern type. If this field is at offset 0, we behave
|
||||
// like the underlying extern type.
|
||||
// FIXME: Once we have made decisions for how to handle size and alignment
|
||||
// of `extern type`, this should be adapted. It is just a temporary hack
|
||||
// to get some code to work that probably ought to work.
|
||||
if sized_size == Size::ZERO {
|
||||
return Ok(None);
|
||||
} else {
|
||||
span_bug!(
|
||||
self.cur_span(),
|
||||
"Fields cannot be extern types, unless they are at offset 0"
|
||||
)
|
||||
}
|
||||
// A field with an extern type. We don't know the actual dynamic size
|
||||
// or the alignment.
|
||||
return Ok(None);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -362,21 +362,15 @@ where
|
|||
// 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 => {
|
||||
// An extern type at offset 0, we fall back to its static alignment.
|
||||
// FIXME: Once we have made decisions for how to handle size and alignment
|
||||
// of `extern type`, this should be adapted. It is just a temporary hack
|
||||
// to get some code to work that probably ought to work.
|
||||
field_layout.align.abi
|
||||
match self.size_and_align_of(&base.meta, &field_layout)? {
|
||||
Some((_, align)) => (base.meta, offset.align_to(align)),
|
||||
None => {
|
||||
// For unsized types with an extern type tail we perform no adjustments.
|
||||
// NOTE: keep this in sync with `PlaceRef::project_field` in the codegen backend.
|
||||
assert!(matches!(base.meta, MemPlaceMeta::None));
|
||||
(base.meta, offset)
|
||||
}
|
||||
None => span_bug!(
|
||||
self.cur_span(),
|
||||
"cannot compute offset for extern type field at non-0 offset"
|
||||
),
|
||||
};
|
||||
(base.meta, offset.align_to(align))
|
||||
}
|
||||
} else {
|
||||
// base.meta could be present; we might be accessing a sized field of an unsized
|
||||
// struct.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue