[PATCH] D146466: [clang] diagnose function fallthrough

Nick Desaulniers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 20 16:01:24 PDT 2023


nickdesaulniers created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

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/


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146466

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/Frontend/backend-function-fallthrough.c
  llvm/include/llvm/IR/DiagnosticInfo.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/IR/DiagnosticInfo.cpp
  llvm/test/CodeGen/AArch64/function-fallthrough.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146466.506758.patch
Type: text/x-patch
Size: 8081 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230320/794480d9/attachment.bin>


More information about the cfe-commits mailing list