2 ms·
For anyone else also trying to wrap their head around the Clang C++ optimization/concurrency bug [1]: The crux of it is that deleting *p = i prior to foo(i, a)
by dataflow 3y ago
For anyone else also trying to wrap their head around the Clang C++ optimization/concurrency bug [1]:
The crux of it is that deleting *p = i prior to foo(i, a) is illegal, because it would lose the guarantee that *a == N implies *p == N in another thread, when X == p.
(i.e. After the optimization, it becomes possible for other threads to observe *p != N even when *a == N, but this should be impossible according to the original code.)
The general issue is that loop invariant code motion (LICM) optimization would also be required to hoist out any threading-related guarantees (like memory fences) from loops, not just the data as it appears to a single thread.
[1] https://github.com/llvm/llvm-project/issues/64188 https://github.com/llvm/llvm-project/issues/64188