[PATCH] D122756: [clang-format] Fix a crash in qualifier alignment
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 30 12:05:45 PDT 2022
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, curdeius, HazardyKnusperkeks.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Related to #54513 <https://github.com/llvm/llvm-project/issues/54513>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D122756
Files:
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/unittests/Format/QualifierFixerTest.cpp
Index: clang/unittests/Format/QualifierFixerTest.cpp
===================================================================
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -816,6 +816,7 @@
EXPECT_EQ(ReplacementCount, 0);
verifyFormat("static const uint32 foo[] = {0, 31};", Style);
verifyFormat("#define MACRO static const", Style);
+ verifyFormat("using sc = static const", Style);
EXPECT_EQ(ReplacementCount, 0);
}
Index: clang/lib/Format/QualifierAlignmentFixer.cpp
===================================================================
--- clang/lib/Format/QualifierAlignmentFixer.cpp
+++ clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -303,6 +303,8 @@
if (LastQual && Qual != LastQual && Qual->is(QualifierType)) {
rotateTokens(SourceMgr, Fixes, Tok, Qual, /*Left=*/true);
+ if (!Qual->Next)
+ return Tok;
Tok = Qual->Next;
} else if (Tok->startsSequence(tok::identifier, QualifierType)) {
if (Tok->Next->Next && Tok->Next->Next->isOneOf(tok::identifier, tok::star,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122756.419237.patch
Type: text/x-patch
Size: 1068 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220330/58ab4efe/attachment.bin>
More information about the cfe-commits
mailing list