[llvm] Revert "[SimplifyCFG] Deduce paths unreachable if they cause div/rem UB" (PR #137741)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 29 11:21:02 PDT 2025


dtcxzyw wrote:

> @nikic and @dtcxzyw, since you both NACK'ed this patch, please offer a way to address this issue rather than using hidden flags. This issue is not simply a Linux kernel issue. It may happen to anyone who uses Clang. So I'd like to know the best way to address this.

The best solution is to avoid UB in your code. As I said before, you cannot expect a trap to be triggered when division by zero happens (e.g., on RISC-V platforms). If you need a trap, please add an explicit check and use `__builtin_trap` (or compile your code with `-fsanitize=integer-divide-by-zero`).

For the second comment https://github.com/llvm/llvm-project/pull/137741#issuecomment-2837179510, I am okay to add a flag to insert a `__builtin_trap` before each `__builtin_unreachable` introduced by the optimizer. There is a balance between safety and performance.

> From what Linus commented, it looks like Clang isn't honoring unreachable code, and will generate some instructions after it. In the specific case, the panic() call, which is marked "noreturn".

Please file a separate issue :)


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


More information about the llvm-commits mailing list