IT lexicon › Programming › Poison value

Poison value

Programming På svenska → Updated: 2026-11-05

LLVM's way of deferring undefined behaviour: a value produced by an illegal operation that only causes trouble if it is actually used.

Signed integer overflow in C is undefined, and LLVM marks the addition add nsw. If that were immediately undefined, the optimizer could never hoist such an addition out of a loop that might not run. With poison, the overflow instead yields a tainted value that propagates through computations. Only when it steers a branch, serves as an address or gets stored somewhere that matters does it become undefined behaviour — and suddenly speculative code motion is legal.

The older undef — an arbitrary value that may differ at every use — turned out to be nearly impossible to reason about. Juneyoung Lee and colleagues documented in 2017 how the rules contradicted each other and produced miscompilations. The freeze instruction, which pins a poison value to something arbitrary but fixed, landed in LLVM 10 in 2020, and undef has been on its way out ever since.

← Back to the lexicon