[llvm-branch-commits] [clang] f1491c7 - [clang-format] Fix a crash with AlignArrayOfStructures option (#86420)
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon May 13 17:56:11 PDT 2024
Author: Owen Pan
Date: 2024-05-13T17:55:32-07:00
New Revision: f1491c7460e788f15d3fc2ad2a6bcf86606272ec
URL: https://github.com/llvm/llvm-project/commit/f1491c7460e788f15d3fc2ad2a6bcf86606272ec
DIFF: https://github.com/llvm/llvm-project/commit/f1491c7460e788f15d3fc2ad2a6bcf86606272ec.diff
LOG: [clang-format] Fix a crash with AlignArrayOfStructures option (#86420)
Fixes #86109.
(cherry picked from commit cceedc939a43c7c732a5888364251775bffc2dba)
Added:
Modified:
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index df84f97a8e8ac..7525e6ee650b6 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1466,7 +1466,7 @@ WhitespaceManager::CellDescriptions WhitespaceManager::getCells(unsigned Start,
: Cell);
// Go to the next non-comment and ensure there is a break in front
const auto *NextNonComment = C.Tok->getNextNonComment();
- while (NextNonComment->is(tok::comma))
+ while (NextNonComment && NextNonComment->is(tok::comma))
NextNonComment = NextNonComment->getNextNonComment();
auto j = i;
while (Changes[j].Tok != NextNonComment && j < End)
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 923128672c316..0161a1685eb12 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20955,7 +20955,14 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) {
" [0] = {1, 1},\n"
" [1] { 1, 1, },\n"
" [2] { 1, 1, },\n"
- "};");
+ "};",
+ Style);
+ verifyNoCrash("test arr[] = {\n"
+ "#define FOO(i) {i, i},\n"
+ "SOME_GENERATOR(FOO)\n"
+ "{2, 2}\n"
+ "};",
+ Style);
verifyFormat("return GradForUnaryCwise(g, {\n"
" {{\"sign\"}, \"Sign\", "
@@ -21208,7 +21215,14 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) {
" [0] = {1, 1},\n"
" [1] { 1, 1, },\n"
" [2] { 1, 1, },\n"
- "};");
+ "};",
+ Style);
+ verifyNoCrash("test arr[] = {\n"
+ "#define FOO(i) {i, i},\n"
+ "SOME_GENERATOR(FOO)\n"
+ "{2, 2}\n"
+ "};",
+ Style);
verifyFormat("return GradForUnaryCwise(g, {\n"
" {{\"sign\"}, \"Sign\", {\"x\", "
More information about the llvm-branch-commits
mailing list