-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Don't try to force_ptr pointers to zsts #68088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -608,9 +608,14 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> | |||
return Ok(()); | ||||
} | ||||
// This is the element type size. | ||||
let ty_size = self.ecx.layout_of(tys)?.size; | ||||
let layout = self.ecx.layout_of(tys)?; | ||||
// Empty tuples and fieldless structs (the only ZSTs that allow reaching this code) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes it very odd that we have them in the same match arm as integers, given that we handle them entirely separate... we could have a match arm for these ZST that just doesn't do anything, I think. But that is a pre-existing condition, so we can leave that for later and fix Miri now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well.. with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC validity checking assumes that the place itself is aligned and dereferencable? For references, we check those before adding them to the TODO list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We definitely assume it to be dereferencable: rust/src/librustc_mir/interpret/validity.rs Line 668 in 19b9b26
I don't think we check alignment elsewhere... and that's okay, we want to use this to validate packed structs as well! |
||||
// have no data to be checked. | ||||
if layout.is_zst() { | ||||
return Ok(()); | ||||
} | ||||
// This is the size in bytes of the whole array. | ||||
let size = ty_size * len; | ||||
let size = layout.size * len; | ||||
// Size is not 0, get a pointer. | ||||
let ptr = self.ecx.force_ptr(mplace.ptr)?; | ||||
|
||||
|
@@ -640,7 +645,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> | |||
// Some byte was undefined, determine which | ||||
// element that byte belongs to so we can | ||||
// provide an index. | ||||
let i = (offset.bytes() / ty_size.bytes()) as usize; | ||||
let i = (offset.bytes() / layout.size.bytes()) as usize; | ||||
self.path.push(PathElem::ArrayElem(i)); | ||||
|
||||
throw_validation_failure!("undefined bytes", self.path) | ||||
|
Uh oh!
There was an error while loading. Please reload this page.