[llvm] [RFC][BPF] Report Unreachable Behavior from IR (PR #126858)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 26 13:36:12 PST 2025
eddyz87 wrote:
I was curious if there are other cases besides switch instruction, where `unreachable` could survive up to codegen. Unfortunately, `unreachable` is generated in a lot of places with complex logic, e.g. loop fusion or SCCP. It looks like it is impossible to know the answer for sure.
Given this, I tend to agree that a runtime trap would be a simpler solution. E.g. something along the lines libbpf does [here](https://github.com/libbpf/libbpf/blob/42a6ef63161a8dc4288172b27f3870e50b3606f7/src/libbpf.c#L6062), where it inserts a call to unknown helper function. In kernel `verifier.c:get_helper_proto()` is only called from `check_helper_call()` on main verification pass. Meaning that if `unreachable` is a dead code, verifier would delete it, otherwise it would report an error.
Verifier can be changed to report something about undefined behaviour trap to simplify debugging. BPF backend can be changed to avoid clobbering registers because of this special trap call.
Just my 5 cents.
https://github.com/llvm/llvm-project/pull/126858
More information about the llvm-commits
mailing list