[PATCH] D90708: [LangRef] Clarify GEP inbounds wrapping semantics

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 11 12:00:09 PST 2020


nikic added inline comments.


================
Comment at: llvm/docs/LangRef.rst:9782
+   means that it points into an allocated object, or to its end (which is one
+   byte past the last byte contained in the object). The only *in bounds*
+   address for a null pointer in the default address-space is the null pointer
----------------
nlopes wrote:
> I still don't like the current writing. I would need to see some evidence from language standards that they require pointers past the end of objects.
What would be a better wording? "One past the end" is a term of art, and as such should be well understood: https://www.google.com/search?q=one+past+the+end


================
Comment at: llvm/docs/LangRef.rst:9789
+   index type in a signed sense (``nsw``).
+*  The successive addition of offsets (without adding the base address) does
+   not wrap the pointer index type in a signed sense (``nsw``).
----------------
jrtc27 wrote:
> nlopes wrote:
> > It's a bit stronger than that. The addition of each offset to the preceding pointer should not overflow. You can't do e.g.:
> > gep inbounds %p, -1, 1
> > 
> > because %p-1 is OOB, even though the result is in bounds (because %p must be in bounds).
> It's more nuanced than that, no? `%p` could be a pointer part-way through (or one past the end of) an object, in which case `%p-1` would still be in bounds?
This is specified in the next bullet point (successive addition to the base pointer must remain in bounds of the allocated object).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90708/new/

https://reviews.llvm.org/D90708



More information about the llvm-commits mailing list