Debugging functions that have fallen through to the next function is not
fun. So much so that the Linux kernel has a host utility called objtool
that can report such cases of fallthrough (for architectures objtool
supports). Example:
drivers/media/i2c/m5mols/m5mols.o: warning: objtool: m5mols_set_fmt() falls through to next function __cfi_m5mols_open()
With this new diagnostic, -Wfunction-fallthrough, we can produce a
similar diagnostic:
drivers/media/i2c/m5mols/m5mols_core.c:573:12: warning: function 'm5mols_set_fmt' falls through to next function [-Wfunction-fallthrough] static int m5mols_set_fmt(struct v4l2_subdev *sd, ^
This can help diagnose the improper usage of __builtin_unreachable(). It
can also help us spot potential codegen bugs in LLVM itself.
Example issues faced in the past:
https://github.com/ClangBuiltLinux/linux/issues?q=is%3Aissue+falls+label%3A%22%5BTOOL%5D+objtool%22+
Feature request:
https://lore.kernel.org/llvm/CAHk-=wgTSdKYbmB1JYM5vmHMcD9J9UZr0mn7BOYM_LudrP+Xvw@mail.gmail.com/
TODO: add test that the final MBB is a call to a noreturn function followed by unreachable