Skip to content

Commit c1ec5be

Browse files
authored
[clang-format] Fix a TableGen crash on comment after l_paren (#124380)
Fixes #124248.
1 parent c1f10ef commit c1ec5be

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

clang/lib/Format/TokenAnnotator.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ class AnnotatingParser {
11151115
}
11161116
if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
11171117
return false;
1118-
skipToNextNonComment();
1118+
next();
11191119
// FIXME: Hack using inheritance to child context
11201120
Contexts.back().IsTableGenBangOpe = true;
11211121
bool Result = parseParens();
@@ -1124,12 +1124,10 @@ class AnnotatingParser {
11241124
}
11251125
// SimpleValue 9: Cond operator
11261126
if (Tok->is(TT_TableGenCondOperator)) {
1127-
Tok = CurrentToken;
1128-
skipToNextNonComment();
1129-
if (!Tok || Tok->isNot(tok::l_paren))
1127+
if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
11301128
return false;
1131-
bool Result = parseParens();
1132-
return Result;
1129+
next();
1130+
return parseParens();
11331131
}
11341132
// We have to check identifier at the last because the kind of bang/cond
11351133
// operators are also identifier.

clang/unittests/Format/FormatTestTableGen.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ TEST_F(FormatTestTableGen, BangOperators) {
101101
" \"zerozero\",\n"
102102
" true: // default\n"
103103
" \"positivepositive\");\n"
104+
" let CondOpe3WithCommentAfterLParen = !cond(\n"
105+
" // comment\n"
106+
" !eq(/* comment */ x, 0): \"zero\");\n"
104107
"}");
105108
}
106109

0 commit comments

Comments
 (0)