[clang] b1aba4a - [clang][Diagnostics] Don't expand label fixit to the next line

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 15 06:58:49 PDT 2023


Author: Timm Bäder
Date: 2023-06-15T15:58:23+02:00
New Revision: b1aba4a1009937aca920539f7737b1973f908dbd

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

LOG: [clang][Diagnostics] Don't expand label fixit to the next line

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.

Differential Revision: https://reviews.llvm.org/D152525

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaDecl.cpp
    clang/test/FixIt/fixit-newline-style.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 451835f8bb39a..336bd5b6aa2e1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -350,6 +350,9 @@ Improvements to Clang's diagnostics
 - Clang no longer diagnoses a read of an empty structure as use of an
   uninitialized variable.
   (`#26842: <https://github.com/llvm/llvm-project/issues/26842>`_)
+- The Fix-It emitted for unused labels used to expand to the next line, which caused
+  visual oddities now that Clang shows more than one line of code snippet. This has
+  been fixed and the Fix-It now only spans to the end of the ``:``.
 
 Bug Fixes in This Version
 -------------------------

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b1436ba50892a..757c4c310be3d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2096,7 +2096,7 @@ static void GenerateFixForUnusedDecl(const NamedDecl *D, ASTContext &Ctx,
   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(

diff  --git a/clang/test/FixIt/fixit-newline-style.c b/clang/test/FixIt/fixit-newline-style.c
index 091b79426bcdf..06cb262691ea0 100644
--- a/clang/test/FixIt/fixit-newline-style.c
+++ b/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:
   ;


        


More information about the cfe-commits mailing list