r226451 - clang-format: Fix crasher on incomplete condition compilation.
Daniel Jasper
djasper at google.com
Mon Jan 19 02:52:17 PST 2015
Author: djasper
Date: Mon Jan 19 04:52:16 2015
New Revision: 226451
URL: http://llvm.org/viewvc/llvm-project?rev=226451&view=rev
Log:
clang-format: Fix crasher on incomplete condition compilation.
Previously crashing input:
void f(
#if A
);
#else
#endif
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=226451&r1=226450&r2=226451&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jan 19 04:52:16 2015
@@ -1361,7 +1361,7 @@ static bool isFunctionDeclarationName(co
assert(Next->is(tok::l_paren));
if (Next->Next == Next->MatchingParen)
return true;
- for (const FormatToken *Tok = Next->Next; Tok != Next->MatchingParen;
+ for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {
if (Tok->is(tok::kw_const) || Tok->isSimpleTypeSpecifier() ||
Tok->isOneOf(TT_PointerOrReference, TT_StartOfName))
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=226451&r1=226450&r2=226451&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 19 04:52:16 2015
@@ -2930,6 +2930,12 @@ TEST_F(FormatTest, LayoutStatementsAroun
"#if a\n"
"#else\n"
"#endif");
+
+ verifyFormat("void f(\n"
+ "#if A\n"
+ " );\n"
+ "#else\n"
+ "#endif");
}
TEST_F(FormatTest, GraciouslyHandleIncorrectPreprocessorConditions) {
More information about the cfe-commits
mailing list