Add constraint that ptr, val and old should not alias each other.
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I don't believe a compiler can ever generate code that hits this code path. The public function is:
c C atomic_exchange_explicit( volatile A* obj, C desired, memory_order order );
The compiler lowers this by allocating space for the return value (*old) and passing desired by reference. The right thing to do is probably document that the two parameters must not alias (I'd be happy with sticking restrict on all three pointer arguments, actually, and documenting that).
I really don't like the xor magic in the alternative path because it breaks any pointer provenance. If the target is any kind of CHERI CPU, it will generate invalid machine code. If we are in an LTO build and end up inlining this function then we're destroying any alias info that we might otherwise have. If we actually need that path, I'd much rather that we copied everything via a temporary and used intptr_t for any chunks that are sized and aligned like an intptr_t.