Skip to content

Detect (non-raw) borrows of null ZST pointers in CheckNull#136601

Merged
bors merged 2 commits into
rust-lang:masterfrom
compiler-errors:borrow-null-zst
Feb 9, 2025
Merged

Detect (non-raw) borrows of null ZST pointers in CheckNull#136601
bors merged 2 commits into
rust-lang:masterfrom
compiler-errors:borrow-null-zst

Conversation

@compiler-errors

@compiler-errors compiler-errors commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

Fixes #136568. Ensures that we check that borrows of derefs are non-null in the CheckNull pass even if it's a ZST pointee.

I'm actually surprised that this is UB in Miri, but if it's certainly UB, then this PR modifies the null check to be stricter. I couldn't find anywhere in https://doc.rust-lang.org/reference/behavior-considered-undefined.html that discusses this case specifically, but I didn't read it too closely, or perhaps it's just missing a bullet point.

On the contrary, if this is actually erroneous UB in Miri, then I'm happy to close this (and perhaps fix the null check in Miri to exclude ZSTs?)

On the double contrary, if this is still an "open question", I'm also happy to close this and wait for a decision to be made.

r? @saethlin cc @RalfJung (perhaps you feel strongly about this change)

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Null ptr check doesn't catch null reference to ZSTs

6 participants