Re: [WIP 0/3] Memory model and atomic API in Rust

comex
2024-03-24T17:37:18Z

> On Mar 24, 2024, at 11:22 AM, Alan Stern <stern@rowland.harvard.edu> wrote:
>
> I don't know if this is what you meant by "in a weak memory model, the
> escape can ‘time travel'". Regardless, it seems very clear that any
> compiler which swaps L1 and L2 in f() has a genuine bug.

Yes, that’s what I meant. Clang thinks it’s valid to swap L1 and L2. Though, for it to actually happen, they would have to be in a loop, since the problematic optimization is “loop-invariant code motion". Here’s a modified version of your f() that shows the optimization in action:

https://godbolt.org/z/bdaTjjvMs

Anyway, my point is just that using LKMM doesn’t save you from the bug.