[llvm] LangRef: storing poison in memory is UB (PR #141339)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 22 03:45:42 PDT 2026


dtcxzyw wrote:

> I used to hit a rare miscompilation with rustlantis + llubi, which contains a store with poison value in the optimized IR.

I hit this again in https://github.com/dtcxzyw/llvm-autoreduce/issues/320 :)
src:
```
; opt -passes=licm reduced.ll
define i32 @main() {
entry:
  %p = alloca ptr
  br label %al

al:
  br i1 false, label %if.end, label %exit

if.end:
  store ptr null, ptr %p
  br label %al

exit:
  ret i32 0
}
```
tgt:
```
define i32 @main() {
entry:
  %p = alloca ptr, align 8
  %p.promoted = load ptr, ptr %p, align 1 ; returns poison
  br label %al

al:
  %0 = phi ptr [ null, %if.end ], [ %p.promoted, %entry ]
  br i1 false, label %if.end, label %exit

if.end:
  br label %al

exit:
  %.lcssa = phi ptr [ %0, %al ]
  store ptr %.lcssa, ptr %p, align 1 ; UB
  ret i32 0
}
```


https://github.com/llvm/llvm-project/pull/141339


More information about the llvm-commits mailing list