-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang-format] Fix a crash with AlignArrayOfStructures option #86420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) ChangesFixes #86109. Full diff: https://github.com/llvm/llvm-project/pull/86420.diff 2 Files Affected:
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index fef85abf79a38c..710bf8d8a8ec70 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1491,7 +1491,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 (j < End && Changes[j].Tok != NextNonComment)
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index cf8d6ab691d9a0..a33520d81b8421 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21101,6 +21101,11 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) {
" [1] { 1, 1, },\n"
" [2] { 1, 1, },\n"
"};");
+ verifyNoCrash("test arr[] = {\n"
+ "#define FOO(i) {i, i},\n"
+ "SOME_GENERATOR(FOO)\n"
+ "{2, 2}\n"
+ "};");
verifyFormat("return GradForUnaryCwise(g, {\n"
" {{\"sign\"}, \"Sign\", "
@@ -21354,6 +21359,11 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) {
" [1] { 1, 1, },\n"
" [2] { 1, 1, },\n"
"};");
+ verifyNoCrash("test arr[] = {\n"
+ "#define FOO(i) {i, i},\n"
+ "SOME_GENERATOR(FOO)\n"
+ "{2, 2}\n"
+ "};");
verifyFormat("return GradForUnaryCwise(g, {\n"
" {{\"sign\"}, \"Sign\", {\"x\", "
|
✅ With the latest revision this PR passed the Python code formatter. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
HazardyKnusperkeks
approved these changes
Mar 24, 2024
/cherry-pick cceedc9 |
llvmbot
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
May 4, 2024
…6420) Fixes llvm#86109. (cherry picked from commit cceedc9)
/pull-request #91049 |
tstellar
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
May 14, 2024
…6420) Fixes llvm#86109. (cherry picked from commit cceedc9)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #86109.