-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
miri: treat non-memory local variables properly for data race detection #129828
Conversation
Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri The Miri subtree was changed cc @rust-lang/miri |
I'll steal the review |
☔ The latest upstream changes (presumably #129778) made this pull request unmergeable. Please resolve the merge conflicts. |
2894ff7
to
a888905
Compare
// Local can be updated in-place. | ||
*local_val = src; | ||
// Call the machine hook (the data race detector needs to know about this write). | ||
if !self.validation_in_progress() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these checks for valiation_in_progress()
just an optimization, or are they required for correctness?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This matches the equivalent logic in memory.rs
. There it is definitely required; we have some "administrative reads" that we don't want to show up in the aliasing model (specifically, the ones added in #128942).
Here I am not sure if it is required, but it would seem odd to not make this consistent with the logic in memory.rs
.
@rustbot author |
@rustbot ready |
@bors r+ |
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#129439 (Implement feature `string_from_utf8_lossy_owned` for lossy conversion from `Vec<u8>` to `String` methods) - rust-lang#129828 (miri: treat non-memory local variables properly for data race detection) - rust-lang#130110 (make dist vendoring configurable) - rust-lang#130293 (Fix lint levels not getting overridden by attrs on `Stmt` nodes) - rust-lang#130342 (interpret, miri: fix dealing with overflow during slice indexing and allocation) Failed merges: - rust-lang#130394 (const: don't ICE when encountering a mutable ref to immutable memory) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#129828 - RalfJung:miri-data-race, r=saethlin miri: treat non-memory local variables properly for data race detection Fixes rust-lang/miri#3242 Miri has an optimization where some local variables are not represented in memory until something forces them to be stored in memory (most notably, creating a pointer/reference to the local will do that). However, for a subsystem triggering on memory accesses -- such as the data race detector -- this means that the memory access seems to happen only when the local is moved to memory, instead of at the time that it actually happens. This can lead to UB reports in programs that do not actually have UB. This PR fixes that by adding machine hooks for reads and writes to such efficiently represented local variables. The data race system tracks those very similar to how it would track reads and writes to addressable memory, and when a local is moved to memory, the clocks get overwritten with the information stored for the local.
Fixes rust-lang/miri#3242
Miri has an optimization where some local variables are not represented in memory until something forces them to be stored in memory (most notably, creating a pointer/reference to the local will do that). However, for a subsystem triggering on memory accesses -- such as the data race detector -- this means that the memory access seems to happen only when the local is moved to memory, instead of at the time that it actually happens. This can lead to UB reports in programs that do not actually have UB.
This PR fixes that by adding machine hooks for reads and writes to such efficiently represented local variables. The data race system tracks those very similar to how it would track reads and writes to addressable memory, and when a local is moved to memory, the clocks get overwritten with the information stored for the local.