Skip to content

ZST pointers and pointer equality #453

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

Merged
merged 3 commits into from
Sep 18, 2018
Merged

ZST pointers and pointer equality #453

merged 3 commits into from
Sep 18, 2018

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Sep 15, 2018

Corresponding rustc PR to make these actually pass is upcoming.

This is mostly a whole bunch of new tests to make sure that we rule out loading a ZST from an out-of-bounds pointer (because it might be NULL). Also, pointer equality changes to be more conservative, so I think that with this change we only return a result for an equality test when we can be sure -- with the sole exception of a one-past-the-end pointer of one allocation being compared to the first pointer of another allocation; these two could be equal if the allocations are placed right next to each other.

@RalfJung
Copy link
Member Author

Here it is: rust-lang/rust#54254

bors added a commit to rust-lang/rust that referenced this pull request Sep 15, 2018
miri engine: keep around some information for dead allocations

We use it to make sure a dangling ptr is aligned and non-NULL. This makes some code pass that should pass (writing a ZST to a properly aligned dangling pointer), and makes some code fail that should fail (writing a ZST to a pointer obtained via pointer arithmetic from a real location, but ouf-of-bounds -- that pointer could be NULL, so we cannot allow writing to it).

CTFE does not allow these operations; tests are added to miri with rust-lang/miri#453.
@RalfJung RalfJung changed the title test more operations on dangling ZST pointers ZST pointers and pointer equality Sep 15, 2018
@RalfJung
Copy link
Member Author

I added another commit that makes pointer equality more strict, and adds compile-fail tests for all cases I can think of right now that I think should fail.

@RalfJung RalfJung force-pushed the zst branch 2 times, most recently from 2b81f9d to 420c074 Compare September 15, 2018 16:33
bors added a commit to rust-lang/rust that referenced this pull request Sep 17, 2018
miri engine: keep around some information for dead allocations

We use it to test if a dangling ptr is aligned and non-NULL. This makes some code pass that should pass (writing a ZST to a properly aligned dangling pointer), and makes some code fail that should fail (writing a ZST to a pointer obtained via pointer arithmetic from a real location, but ouf-of-bounds -- that pointer could be NULL, so we cannot allow writing to it).

CTFE does not allow these operations; tests are added to miri with rust-lang/miri#453.
…; and fix ptr equality to fail all of them.

At least these are the cases I can think of right now.
@RalfJung RalfJung merged commit 384c2be into rust-lang:master Sep 18, 2018
@RalfJung RalfJung deleted the zst branch October 12, 2018 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants