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

comex comexk at gmail.com
Sun Mar 24 10:37:03 PDT 2024



> On Mar 24, 2024, at 11:22 AM, Alan Stern <stern at 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.


More information about the linux-arm-kernel mailing list