Skip to content

Commit

Permalink
[clang-format] Fix a TableGen crash on comment after l_paren (llvm#12…
Browse files Browse the repository at this point in the history
  • Loading branch information
owenca authored Jan 26, 2025
1 parent c1f10ef commit c1ec5be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 4 additions & 6 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ class AnnotatingParser {
}
if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
return false;
skipToNextNonComment();
next();
// FIXME: Hack using inheritance to child context
Contexts.back().IsTableGenBangOpe = true;
bool Result = parseParens();
Expand All @@ -1124,12 +1124,10 @@ class AnnotatingParser {
}
// SimpleValue 9: Cond operator
if (Tok->is(TT_TableGenCondOperator)) {
Tok = CurrentToken;
skipToNextNonComment();
if (!Tok || Tok->isNot(tok::l_paren))
if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
return false;
bool Result = parseParens();
return Result;
next();
return parseParens();
}
// We have to check identifier at the last because the kind of bang/cond
// operators are also identifier.
Expand Down
3 changes: 3 additions & 0 deletions clang/unittests/Format/FormatTestTableGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ TEST_F(FormatTestTableGen, BangOperators) {
" \"zerozero\",\n"
" true: // default\n"
" \"positivepositive\");\n"
" let CondOpe3WithCommentAfterLParen = !cond(\n"
" // comment\n"
" !eq(/* comment */ x, 0): \"zero\");\n"
"}");
}

Expand Down

0 comments on commit c1ec5be

Please sign in to comment.