Skip to content
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

Don't try to force_ptr pointers to zsts #68088

Merged
merged 1 commit into from
Jan 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,14 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
return Ok(());
RalfJung marked this conversation as resolved.
Show resolved Hide resolved
}
// 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)
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well.. with the check_mplace_access we additionally get a check ensuring that the zst is correctly aligned (due to the early abort we're not checking this anymore), so if we want to keep doing such checks we're going to have to either duplicate all the logic in a struct/tuple arm or we have to intermingle it here as I did earlier with check_mplace_access.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

@RalfJung RalfJung Jan 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely assume it to be dereferencable:

/// This function checks the data at `op`. `op` is assumed to cover valid memory if it

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)?;

Expand Down Expand Up @@ -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)
Expand Down