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