-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
type_size
now returns None
for unsized types
- Loading branch information
Showing
4 changed files
with
31 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { | |
"copy_nonoverlapping" => { | ||
// FIXME: check whether overlapping occurs | ||
let elem_ty = substs.type_at(0); | ||
let elem_size = self.type_size(elem_ty); | ||
let elem_size = self.type_size(elem_ty).expect("cannot copy unsized value"); | ||
let elem_align = self.type_align(elem_ty); | ||
let src = arg_vals[0].read_ptr(&self.memory)?; | ||
let dest = arg_vals[1].read_ptr(&self.memory)?; | ||
|
@@ -230,7 +230,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { | |
|
||
"offset" => { | ||
let pointee_ty = substs.type_at(0); | ||
let pointee_size = self.type_size(pointee_ty) as isize; | ||
let pointee_size = self.type_size(pointee_ty).expect("cannot offset a pointer to an unsized type") as isize; | ||
let offset = self.value_to_primval(arg_vals[1], isize)? | ||
.expect_int("offset second arg not isize"); | ||
|
||
|
@@ -281,7 +281,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { | |
|
||
"size_of" => { | ||
let ty = substs.type_at(0); | ||
let size = self.type_size(ty) as u64; | ||
// FIXME: change the `box_free` lang item to take `T: ?Sized` and have it use the | ||
// `size_of_val` intrinsic, then change this back to | ||
// .expect("size_of intrinsic called on unsized value") | ||
// see https://github.com/rust-lang/rust/pull/37708 | ||
let size = self.type_size(ty).unwrap_or(!0) as u64; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
oli-obk
Author
Contributor
|
||
let size_val = self.usize_primval(size); | ||
self.write_primval(dest, size_val)?; | ||
} | ||
|
@@ -360,8 +364,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { | |
value: Value, | ||
) -> EvalResult<'tcx, (u64, u64)> { | ||
let pointer_size = self.memory.pointer_size(); | ||
if self.type_is_sized(ty) { | ||
Ok((self.type_size(ty) as u64, self.type_align(ty) as u64)) | ||
if let Some(size) = self.type_size(ty) { | ||
Ok((size as u64, self.type_align(ty) as u64)) | ||
} else { | ||
match ty.sty { | ||
ty::TyAdt(def, substs) => { | ||
|
@@ -435,7 +439,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { | |
|
||
ty::TySlice(_) | ty::TyStr => { | ||
let elem_ty = ty.sequence_element_type(self.tcx); | ||
let elem_size = self.type_size(elem_ty) as u64; | ||
let elem_size = self.type_size(elem_ty).expect("slice element must be sized") as u64; | ||
let len = value.expect_slice_len(&self.memory)?; | ||
let align = self.type_align(elem_ty); | ||
Ok((len * elem_size, align as u64)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Why
!0
?