[PATCH] D121682: [clang-format] Fix crashes due to missing l_paren
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 15 03:41:07 PDT 2022
owenpan created this revision.
owenpan added reviewers: HazardyKnusperkeks, curdeius, MyDeveloperDay.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Fixes https://github.com/llvm/llvm-project/issues/54384.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D121682
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12089,6 +12089,7 @@
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;");
}
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1023,6 +1023,8 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121682.415374.patch
Type: text/x-patch
Size: 1040 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220315/62ff91c0/attachment.bin>
More information about the cfe-commits
mailing list