Skip to content

Conversation

@RalfJung
Copy link
Member

@RalfJung RalfJung commented Oct 30, 2025

We used to clear the store buffer on every non-atomic read, which made sense back when non-atomic accesses were not allowed to race with atomic accesses -- but these days, this makes little sense, and it prevents legal behaviors from being explored (see the change in the weak.rs test). Furthermore, when we reconstruct the store buffer on the next atomic store, we assume that the "prior" state we are inserting corresponds to a non-atomic write, and thus we do not give it a sync clock -- but if we cleared the store buffer, that prior state might in fact be an atomic write, so the incorrect sync clock then leads to incorrect vector clocks which causes wrong UB and potentially also wrong behavior.

Fixes #4655

@rustbot
Copy link
Collaborator

rustbot commented Oct 30, 2025

Thank you for contributing to Miri!
Please remember to not force-push to the PR branch except when you need to rebase due to a conflict or when the reviewer asks you for it.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Oct 30, 2025
@RalfJung RalfJung force-pushed the weak-mem-na-reads branch 3 times, most recently from 930b74f to f3cba0b Compare October 30, 2025 09:32
self.write_type = write_type;
self.read.set_zero_vector();
// This is not an atomic location any more.
self.atomic_ops = None;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbeuw do you know if there is a particular reason why we kept the atomic_ops around even after a non-atomic write?

data_race.read(alloc_id, range, NaReadType::Read, None, machine)?;
if let Some(weak_memory) = weak_memory {
weak_memory.memory_accessed(range, machine.data_race.as_vclocks_ref().unwrap());
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbeuw is it correct to do absolutely nothing with the store buffers on a non-atomic read? I would think so, but better to double-check.^^

@rustbot
Copy link
Collaborator

rustbot commented Oct 30, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@RalfJung
Copy link
Member Author

RalfJung commented Nov 1, 2025

I'm going to land this for now to fix the bug; we can always adjust more later.

@RalfJung RalfJung added this pull request to the merge queue Nov 1, 2025
Merged via the queue into rust-lang:master with commit 52c5daf Nov 1, 2025
13 checks passed
@RalfJung RalfJung deleted the weak-mem-na-reads branch November 1, 2025 06:53
@rustbot rustbot removed the S-waiting-on-review Status: Waiting for a review to complete label Nov 1, 2025
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.

Incorrect data race UB reported when mixing atomic and non-atomic accesses

2 participants