From: Alexander Kornienko Date: Fri, 25 Jan 2013 15:49:34 +0000 (+0000) Subject: Don't suggest to insert [[clang::fallthrough]] before empty cases. Fix for multiple... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e992ed1a065d857947b3969e6b779c41cc35c234;p=clang Don't suggest to insert [[clang::fallthrough]] before empty cases. Fix for multiple case labels. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173458 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index d5fa959bf4..78864ec285 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -846,13 +846,13 @@ static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC, int AnnotatedCnt; for (CFG::reverse_iterator I = Cfg->rbegin(), E = Cfg->rend(); I != E; ++I) { - const CFGBlock &B = **I; - const Stmt *Label = B.getLabel(); + const CFGBlock *B = *I; + const Stmt *Label = B->getLabel(); if (!Label || !isa(Label)) continue; - if (!FM.checkFallThroughIntoBlock(B, AnnotatedCnt)) + if (!FM.checkFallThroughIntoBlock(*B, AnnotatedCnt)) continue; S.Diag(Label->getLocStart(), @@ -864,8 +864,13 @@ static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC, if (L.isMacroID()) continue; if (S.getLangOpts().CPlusPlus11) { - const Stmt *Term = B.getTerminator(); - if (!(B.empty() && Term && isa(Term))) { + const Stmt *Term = B->getTerminator(); + // Skip empty cases. + while (B->empty() && !Term && B->succ_size() == 1) { + B = *B->succ_begin(); + Term = B->getTerminator(); + } + if (!(B->empty() && Term && isa(Term))) { Preprocessor &PP = S.getPreprocessor(); TokenValue Tokens[] = { tok::l_square, tok::l_square, PP.getIdentifierInfo("clang"), diff --git a/test/SemaCXX/switch-implicit-fallthrough.cpp b/test/SemaCXX/switch-implicit-fallthrough.cpp index cfc29c237c..75dda8a961 100644 --- a/test/SemaCXX/switch-implicit-fallthrough.cpp +++ b/test/SemaCXX/switch-implicit-fallthrough.cpp @@ -34,6 +34,8 @@ int fallthrough(int n) { case 6: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}} n += 300; case 66: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}} + case 67: + case 68: break; } switch (n / 20) {