tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, cjdb.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  Now that we print >1 line of code snippet, we printed another line of
  code for now reason, because the source range we created for the fixit
  expanded to the next line, if the next token was there. Don't do that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152525

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/FixIt/fixit-newline-style.c


Index: clang/test/FixIt/fixit-newline-style.c
===================================================================
--- clang/test/FixIt/fixit-newline-style.c
+++ clang/test/FixIt/fixit-newline-style.c
@@ -5,6 +5,7 @@
 // CHECK: warning: unused label 'ddd'
 // CHECK-NEXT: {{^  ddd:}}
 // CHECK-NEXT: {{^  \^~~~$}}
+// CHECK-NOT: {{^  ;}}
 void f(void) {
   ddd:
   ;
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -2096,7 +2096,7 @@
   if (isa<LabelDecl>(D)) {
     SourceLocation AfterColon = Lexer::findLocationAfterToken(
         D->getEndLoc(), tok::colon, Ctx.getSourceManager(), Ctx.getLangOpts(),
-        true);
+        /*SkipTrailingWhitespaceAndNewline=*/false);
     if (AfterColon.isInvalid())
       return;
     Hint = FixItHint::CreateRemoval(


Index: clang/test/FixIt/fixit-newline-style.c
===================================================================
--- clang/test/FixIt/fixit-newline-style.c
+++ clang/test/FixIt/fixit-newline-style.c
@@ -5,6 +5,7 @@
 // CHECK: warning: unused label 'ddd'
 // CHECK-NEXT: {{^  ddd:}}
 // CHECK-NEXT: {{^  \^~~~$}}
+// CHECK-NOT: {{^  ;}}
 void f(void) {
   ddd:
   ;
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -2096,7 +2096,7 @@
   if (isa<LabelDecl>(D)) {
     SourceLocation AfterColon = Lexer::findLocationAfterToken(
         D->getEndLoc(), tok::colon, Ctx.getSourceManager(), Ctx.getLangOpts(),
-        true);
+        /*SkipTrailingWhitespaceAndNewline=*/false);
     if (AfterColon.isInvalid())
       return;
     Hint = FixItHint::CreateRemoval(
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to