[clang] [clang-format] Fix a crash on fuzzer-generated invalid C++ code (PR #186566)

via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 13 23:56:37 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format

Author: owenca (owenca)

<details>
<summary>Changes</summary>

Fixes #<!-- -->185421

---
Full diff: https://github.com/llvm/llvm-project/pull/186566.diff


2 Files Affected:

- (modified) clang/lib/Format/ContinuationIndenter.cpp (+2-1) 
- (modified) clang/unittests/Format/FormatTest.cpp (+8) 


``````````diff
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 1eb17592a89e6..a388b74920e0b 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -710,7 +710,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
         return false;
       if (Tok->is(TT_TemplateCloser)) {
         Tok = Tok->MatchingParen;
-        assert(Tok);
+        if (!Tok)
+          return false;
       }
       if (Tok->FirstAfterPPLine)
         return false;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 33af71de398be..df351489262f4 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -29243,6 +29243,14 @@ TEST_F(FormatTest, UnbalancedAngleBrackets) {
 
   verifyNoCrash("typename foo<bar>::value, const String &>::type f();",
                 getLLVMStyleWithColumns(50));
+
+  verifyNoCrash(
+      ">\n"
+      " f({\n"
+      "   {}inner> () __attribute __attribute__((foo())) int foo(void)\n"
+      "   {};\n"
+      "   }, );",
+      getLLVMStyleWithColumns(70));
 }
 
 } // namespace

``````````

</details>


https://github.com/llvm/llvm-project/pull/186566


More information about the cfe-commits mailing list