]> granicus.if.org Git - clang/commitdiff
Don't suggest to insert [[clang::fallthrough]] before empty cases. Fix for multiple...
authorAlexander Kornienko <alexfh@google.com>
Fri, 25 Jan 2013 15:49:34 +0000 (15:49 +0000)
committerAlexander Kornienko <alexfh@google.com>
Fri, 25 Jan 2013 15:49:34 +0000 (15:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173458 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/AnalysisBasedWarnings.cpp
test/SemaCXX/switch-implicit-fallthrough.cpp

index d5fa959bf449b86d4863c20b4bf92b5dc14b4d0d..78864ec2852e326162e88c2a77f857aa8b2866ea 100644 (file)
@@ -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<SwitchCase>(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<BreakStmt>(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<BreakStmt>(Term))) {
           Preprocessor &PP = S.getPreprocessor();
           TokenValue Tokens[] = {
             tok::l_square, tok::l_square, PP.getIdentifierInfo("clang"),
index cfc29c237c2d5cbc2062e93ca6334a489421b8ba..75dda8a9617969e5de64fc2ad86ec6c8eb4db9fe 100644 (file)
@@ -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) {