[llvm] 9334ef9 - [LangRef] Specify that load of alloca outside lifetime is poison (#157852)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 11 03:22:51 PDT 2025
Author: Nikita Popov
Date: 2025-09-11T12:22:47+02:00
New Revision: 9334ef98984f53f344cf5953ab74cdc29a0675de
URL: https://github.com/llvm/llvm-project/commit/9334ef98984f53f344cf5953ab74cdc29a0675de
DIFF: https://github.com/llvm/llvm-project/commit/9334ef98984f53f344cf5953ab74cdc29a0675de.diff
LOG: [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 https://github.com/llvm/llvm-project/issues/141892 (and probably a
bunch of others...)
Added:
Modified:
llvm/docs/LangRef.rst
Removed:
################################################################################
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 45ae2327323d6..43d31b03932cf 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -3388,6 +3388,10 @@ the object's lifetime. A stack object's lifetime can be explicitly specified
using :ref:`llvm.lifetime.start <int_lifestart>` and
:ref:`llvm.lifetime.end <int_lifeend>` intrinsic function calls.
+As an exception to the above, loading from a stack object outside its lifetime
+is not undefined behavior and returns a poison value instead. Storing to it is
+still undefined behavior.
+
.. _pointeraliasing:
Pointer Aliasing Rules
More information about the llvm-commits
mailing list