[PATCH] D48239: [LangRef] Clarify meaning of "dereferencable" attribute/metadata.

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 17 11:43:41 PDT 2018


sanjoy added inline comments.


================
Comment at: docs/LangRef.rst:1133
+    returned value is dereferenceable for the duration of the program.
+    If the pointer cannot be dereferenced, the behavior is undefined. This
     attribute may only be applied to pointer typed parameters. A pointer that
----------------
nlopes wrote:
> sanjoy wrote:
> > DeadArgElim transforms
> > 
> > ```
> > define void @f(i8* dereferenceable(16) %ptr) {
> >   ret void
> > }
> > 
> > define void @caller(i8* %v) {
> >   call void @f(i8* %v)
> >   ret void
> > }
> > ```
> > 
> > to
> > 
> > ```
> > define void @f(i8* dereferenceable(16) %ptr) {
> >   ret void
> > }
> > 
> > define void @caller(i8* %v) {
> >   call void @f(i8* undef)
> >   ret void
> > }
> > ```
> > 
> > Given this semantic this transform is wrong, right?
> Nice example :)
> I guess DeadArgElim could be fixed to drop the dereferenceable tag?
> 
> I think being UB when the ptr is not dereferenceable sounds reasonable to me.
> I guess DeadArgElim could be fixed to drop the dereferenceable tag?

Sounds good to me.  I think we can think about `dereferenceable(N)` as "there is an `N` byte load from the pointer at the entry and exit of the function".


Repository:
  rL LLVM

https://reviews.llvm.org/D48239





More information about the llvm-commits mailing list