Alex Kornienko proposed enabling this warning back in 2012 here:
At the time, Chris Lattner said he didn't feel it was worth annotating
all of LLVM and Clang with a new macro to enable this warning.
However, GCC 7 added this warning as part of -Wextra,This patch should not introduce any behavior changes. and we've slowlyIt consists of
annotated most of LLVM and Clang with LLVM_FALLTHROUGH.
At this point, I think we should re-evaluate this decision and enablely one of two changes:
this warning for both clang and GCC.
Since our codebase is already annotated,1. it will help developers (likeReplacing fall through comments with the LLVM_FALLTHROUGH macro
me), who use Clang locally,2. to find unintendedInserting 'break' before falling through bugs in theirinto a case block consisting
code. For example, I committed r345676, which had to be reverted because
of an unintended fallthrough. This warning would've helped of only 'break'.
There is also marginal benefit to aligning warnings between GCC and
Clang. While there will always be divergence in warnings between GCC and
Clang, when possibleWe were already using this warning with GCC, it saves time when clang can diagnose things thatbut its warning behaves
would later become a -Werror warning on some GCC 7 buildbot.
This is a summary ofslightly differently. In this patch, the following differences in the behavior ofare
-Wimplicit-fallthrough between clang and GCC:relevant:
1. GCC recognizes comments that say "fall through" as annotations, clang
2. GCC doesn't warn on "case N: foo(); default: break;", clang does
3. GCC doesn't warn when the case contains a switch, but falls through
the outer case. See the AArch64ISelLowering.cpp change for an
instance where this almost caused a bug, but a redundant check saved
us. I've removed the redundant check.
4. Clang warns on LLVM_FALLTHROUGH after llvm_unreachable. GCC doesn't,
so I removed the one instance of this that I found.
Changing Clang's behavior in light of these differences is out of scope
for me. I want developers who compile with any of the last 4 years of
clang releases to be able to use this warning, and those releases have
the behavior described above. If you want to discuss changing Clang to
be more like GCC here, please file a bug or start a thread on cfe-dev.
I intend to split out the libc++ parts of this patch, which are just
included for reference. The rest I plan to commit all at once, since
clang, lld, llvm, and lldb all use the same warning settings and
LLVM_FALLTHROUGH annotation macrothe outer case.
To conclude and restate, this warning is already enabled for GCC and
we've already annotated most of our codebase for it, so let's enable theI will enable the warning separately in a follow-up patch so that it can
warning for clangbe cleanly reverted if necessary.