Skip to content

Commit

Permalink
[clang][Diagnostics] Don't expand label fixit to the next line
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tbaederr committed Jun 15, 2023
1 parent 8a257ae commit b1aba4a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions clang/test/FixIt/fixit-newline-style.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// CHECK: warning: unused label 'ddd'
// CHECK-NEXT: {{^ ddd:}}
// CHECK-NEXT: {{^ \^~~~$}}
// CHECK-NOT: {{^ ;}}
void f(void) {
ddd:
;
Expand Down

0 comments on commit b1aba4a

Please sign in to comment.