clang-format: Fix segfault in 'incomplete' macros.

The code leading to a segfault was:
  #pragma omp threadprivate(y)), // long comment leading to a line break

This fixes llvm.org/PR16513.

llvm-svn: 189460
This commit is contained in:
Daniel Jasper 2013-08-28 09:17:37 +00:00
parent a49393f54d
commit 96df37a6a1
2 changed files with 7 additions and 3 deletions

View File

@ -536,9 +536,10 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
// If we encounter a closing ), ], } or >, we can remove a level from our // If we encounter a closing ), ], } or >, we can remove a level from our
// stacks. // stacks.
if (Current.isOneOf(tok::r_paren, tok::r_square) || if (State.Stack.size() > 1 &&
(Current.is(tok::r_brace) && State.NextToken != Line.First) || (Current.isOneOf(tok::r_paren, tok::r_square) ||
State.NextToken->Type == TT_TemplateCloser) { (Current.is(tok::r_brace) && State.NextToken != Line.First) ||
State.NextToken->Type == TT_TemplateCloser)) {
State.Stack.pop_back(); State.Stack.pop_back();
--State.ParenLevel; --State.ParenLevel;
} }

View File

@ -1942,6 +1942,9 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) {
verifyFormat("#define A template <typename T>"); verifyFormat("#define A template <typename T>");
verifyFormat("#define STR(x) #x\n" verifyFormat("#define STR(x) #x\n"
"f(STR(this_is_a_string_literal{));"); "f(STR(this_is_a_string_literal{));");
verifyFormat("#pragma omp threadprivate( \\\n"
" y)), // expected-warning",
getLLVMStyleWithColumns(28));
} }
TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) { TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {