[PATCH] D121682: [clang-format] Fix crashes due to missing l_paren
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 16 01:45:50 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7fb2d9f9b5ef: [clang-format] Fix crashes due to missing l_paren (authored by owenpan).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D121682/new/
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
@@ -12113,6 +12113,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.415732.patch
Type: text/x-patch
Size: 1040 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220316/1243b049/attachment.bin>
More information about the cfe-commits
mailing list