Author: Owen Pan Date: 2022-03-16T01:45:20-07:00 New Revision: 7fb2d9f9b5efaf15c10711826b496ee65f70491d
URL: https://github.com/llvm/llvm-project/commit/7fb2d9f9b5efaf15c10711826b496ee65f70491d DIFF: https://github.com/llvm/llvm-project/commit/7fb2d9f9b5efaf15c10711826b496ee65f70491d.diff LOG: [clang-format] Fix crashes due to missing l_paren Fixes #54384. Differential Revision: https://reviews.llvm.org/D121682 Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 848f69afca7c3..f1ff1995c806d 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1023,6 +1023,8 @@ class AnnotatingParser { if (Style.isCpp() && CurrentToken && CurrentToken->is(tok::kw_co_await)) next(); Contexts.back().ColonIsForRangeExpr = true; + if (!CurrentToken || CurrentToken->isNot(tok::l_paren)) + return false; next(); if (!parseParens()) return false; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 459cbf1c7681c..926bf8905c7a6 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -12113,6 +12113,7 @@ TEST_F(FormatTest, IncorrectCodeMissingParens) { verifyFormat("if {\n foo;\n foo();\n}"); verifyFormat("switch {\n foo;\n foo();\n}"); verifyIncompleteFormat("for {\n foo;\n foo();\n}"); + verifyIncompleteFormat("ERROR: for target;"); verifyFormat("while {\n foo;\n foo();\n}"); verifyFormat("do {\n foo;\n foo();\n} while;"); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits