[llvm] [LangRef] Do not allow free via synchronization in nofree (PR #195658)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Tue May 5 23:27:42 PDT 2026


antoniofrighetto wrote:

> Argument-level nofree is now specified to only apply to the particular pointer (similar to captures etc). The underlying object may still be freed via a different argument to which the same pointer is passed. (I'm open to changing this, but that would essentially limit inference to noalias arguments.)

So, given:
```llvm
define void @caller(ptr nofree %a, ptr %b) {
  call void @free(ptr %b)
  ret void
}
```

We are saying that nofree only constrains frees performed through a pointer derived from %a, regardless of whether %a and %b happen to alias, correct? I wonder if the alternative would be more correct (free(%b) UB if they alias), though I guess this would be not particularly useful. Would this be primarily helpful to optimizations on the caller side (i.e., we would like to conclude that nothing derived from %a is free'd?).

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


More information about the llvm-commits mailing list