[PATCH] D75461: Ignore macro expansions when scanning for fallthrough comments

2020-03-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added a reviewer: tstellar.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When scanning for fallthrough comments, it's not useful to go to the definition 
of a macro. We instead only want to search at the expanded source code 
location. Includes a test that failed before.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75461

Files:
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/Sema/fallthrough-comment.c


Index: clang/test/Sema/fallthrough-comment.c
===
--- clang/test/Sema/fallthrough-comment.c
+++ clang/test/Sema/fallthrough-comment.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c11 -verify -Wimplicit-fallthrough %s
 
+#define SOME_CONSTANT 1
+
 int fallthrough_comment(int n) {
   switch (n) {
   case 0:
@@ -10,9 +12,13 @@
 
 /*fall-through.*/
 
-  case 2:
+  case 3:
+n += SOME_CONSTANT;
+/* FALL THRU */
+
+  case 4:
 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}}
+  case 5: // 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;
   }
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -1216,9 +1216,10 @@
 bool isFollowedByFallThroughComment(const Stmt *Statement) {
   // Try to detect whether the fallthough is marked by a comment like
   // /*FALLTHOUGH*/.
+  auto Loc = S.getSourceManager().getExpansionLoc(Statement->getEndLoc());
   bool Invalid;
-  const char *SourceData = S.getSourceManager().getCharacterData(
-  Statement->getEndLoc(), &Invalid);
+  const char *SourceData =
+  S.getSourceManager().getCharacterData(Loc, &Invalid);
   if (Invalid)
 return false;
   const char *LineStart = SourceData;


Index: clang/test/Sema/fallthrough-comment.c
===
--- clang/test/Sema/fallthrough-comment.c
+++ clang/test/Sema/fallthrough-comment.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c11 -verify -Wimplicit-fallthrough %s
 
+#define SOME_CONSTANT 1
+
 int fallthrough_comment(int n) {
   switch (n) {
   case 0:
@@ -10,9 +12,13 @@
 
 /*fall-through.*/
 
-  case 2:
+  case 3:
+n += SOME_CONSTANT;
+/* FALL THRU */
+
+  case 4:
 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}}
+  case 5: // 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;
   }
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -1216,9 +1216,10 @@
 bool isFollowedByFallThroughComment(const Stmt *Statement) {
   // Try to detect whether the fallthough is marked by a comment like
   // /*FALLTHOUGH*/.
+  auto Loc = S.getSourceManager().getExpansionLoc(Statement->getEndLoc());
   bool Invalid;
-  const char *SourceData = S.getSourceManager().getCharacterData(
-  Statement->getEndLoc(), &Invalid);
+  const char *SourceData =
+  S.getSourceManager().getCharacterData(Loc, &Invalid);
   if (Invalid)
 return false;
   const char *LineStart = SourceData;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75461: Ignore macro expansions when scanning for fallthrough comments

2020-03-03 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

fallthrough comment detection has been reverted, so abandon this in the 
meantime.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75461



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits