From 7143a21706d951ad53b5167a4dcd750f5997d208 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 28 Aug 2013 09:17:37 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189460 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 7 ++++--- unittests/Format/FormatTest.cpp | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 199fc02204..798e4f3aec 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -536,9 +536,10 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, // If we encounter a closing ), ], } or >, we can remove a level from our // stacks. - if (Current.isOneOf(tok::r_paren, tok::r_square) || - (Current.is(tok::r_brace) && State.NextToken != Line.First) || - State.NextToken->Type == TT_TemplateCloser) { + if (State.Stack.size() > 1 && + (Current.isOneOf(tok::r_paren, tok::r_square) || + (Current.is(tok::r_brace) && State.NextToken != Line.First) || + State.NextToken->Type == TT_TemplateCloser)) { State.Stack.pop_back(); --State.ParenLevel; } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index d80011ba17..067a259b2c 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1942,6 +1942,9 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) { verifyFormat("#define A template "); verifyFormat("#define STR(x) #x\n" "f(STR(this_is_a_string_literal{));"); + verifyFormat("#pragma omp threadprivate( \\\n" + " y)), // expected-warning", + getLLVMStyleWithColumns(28)); } TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) { -- 2.40.0