[clang] [CodeGen] Apply 'readonly' to 'this' pointer argument. (PR #106499)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 29 03:12:54 PDT 2024


nikic wrote:

> > I'm very confused. `readonly` means that the memory behind `this` cannot be changed, not that the pointer cannot be changed.
> 
> Out of curiosity, it looks not same in https://llvm.org/docs/LangRef.html:
> 
> > This attribute indicates that the function does not write through this pointer argument, even though it may write to the memory that the pointer points to.
> > If a function writes to a readonly pointer argument, the behavior is undefined.
> 
> My understanding for ` it may write to the memory that the pointer points to.` is what you said. Or do we need to update the document?

The distinction in LangRef is about a write through the pointer vs a write through an alias of the pointer to the same memory. Only the former is forbidden.

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


More information about the cfe-commits mailing list