[clang] 492cb7b - [clang-format] Fix a crash in qualifier alignment

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 1 17:31:10 PDT 2022


Author: Owen Pan
Date: 2022-04-01T17:30:59-07:00
New Revision: 492cb7bf91648058f3fc9ca37f9383786f7ce718

URL: https://github.com/llvm/llvm-project/commit/492cb7bf91648058f3fc9ca37f9383786f7ce718
DIFF: https://github.com/llvm/llvm-project/commit/492cb7bf91648058f3fc9ca37f9383786f7ce718.diff

LOG: [clang-format] Fix a crash in qualifier alignment

Related to #54513.

Added: 
    

Modified: 
    clang/lib/Format/QualifierAlignmentFixer.cpp
    clang/unittests/Format/QualifierFixerTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp
index fc37f18c790a4..c0b3345404dec 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -303,6 +303,8 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft(
 
   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,

diff  --git a/clang/unittests/Format/QualifierFixerTest.cpp b/clang/unittests/Format/QualifierFixerTest.cpp
index cd796f48cb568..fc7e932af4402 100755
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -816,6 +816,7 @@ TEST_F(QualifierFixerTest, NoOpQualifierReplacements) {
   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);
 }
 


        


More information about the cfe-commits mailing list