[llvm-branch-commits] [clang] 2d079b9 - release/20.x: [clang-format] Fix a crash on formatting missing r_paren/r_brace (#138230)
    Tom Stellard via llvm-branch-commits 
    llvm-branch-commits at lists.llvm.org
       
    Tue May 13 14:30:14 PDT 2025
    
    
  
Author: Owen Pan
Date: 2025-05-13T14:28:28-07:00
New Revision: 2d079b96a5fb2d1da62cfddbafa6632058b22e76
URL: https://github.com/llvm/llvm-project/commit/2d079b96a5fb2d1da62cfddbafa6632058b22e76
DIFF: https://github.com/llvm/llvm-project/commit/2d079b96a5fb2d1da62cfddbafa6632058b22e76.diff
LOG: release/20.x: [clang-format] Fix a crash on formatting missing r_paren/r_brace (#138230)
Backport 79210feb2993ff9a79ef11f8a7016a527d4fcf22
Added: 
    
Modified: 
    clang/lib/Format/UnwrappedLineParser.cpp
    clang/unittests/Format/FormatTest.cpp
Removed: 
    
################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index c3ffabce15ec8..673b3e6c4b8c2 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1837,8 +1837,8 @@ void UnwrappedLineParser::parseStructuralElement(
       nextToken();
       if (FormatTok->is(tok::l_paren)) {
         parseParens();
-        assert(FormatTok->Previous);
-        if (FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
+        if (FormatTok->Previous &&
+            FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
                                               tok::l_paren)) {
           Line->SeenDecltypeAuto = true;
         }
diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 49e1fde1d9ccf..90a79230e9f4c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -13962,6 +13962,8 @@ TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
   verifyNoCrash("struct Foo {\n"
                 "  operator foo(bar\n"
                 "};");
+  verifyNoCrash("decltype( {\n"
+                "  {");
 }
 
 TEST_F(FormatTest, IncorrectUnbalancedBracesInMacrosWithUnicode) {
        
    
    
More information about the llvm-branch-commits
mailing list