fix field indexing into fat pointers
This commit is contained in:
parent
d42a7d021d
commit
75f56eb144
2 changed files with 13 additions and 4 deletions
|
@ -544,7 +544,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
let dest = self.force_allocation(dest)?.to_ptr();
|
let dest = self.force_allocation(dest)?.to_ptr();
|
||||||
|
|
||||||
let dest = dest.offset(offset.bytes() as isize);
|
let dest = dest.offset(offset.bytes() as isize);
|
||||||
let dest_size = self.type_size(ty).unwrap_or(self.memory.pointer_size());
|
let dest_size = self.type_size(ty).expect("bad StructWrappedNullablePointer discrfield");
|
||||||
try!(self.memory.write_int(dest, 0, dest_size));
|
try!(self.memory.write_int(dest, 0, dest_size));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -734,8 +734,17 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
ty::TyRef(_, ty::TypeAndMut { ty, .. }) |
|
ty::TyRef(_, ty::TypeAndMut { ty, .. }) |
|
||||||
ty::TyRawPtr(ty::TypeAndMut { ty, .. }) |
|
ty::TyRawPtr(ty::TypeAndMut { ty, .. }) |
|
||||||
ty::TyBox(ty) => {
|
ty::TyBox(ty) => {
|
||||||
assert_eq!(field_index, 0);
|
if self.type_is_sized(ty) {
|
||||||
Ok(ty)
|
assert_eq!(field_index, 0);
|
||||||
|
Ok(self.tcx.mk_imm_ptr(self.tcx.types.never))
|
||||||
|
} else {
|
||||||
|
match (field_index, &ty.sty) {
|
||||||
|
(1, &ty::TySlice(_)) => Ok(self.tcx.types.usize),
|
||||||
|
(1, &ty::TyTrait(_)) |
|
||||||
|
(0, _) => Ok(self.tcx.mk_imm_ptr(self.tcx.types.never)),
|
||||||
|
_ => bug!("invalid fat pointee type"),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => Err(EvalError::Unimplemented(format!("can't handle type: {:?}, {:?}", ty, ty.sty))),
|
_ => Err(EvalError::Unimplemented(format!("can't handle type: {:?}, {:?}", ty, ty.sty))),
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,7 +272,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
let (offset, ty) = self.nonnull_offset_and_ty(adt_ty, nndiscr, discrfield)?;
|
let (offset, ty) = self.nonnull_offset_and_ty(adt_ty, nndiscr, discrfield)?;
|
||||||
let nonnull = adt_ptr.offset(offset.bytes() as isize);
|
let nonnull = adt_ptr.offset(offset.bytes() as isize);
|
||||||
// only the pointer part of a fat pointer is used for this space optimization
|
// only the pointer part of a fat pointer is used for this space optimization
|
||||||
let discr_size = self.type_size(ty).unwrap_or(self.memory.pointer_size());
|
let discr_size = self.type_size(ty).expect("bad StructWrappedNullablePointer discrfield");
|
||||||
self.read_nonnull_discriminant_value(nonnull, nndiscr, discr_size)?
|
self.read_nonnull_discriminant_value(nonnull, nndiscr, discr_size)?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue