[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
This commit is contained in:
Timm Bäder 2023-06-09 14:01:07 +02:00
parent 8a257aebeb
commit b1aba4a100
3 changed files with 5 additions and 1 deletions

View File

@ -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
-------------------------

View File

@ -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(

View File

@ -5,6 +5,7 @@
// CHECK: warning: unused label 'ddd'
// CHECK-NEXT: {{^ ddd:}}
// CHECK-NEXT: {{^ \^~~~$}}
// CHECK-NOT: {{^ ;}}
void f(void) {
ddd:
;