[PATCH] D107933: [clang] Expose unreachable fallthrough annotation warning

Nathan Chancellor via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 12 14:04:37 PDT 2021


nathanchance added a comment.

So something more along the lines of

  diff
  diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
  index 1555a9ee2465..0aa9a82e3d11 100644
  --- a/clang/include/clang/Basic/DiagnosticGroups.td
  +++ b/clang/include/clang/Basic/DiagnosticGroups.td
  @@ -823,10 +823,12 @@ def UnreachableCode : DiagGroup<"unreachable-code",
                                   [UnreachableCodeLoopIncrement]>;
   def UnreachableCodeBreak : DiagGroup<"unreachable-code-break">;
   def UnreachableCodeReturn : DiagGroup<"unreachable-code-return">;
  +def UnreachableCodeFallthrough : DiagGroup<"unreachable-code-fallthrough">;
   def UnreachableCodeAggressive : DiagGroup<"unreachable-code-aggressive",
                                       [UnreachableCode,
                                        UnreachableCodeBreak,
  -                                     UnreachableCodeReturn]>;
  +                                     UnreachableCodeReturn,
  +                                     UnreachableCodeFallthrough]>;
  
   // Aggregation warning settings.
  
  diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
  index bf857f58951b..f533076a6c77 100644
  --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
  +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
  @@ -682,6 +682,9 @@ def warn_unreachable_return : Warning<
   def warn_unreachable_loop_increment : Warning<
     "loop will run at most once (loop increment never executed)">,
     InGroup<UnreachableCodeLoopIncrement>, DefaultIgnore;
  +def warn_unreachable_fallthrough_attr : Warning<
  +  "fallthrough annotation in unreachable code">,
  +  InGroup<UnreachableCodeFallthrough>, DefaultIgnore;
   def note_unreachable_silence : Note<
     "silence by adding parentheses to mark code as explicitly dead">;
  
  @@ -9578,9 +9581,6 @@ def err_fallthrough_attr_outside_switch : Error<
     "fallthrough annotation is outside switch statement">;
   def err_fallthrough_attr_invalid_placement : Error<
     "fallthrough annotation does not directly precede switch label">;
  -def warn_fallthrough_attr_unreachable : Warning<
  -  "fallthrough annotation in unreachable code">,
  -  InGroup<ImplicitFallthrough>, DefaultIgnore;
  
   def warn_unreachable_default : Warning<
     "default label in switch which covers all enumeration values">,
  diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
  index aa2602c8d925..99ce143d3559 100644
  --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
  +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
  @@ -1125,7 +1125,7 @@ namespace {
                   // unreachable in all instantiations of the template.
                   if (!IsTemplateInstantiation)
                     S.Diag(AS->getBeginLoc(),
  -                         diag::warn_fallthrough_attr_unreachable);
  +                         diag::warn_unreachable_fallthrough_attr);
                   markFallthroughVisited(AS);
                   ++AnnotatedCnt;
                   break;

if I understand correctly?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107933/new/

https://reviews.llvm.org/D107933



More information about the cfe-commits mailing list