Skip to content

Commit 9334ef9

Browse files
authored
[LangRef] Specify that load of alloca outside lifetime is poison (#157852)
We consider (in bounds) loads from allocas to always be speculatable, without taking lifetimes into account. This means that such loads cannot be immediate UB. Specify them as returning poison instead. Due to stack coloring, such a load may end up loading from a different alloca, but that's compatible with poison. Stores are still UB, but that's a much more narrow problem (I think the only transform violating that part is store scalar promotion in LICM). Fixes #141892 (and probably a bunch of others...)
1 parent b970108 commit 9334ef9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

llvm/docs/LangRef.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,6 +3388,10 @@ the object's lifetime. A stack object's lifetime can be explicitly specified
33883388
using :ref:`llvm.lifetime.start <int_lifestart>` and
33893389
:ref:`llvm.lifetime.end <int_lifeend>` intrinsic function calls.
33903390

3391+
As an exception to the above, loading from a stack object outside its lifetime
3392+
is not undefined behavior and returns a poison value instead. Storing to it is
3393+
still undefined behavior.
3394+
33913395
.. _pointeraliasing:
33923396

33933397
Pointer Aliasing Rules

0 commit comments

Comments
 (0)