Fix unions

This commit is contained in:
Oliver Schneider 2017-06-19 16:54:31 +02:00
parent 75fddee700
commit a6734cd890
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9
2 changed files with 88 additions and 3 deletions

View file

@ -182,7 +182,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
field_ty: Ty<'tcx>,
) -> EvalResult<'tcx, Lvalue<'tcx>> {
let base_layout = self.type_layout(base_ty)?;
use rustc::ty::layout::Layout::*;
let (offset, packed) = match *base_layout {
Univariant { ref variant, .. } => {
@ -255,8 +254,13 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}
},
Value::ByVal(_) => {
assert_eq!(field_index, 0, "ByVal can only have 1 non zst field with offset 0");
return Ok(base);
if self.get_field_count(base_ty)? == 1 {
assert_eq!(field_index, 0, "ByVal can only have 1 non zst field with offset 0");
return Ok(base);
}
// this branch is taken when a union creates a large ByVal which is then
// accessed as a struct with multiple small fields
(PrimVal::Ptr(self.force_allocation(base)?.to_ptr()?), LvalueExtra::None)
},
Value::ByValPair(_, _) => {
let field_count = self.get_field_count(base_ty)?;