Skip to content

[LangRef] Update initializes definition #134370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions llvm/docs/LangRef.rst
Original file line number Diff line number Diff line change
@@ -1690,10 +1690,24 @@ Currently, only the following parameter attributes are defined:

``initializes((Lo1, Hi1), ...)``
This attribute indicates that the function initializes the ranges of the
pointer parameter's memory, ``[%p+LoN, %p+HiN)``. Initialization of memory
means the first memory access is a non-volatile, non-atomic write. The
write must happen before the function returns. If the function unwinds,
the write may not happen.
pointer parameter's memory ``[%p+LoN, %p+HiN)``. Colloquially, this means
that all bytes in the specified range are written before the function
returns, and not read prior to the initializing write. If the function
unwinds, the write may not happen.

Formally, this is specified in terms of an "initialized" shadow state for
all bytes in the range, which is set to "not initialized" at function entry.
If a memory access is performed through a pointer based on the argument,
and an accessed byte has not been marked as "initialized" yet, then:

* If the byte is stored with a non-volatile, non-atomic write, mark it as
"initialized".
* If the byte is stored with a volatile or atomic write, the behavior is
undefined.
* If the byte is loaded, return a poison value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be poison, since initializes is only added to function arguments when they are initialized. And reduces our use of undef.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning poison is a bit problematic due to load poison widening, but I would be okay with specifying poison here. (As we currently just ignore the whole load poison widening issue everywhere anyway.)


Additionally, if the function returns normally, write an undef value to all
bytes that are part of the range and have not been marked as "initialized".

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