Skip to content

Commit cceedc9

Browse files
authored
[clang-format] Fix a crash with AlignArrayOfStructures option (llvm#86420)
Fixes llvm#86109.
1 parent 67f2267 commit cceedc9

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,7 @@ WhitespaceManager::CellDescriptions WhitespaceManager::getCells(unsigned Start,
14911491
: Cell);
14921492
// Go to the next non-comment and ensure there is a break in front
14931493
const auto *NextNonComment = C.Tok->getNextNonComment();
1494-
while (NextNonComment->is(tok::comma))
1494+
while (NextNonComment && NextNonComment->is(tok::comma))
14951495
NextNonComment = NextNonComment->getNextNonComment();
14961496
auto j = i;
14971497
while (j < End && Changes[j].Tok != NextNonComment)

clang/unittests/Format/FormatTest.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21100,7 +21100,14 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) {
2110021100
" [0] = {1, 1},\n"
2110121101
" [1] { 1, 1, },\n"
2110221102
" [2] { 1, 1, },\n"
21103-
"};");
21103+
"};",
21104+
Style);
21105+
verifyNoCrash("test arr[] = {\n"
21106+
"#define FOO(i) {i, i},\n"
21107+
"SOME_GENERATOR(FOO)\n"
21108+
"{2, 2}\n"
21109+
"};",
21110+
Style);
2110421111

2110521112
verifyFormat("return GradForUnaryCwise(g, {\n"
2110621113
" {{\"sign\"}, \"Sign\", "
@@ -21353,7 +21360,14 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) {
2135321360
" [0] = {1, 1},\n"
2135421361
" [1] { 1, 1, },\n"
2135521362
" [2] { 1, 1, },\n"
21356-
"};");
21363+
"};",
21364+
Style);
21365+
verifyNoCrash("test arr[] = {\n"
21366+
"#define FOO(i) {i, i},\n"
21367+
"SOME_GENERATOR(FOO)\n"
21368+
"{2, 2}\n"
21369+
"};",
21370+
Style);
2135721371

2135821372
verifyFormat("return GradForUnaryCwise(g, {\n"
2135921373
" {{\"sign\"}, \"Sign\", {\"x\", "

0 commit comments

Comments
 (0)