[clang] c61401b - Revert "[clang] detect switch fallthrough marked by a comment (PR43465)"

Luboš Luňák via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 2 13:33:50 PST 2020


Author: Luboš Luňák
Date: 2020-03-02T22:33:25+01:00
New Revision: c61401b89742f230b7e6a2cc0548fbf7442e906d

URL: https://github.com/llvm/llvm-project/commit/c61401b89742f230b7e6a2cc0548fbf7442e906d
DIFF: https://github.com/llvm/llvm-project/commit/c61401b89742f230b7e6a2cc0548fbf7442e906d.diff

LOG: Revert "[clang] detect switch fallthrough marked by a comment (PR43465)"

This reverts commit 398b4ed87d488b42032c8d0304324dce76ba9b66.
As requested in https://bugs.llvm.org/show_bug.cgi?id=43465#c37 .

Added: 
    

Modified: 
    clang/lib/Sema/AnalysisBasedWarnings.cpp

Removed: 
    clang/test/Sema/fallthrough-comment.c


################################################################################
diff  --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index a162ff091efd..04611dadde66 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -1148,11 +1148,6 @@ namespace {
           continue;
         }
 
-        if (isFollowedByFallThroughComment(LastStmt)) {
-          ++AnnotatedCnt;
-          continue; // Fallthrough comment, good.
-        }
-
         ++UnannotatedCnt;
       }
       return !!UnannotatedCnt;
@@ -1213,41 +1208,10 @@ namespace {
       return nullptr;
     }
 
-    bool isFollowedByFallThroughComment(const Stmt *Statement) {
-      // Try to detect whether the fallthough is marked by a comment like
-      // /*FALLTHOUGH*/.
-      bool Invalid;
-      const char *SourceData = S.getSourceManager().getCharacterData(
-          Statement->getEndLoc(), &Invalid);
-      if (Invalid)
-        return false;
-      const char *LineStart = SourceData;
-      for (;;) {
-        LineStart = strchr(LineStart, '\n');
-        if (LineStart == nullptr)
-          return false;
-        ++LineStart; // Start of next line.
-        const char *LineEnd = strchr(LineStart, '\n');
-        StringRef Line(LineStart,
-                       LineEnd ? LineEnd - LineStart : strlen(LineStart));
-        if (LineStart == LineEnd ||
-            Line.find_first_not_of(" \t\r") == StringRef::npos)
-          continue; // Whitespace-only line.
-        if (!FallthroughRegex.isValid())
-          FallthroughRegex =
-              llvm::Regex("(/\\*[ \\t]*fall(s | |-)?thr(ough|u)\\.?[ \\t]*\\*/)"
-                          "|(//[ \\t]*fall(s | |-)?thr(ough|u)\\.?[ \\t]*)",
-                          llvm::Regex::IgnoreCase);
-        assert(FallthroughRegex.isValid());
-        return FallthroughRegex.match(Line);
-      }
-    }
-
     bool FoundSwitchStatements;
     AttrStmts FallthroughStmts;
     Sema &S;
     llvm::SmallPtrSet<const CFGBlock *, 16> ReachableBlocks;
-    llvm::Regex FallthroughRegex;
   };
 } // anonymous namespace
 

diff  --git a/clang/test/Sema/fallthrough-comment.c b/clang/test/Sema/fallthrough-comment.c
deleted file mode 100644
index 85d1257932f6..000000000000
--- a/clang/test/Sema/fallthrough-comment.c
+++ /dev/null
@@ -1,20 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c11 -verify -Wimplicit-fallthrough %s
-
-int fallthrough_comment(int n) {
-  switch (n) {
-  case 0:
-    n++;
-    // FALLTHROUGH
-  case 1:
-    n++;
-
-    /*fall-through.*/
-
-  case 2:
-    n++;
-  case 3: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '__attribute__((fallthrough));' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
-    n++;
-    break;
-  }
-  return n;
-}


        


More information about the cfe-commits mailing list