Skip to content

Commit

Permalink
[clang-format] Fix crash in TokenAnnotator #82349
Browse files Browse the repository at this point in the history
Squash commit from llvm/llvm-project#82349

Change-Id: Ie2a8d501486f2132e5ab9db57159a01f1b631fec
  • Loading branch information
cristianadam committed Mar 6, 2024
1 parent e03addd commit 1fcb238
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3513,7 +3513,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
do {
Tok = Tok->Next;
} while (Tok && Tok->isNot(TT_OverloadedOperatorLParen));
if (!Tok)
if (!Tok || !Tok->MatchingParen)
break;
const auto *LeftParen = Tok;
for (Tok = Tok->Next; Tok && Tok != LeftParen->MatchingParen;
Expand Down
6 changes: 6 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13396,6 +13396,12 @@ TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
verifyFormat("{");
verifyFormat("#})");
verifyNoCrash("(/**/[:!] ?[).");
verifyNoCrash("struct X {\n"
" operator iunt(\n"
"};");
verifyNoCrash("struct Foo {\n"
" operator foo(bar\n"
"};");
}

TEST_F(FormatTest, IncorrectUnbalancedBracesInMacrosWithUnicode) {
Expand Down

0 comments on commit 1fcb238

Please sign in to comment.