Index: llvm/docs/LangRef.rst =================================================================== --- llvm/docs/LangRef.rst +++ llvm/docs/LangRef.rst @@ -9765,17 +9765,27 @@ } If the ``inbounds`` keyword is present, the result value of the -``getelementptr`` is a :ref:`poison value ` if the base -pointer is not an *in bounds* address of an allocated object, or if any -of the addresses that would be formed by successive addition of the -offsets implied by the indices to the base address with infinitely -precise signed arithmetic are not an *in bounds* address of that -allocated object. The *in bounds* addresses for an allocated object are -all the addresses that point into the object, plus the address one byte -past the end. The only *in bounds* address for a null pointer in the -default address-space is the null pointer itself. In cases where the -base is a vector of pointers the ``inbounds`` keyword applies to each -of the computations element-wise. +``getelementptr`` is a :ref:`poison value ` if one of the +following rules is violated: + +* The base pointer is an *in bounds* address of an allocated object, which + means that it points into or one byte past the end of an allocated object. + The only *in bounds* address for a null pointer in the default + address-space is the null pointer itself. +* The multiplication of an index by the type size does not wrap in a signed + sense (``nsw``). +* The successive addition of the current address, interpreted as an unsigned + number, and an offset, interpreted as a signed number, does not wrap the + unsigned address space and remains *in bounds* of the allocated object. +* In cases where the base is a vector of pointers, the ``inbounds`` keyword + applies to each of the computations element-wise. + +As a corollary, the following two properties follow: + +* The successive addition of offsets (without adding the base address) does + not wrap in a signed sense (``nsw``). +* The addition of the base address and a *non-negative* offset does not wrap + in an unsigned sense (``nuw``). If the ``inbounds`` keyword is not present, the offsets are added to the base address with silently-wrapping two's complement arithmetic. If the