summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-01-19 10:52:16 +0000
committerDaniel Jasper <djasper@google.com>2015-01-19 10:52:16 +0000
commit193cdd381b77647a5a96b52b47b47cae454b29c5 (patch)
treef92656bb3a215a7265bdf63a2de341a712c2bf8e
parent20e8c3be3ca1b24ddac51e4cfd67eba1cb551210 (diff)
downloadbcm5719-llvm-193cdd381b77647a5a96b52b47b47cae454b29c5.tar.gz
bcm5719-llvm-193cdd381b77647a5a96b52b47b47cae454b29c5.zip
clang-format: Fix crasher on incomplete condition compilation.
Previously crashing input: void f( #if A ); #else #endif llvm-svn: 226451
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp2
-rw-r--r--clang/unittests/Format/FormatTest.cpp6
2 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 4ba3f919697..58902bfbd69 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1361,7 +1361,7 @@ static bool isFunctionDeclarationName(const FormatToken &Current) {
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))
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 548273ade03..f267c94b6d3 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2930,6 +2930,12 @@ TEST_F(FormatTest, LayoutStatementsAroundPreprocessorDirectives) {
"#if a\n"
"#else\n"
"#endif");
+
+ verifyFormat("void f(\n"
+ "#if A\n"
+ " );\n"
+ "#else\n"
+ "#endif");
}
TEST_F(FormatTest, GraciouslyHandleIncorrectPreprocessorConditions) {
OpenPOWER on IntegriCloud