[llvm-branch-commits] [clang] release/20.x: [clang-format] Fix a crash on formatting missing r_pare… (PR #139345)
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue May 13 14:30:08 PDT 2025
https://github.com/tstellar updated https://github.com/llvm/llvm-project/pull/139345
>From 2d079b96a5fb2d1da62cfddbafa6632058b22e76 Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Fri, 9 May 2025 17:55:48 -0700
Subject: [PATCH] release/20.x: [clang-format] Fix a crash on formatting
missing r_paren/r_brace (#138230)
Backport 79210feb2993ff9a79ef11f8a7016a527d4fcf22
---
clang/lib/Format/UnwrappedLineParser.cpp | 4 ++--
clang/unittests/Format/FormatTest.cpp | 2 ++
2 files changed, 4 insertions(+), 2 deletions(-)
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