Skip to content

interpret/validity: reject references to uninhabited types #97116

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
May 18, 2022

Conversation

RalfJung
Copy link
Member

According to https://doc.rust-lang.org/reference/behavior-considered-undefined.html, this is definitely UB. And we can check this without actually looking up anything in memory, we just need the reference value and its type, making this a great candidate for a validity invariant IMO and my favorite resolution of rust-lang/unsafe-code-guidelines#77.

With this PR, Miri with -Zmiri-check-number-validity implements all my preferred options for what the validity invariants of our types could be. :)

CTFE has been doing recursive checking anyway, so this is backwards compatible but might change the error output. I will submit a PR with the new Miri tests soon.

r? @oli-obk

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 17, 2022
@rust-highfive
Copy link
Contributor

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 17, 2022
@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor

oli-obk commented May 17, 2022

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 17, 2022

📌 Commit 201750d has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 17, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request May 18, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#96647 (rustdoc-json: Fix HRTBs for WherePredicate::BoundPredicate)
 - rust-lang#96651 (Omit unnecessary help to add `#[cfg(test)]` when already annotated)
 - rust-lang#96761 (rustdoc: don't build `rayon` for non-windows targets)
 - rust-lang#97096 (Types with reachable constructors are reachable)
 - rust-lang#97097 (Add tmm_reg clobbers)
 - rust-lang#97113 (Search GUI fixes)
 - rust-lang#97116 (interpret/validity: reject references to uninhabited types)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 248890c into rust-lang:master May 18, 2022
@rustbot rustbot added this to the 1.63.0 milestone May 18, 2022
bors added a commit to rust-lang/miri that referenced this pull request May 18, 2022
test for validity of references pointing to uninhabited types

The new tests for rust-lang/rust#97116
@RalfJung RalfJung deleted the ref-validity branch May 18, 2022 06:35
# for free to join this conversation on GitHub. Already have an account? # 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.

6 participants