summaryrefslogtreecommitdiffstats
path: root/llvm/docs
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2016-11-10 22:34:55 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2016-11-10 22:34:55 +0000
commitd93620bf4d5e165999ad1c3cec2a2fdb02f56218 (patch)
treeaef2609ce725411649a10eb99701de1eb1bf7843 /llvm/docs
parenta0dee61df34fc819aeb26607bd099ef2ae61c903 (diff)
downloadbcm5719-llvm-d93620bf4d5e165999ad1c3cec2a2fdb02f56218.tar.gz
bcm5719-llvm-d93620bf4d5e165999ad1c3cec2a2fdb02f56218.zip
IR: Introduce inrange attribute on getelementptr indices.
If the inrange keyword is present before any index, loading from or storing to any pointer derived from the getelementptr has undefined behavior if the load or store would access memory outside of the bounds of the element selected by the index marked as inrange. This can be used, e.g. for alias analysis or to split globals at element boundaries where beneficial. As previously proposed on llvm-dev: http://lists.llvm.org/pipermail/llvm-dev/2016-July/102472.html Differential Revision: https://reviews.llvm.org/D22793 llvm-svn: 286514
Diffstat (limited to 'llvm/docs')
-rw-r--r--llvm/docs/LangRef.rst18
1 files changed, 15 insertions, 3 deletions
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 22295287c35..f20f4385c2f 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -7450,9 +7450,9 @@ Syntax:
::
- <result> = getelementptr <ty>, <ty>* <ptrval>{, <ty> <idx>}*
- <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, <ty> <idx>}*
- <result> = getelementptr <ty>, <ptr vector> <ptrval>, <vector index type> <idx>
+ <result> = getelementptr <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
+ <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
+ <result> = getelementptr <ty>, <ptr vector> <ptrval>, [inrange] <vector index type> <idx>
Overview:
"""""""""
@@ -7569,6 +7569,18 @@ though, even if it happens to point into allocated storage. See the
:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more
information.
+If the ``inrange`` keyword is present before any index, loading from or
+storing to any pointer derived from the ``getelementptr`` has undefined
+behavior if the load or store would access memory outside of the bounds of
+the element selected by the index marked as ``inrange``. The result of a
+pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations
+involving memory) involving a pointer derived from a ``getelementptr`` with
+the ``inrange`` keyword is undefined, with the exception of comparisons
+in the case where both operands are in the range of the element selected
+by the ``inrange`` keyword, inclusive of the address one past the end of
+that element. Note that the ``inrange`` keyword is currently only allowed
+in constant ``getelementptr`` expressions.
+
The getelementptr instruction is often confusing. For some more insight
into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`.
OpenPOWER on IntegriCloud