[llvm] [LangRef] Specify that dereferenceable implies a spurious read (PR #218413)

Ralf Jung via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 05:34:42 PDT 2026


RalfJung wrote:

So, something like this:
- in `threadA`, `%ptr` is declared `dereferenceable nofree`
- function spawns a thread to run `threadB`
- `threadB` passes `%ptr` to a `noalias` function
- back in `threadA`, LLVM inserts a spurious read (e.g. pulls it out of a loop that was actually dead)
- (the thread synchronize via a barrier)
- in `threadB`, a write to `%ptr` occurs

This write is now UB because the spurious read in thread A conflicts with the write in thread B.
(I added the barrier to ensure that with `noalias`, the spurious read would actually give a valid result.)

https://github.com/llvm/llvm-project/pull/218413


More information about the llvm-commits mailing list