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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 25 03:49:32 PDT 2026


nikic wrote:

> We're saying, essentially, if memory is used as a noalias argument, the memory is not dereferenceable. So global variables are not dereferenceable unless you can prove they aren't used by a noalias operation.

Yes, this is a known problem in the interaction of globals and noalias that nobody seems to have a solution to...

> Escaped allocas are not dereferenceable, because they could be used in a noalias function on another thread.

Hm, I think this case has not come up before. This is problematic.

> "nofree" implies that the pointer is not used as a noalias pointer.

I'm not sure what you mean here. nofree kind of requires the definition of dereferenceability specified here in order to be useful at all, otherwise nofree + noalias + dereferenceable does not actually imply that the object cannot have been freed (because if dereferenceable does not perform an access, then there may have never been an access through the noalias pointer, so it has no effect).

> The only reason "noalias" is even defined the way it's currently defined, with the "memory locations that are modified" rule, is due to C "restrict"; all the other uses of the attribute would be just fine with an alternate formulation that takes a specific size. And we know how to make that work: just say any load while there's an alternative provenance active produces poison. The only reason we can't do that for "restrict" is that we don't know what the size is.

Yes, having a sized noalias would make all of the semantics questions in this area much simpler. Though the unsized form is very convenient from an implementation perspective, because we can just treat it as an identified object and don't have to reason about access ranges.

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


More information about the llvm-commits mailing list