[llvm] [IR] Don't allow values of opaque type (PR #137625)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 28 05:48:45 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {undef deprecator}-->


:warning: undef deprecator found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git diff -U0 --pickaxe-regex -S '([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)' 'HEAD~1' HEAD llvm/include/llvm/IR/Type.h llvm/lib/IR/Type.cpp llvm/lib/Linker/IRMover.cpp llvm/test/Assembler/2004-11-28-InvalidTypeCrash.ll llvm/test/Assembler/2005-05-05-OpaqueUndefValues.ll llvm/test/Assembler/2007-01-02-Undefined-Arg-Type.ll llvm/test/CodeGen/WebAssembly/externref-unsized-load.ll llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll llvm/test/CodeGen/X86/cfguard-x86-64-vectorcall.ll llvm/test/CodeGen/X86/cfguard-x86-vectorcall.ll llvm/test/Linker/Inputs/type-unique-opaque.ll llvm/test/Linker/intrinsics-with-unnamed-types.ll llvm/test/Linker/pr22807.ll llvm/test/Linker/type-unique-opaque.ll llvm/test/ThinLTO/X86/Inputs/import_opaque_type.ll llvm/test/ThinLTO/X86/import_opaque_type.ll llvm/test/Transforms/InstSimplify/gv-alloca-cmp.ll llvm/test/Transforms/Reg2Mem/non-token-test.ll llvm/test/Verifier/memset-pattern-unsized.ll llvm/test/Verifier/nofpclass.ll llvm/test/Verifier/unsized-types-load.ll llvm/test/Verifier/unsized-types-store.ll llvm/unittests/FuzzMutate/OperationsTest.cpp llvm/test/Linker/Inputs/pr22807.ll
``````````

</details>


The following files introduce new uses of undef:
 - llvm/test/Assembler/2005-05-05-OpaqueUndefValues.ll
 - llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll

[Undef](https://llvm.org/docs/LangRef.html#undefined-values) is now deprecated and should only be used in the rare cases where no replacement is possible. For example, a load of uninitialized memory yields `undef`. You should use `poison` values for placeholders instead.

In tests, avoid using `undef` and having tests that trigger undefined behavior. If you need an operand with some unimportant value, you can add a new argument to the function and use that instead.

For example, this is considered a bad practice:
```llvm
define void @fn() {
  ...
  br i1 undef, ...
}
```

Please use the following instead:
```llvm
define void @fn(i1 %cond) {
  ...
  br i1 %cond, ...
}
```

Please refer to the [Undefined Behavior Manual](https://llvm.org/docs/UndefinedBehavior.html) for more information.



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


More information about the llvm-commits mailing list