[llvm] New "initialized" parameter attribute LangRef (PR #82564)

Haopeng Liu via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 17:14:31 PST 2024


https://github.com/haopliu created https://github.com/llvm/llvm-project/pull/82564

None

>From 5b9a37179a09ab1671fa78b696b87b348ded8b16 Mon Sep 17 00:00:00 2001
From: Haopeng Liu <haopliu at google.com>
Date: Fri, 16 Feb 2024 00:57:31 +0000
Subject: [PATCH 1/2] add initialized attribute LangRef

---
 llvm/docs/LangRef.rst | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index fd2e3aacd0169c..6f7a0fd3f7ba5a 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -1589,6 +1589,23 @@ Currently, only the following parameter attributes are defined:
     ``readonly`` or a ``memory`` attribute that does not contain
     ``argmem: write``.
 
+``initialized((Lo1,Hi1),...)``
+    This attribute is a list of const ranges in ascending order with no
+    overlapping or continuous. It indicates that the function initializes the
+    memory through the pointer argument, [%p+LoN, %p+HiN), and there is no read
+    before initialization in the function. (even though it may read before
+    initializating the memory that the pointer points to).
+
+    The ``writable`` or ``dereferenceable`` attribute does not imply
+    ``initialized`` attribute, however the ``initialized`` argument does imply
+    ``writable`` and ``dereferenceable`` in the specified spaces.
+
+    The ``initialized`` attribute can combine with ``writeonly`` attribute, but
+    cannot be combined with ``readnone``, ``readonly`` or a memory attribute
+    that does not contain ``argmem: write``.
+
+    [TODO: unwind]
+
 ``dead_on_unwind``
     At a high level, this attribute indicates that the pointer argument is dead
     if the call unwinds, in the sense that the caller will not depend on the

>From 0be7b883bd97de1113a85bb0ca6ecf6875a6098e Mon Sep 17 00:00:00 2001
From: Haopeng Liu <haopliu at google.com>
Date: Thu, 22 Feb 2024 01:11:13 +0000
Subject: [PATCH 2/2] update initialized attr LangRef

---
 llvm/docs/LangRef.rst | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 6f7a0fd3f7ba5a..b140fef11ecbed 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -1592,10 +1592,19 @@ Currently, only the following parameter attributes are defined:
 ``initialized((Lo1,Hi1),...)``
     This attribute is a list of const ranges in ascending order with no
     overlapping or continuous. It indicates that the function initializes the
-    memory through the pointer argument, [%p+LoN, %p+HiN), and there is no read
-    before initialization in the function. (even though it may read before
-    initializating the memory that the pointer points to).
-
+    memory through the pointer argument, [%p+LoN, %p+HiN): there are no reads,
+    no special uses (such as volatile access, untrackable capture, arithmetic
+    operation), and no instructions that may throw an exception before the
+    initialization in the function.
+
+    Similarly to ``writeonly`` or ``readonly``, this attribute implies that
+    the function initializes and does not read before initialization through
+    this pointer argument, even though it may read the memory before
+    initialization that the pointer points to, such as through other arguments.
+
+    Note that as there are no instructions that may throw an exception before
+    initialization, this attribute is still validated even if the call unwinds.
+   
     The ``writable`` or ``dereferenceable`` attribute does not imply
     ``initialized`` attribute, however the ``initialized`` argument does imply
     ``writable`` and ``dereferenceable`` in the specified spaces.
@@ -1604,8 +1613,6 @@ Currently, only the following parameter attributes are defined:
     cannot be combined with ``readnone``, ``readonly`` or a memory attribute
     that does not contain ``argmem: write``.
 
-    [TODO: unwind]
-
 ``dead_on_unwind``
     At a high level, this attribute indicates that the pointer argument is dead
     if the call unwinds, in the sense that the caller will not depend on the



More information about the llvm-commits mailing list