Skip to content

Commit 03f21e2

Browse files
authored
[LangRef] Update initializes definition (llvm#134370)
Specify the initializes attribute in terms of an "initialized" shadow state, such that: * Loads prior to initialization return poison. * Bytes that are not explicitly initialized are written with undef on function return. This is intended to preserve the core semantics of the attribute, but adjusts the wording in a way that is compatible with existing optimizations, such as insertion of spurious loads and removal of uninitialized writes. Fixes llvm#133038. Fixes llvm#133059.
1 parent 2c1bdd4 commit 03f21e2

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

llvm/docs/LangRef.rst

+18-4
Original file line numberDiff line numberDiff line change
@@ -1690,10 +1690,24 @@ Currently, only the following parameter attributes are defined:
16901690

16911691
``initializes((Lo1, Hi1), ...)``
16921692
This attribute indicates that the function initializes the ranges of the
1693-
pointer parameter's memory, ``[%p+LoN, %p+HiN)``. Initialization of memory
1694-
means the first memory access is a non-volatile, non-atomic write. The
1695-
write must happen before the function returns. If the function unwinds,
1696-
the write may not happen.
1693+
pointer parameter's memory ``[%p+LoN, %p+HiN)``. Colloquially, this means
1694+
that all bytes in the specified range are written before the function
1695+
returns, and not read prior to the initializing write. If the function
1696+
unwinds, the write may not happen.
1697+
1698+
Formally, this is specified in terms of an "initialized" shadow state for
1699+
all bytes in the range, which is set to "not initialized" at function entry.
1700+
If a memory access is performed through a pointer based on the argument,
1701+
and an accessed byte has not been marked as "initialized" yet, then:
1702+
1703+
* If the byte is stored with a non-volatile, non-atomic write, mark it as
1704+
"initialized".
1705+
* If the byte is stored with a volatile or atomic write, the behavior is
1706+
undefined.
1707+
* If the byte is loaded, return a poison value.
1708+
1709+
Additionally, if the function returns normally, write an undef value to all
1710+
bytes that are part of the range and have not been marked as "initialized".
16971711

16981712
This attribute only holds for the memory accessed via this pointer
16991713
parameter. Other arbitrary accesses to the same memory via other pointers

0 commit comments

Comments
 (0)