-
Notifications
You must be signed in to change notification settings - Fork 342
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
Data race false positive due to delayed allocation optimization #3242
Comments
That's in general quite tricky, since we support this kind of delayed initialization for ScalarPair -- so we'd have to track a timestamp for each pair component. Also this breaks our usual memory abstractions pretty badly. There's a fairly easy solution, which is to put the write done at the time of actual (late) initialization at timestamp 0. That will avoid false UB but will introduce bugs where we miss UB, such as in this example. I think currently my preferred solution is
|
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.
miri: treat non-memory local variables properly for data race detection Fixes #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.
The following code should be fine, but Miri raises an error:
The issue has been described well by CAD97 here:
The text was updated successfully, but these errors were encountered: