Page MenuHomePhabricator

Fix clang -Wimplicit-fallthrough warnings across llvm, NFC
ClosedPublic

Authored by rnk on Oct 31 2018, 2:24 PM.

Details

Summary

This patch should not introduce any behavior changes. It consists of
mostly one of two changes:

  1. Replacing fall through comments with the LLVM_FALLTHROUGH macro
  2. Inserting 'break' before falling through into a case block consisting of only 'break'.

We were already using this warning with GCC, but its warning behaves
slightly differently. In this patch, the following differences are
relevant:

  1. GCC recognizes comments that say "fall through" as annotations, clang doesn't
  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.

I will enable the warning separately in a follow-up patch so that it can
be cleanly reverted if necessary.

Diff Detail

Repository
rL LLVM

Event Timeline

rnk created this revision.Oct 31 2018, 2:24 PM
bogner added a subscriber: bogner.Oct 31 2018, 3:24 PM
bogner added inline comments.
clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
190 ↗(On Diff #172020)

Having both LLVM_FALLTHROUGH and the comment is redundant.

clang/lib/AST/ExprConstant.cpp
11146 ↗(On Diff #172020)

Could you commit this case (and the one below) separately? While most of the changes in this patch are mechanical, this one is arguably a correctness fix.

rnk added inline comments.Oct 31 2018, 3:41 PM
clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
190 ↗(On Diff #172020)

It is, but I made an effort to preserve comments like this everywhere, since I thought it might go down easier for more folks. It's not hard to remove them, of course.

clang/lib/AST/ExprConstant.cpp
11146 ↗(On Diff #172020)

Sure, there's this and a couple others, like the AArch64ISelLowering one.

bogner accepted this revision.Oct 31 2018, 3:48 PM

lgtm as long as there's general consent to the idea in the llvm-dev thread.

clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
190 ↗(On Diff #172020)

I'd prefer them removed, unless someone really wants them for some reason.

This revision is now accepted and ready to land.Oct 31 2018, 3:48 PM

Great! Thanks for picking this up and pushing forward!

clang/lib/Analysis/FormatString.cpp
692 ↗(On Diff #172020)

None of these comments seem useful.

clang/tools/clang-func-mapping/ClangFnMapGen.cpp
85 ↗(On Diff #172020)

Incorrect indentation.

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
11039–11040 ↗(On Diff #172020)

This looks like something that's better to commit separately.

llvm/lib/Target/AMDGPU/SIISelLowering.cpp
5053 ↗(On Diff #172020)

Maybe remove the braces? There are none in the other cases.

llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp
791 ↗(On Diff #172020)

Commit bug fixes separately?

1211 ↗(On Diff #172020)

Invalid indentation.

llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
1571 ↗(On Diff #172020)

Incorrect indentation

MatzeB accepted this revision.Oct 31 2018, 5:17 PM

LGTM, thanks for pushing this! Some of the changes here look like things that were just waiting to become an actual problem.

lattner accepted this revision.Oct 31 2018, 10:38 PM
rnk updated this revision to Diff 172208.Nov 1 2018, 12:48 PM
rnk marked 5 inline comments as done.

Address comments
Split out all behavior changes

rnk added inline comments.Nov 1 2018, 12:49 PM
clang/lib/AST/ExprConstant.cpp
11146 ↗(On Diff #172020)

This became rC345862.

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
11039–11040 ↗(On Diff #172020)

This became rL345864.

llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp
791 ↗(On Diff #172020)

This became rL345868.

rnk retitled this revision from Enable -Wimplicit-fallthrough for clang as well as GCC to Fix clang -Wimplicit-fallthrough warnings across llvm, NFC.Nov 1 2018, 12:56 PM
rnk edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.