diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index d2f309f3874ed1..6b33ab0a766501 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -1273,8 +1273,13 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { return ContinuationIndent; } - if (State.Line->InPragmaDirective) - return CurrentState.Indent + Style.ContinuationIndentWidth; + // OpenMP clauses want to get additional indentation when they are pushed onto + // the next line. + if (State.Line->InPragmaDirective) { + FormatToken *PragmaType = State.Line->First->Next->Next; + if (PragmaType && PragmaType->TokenText.equals("omp")) + return CurrentState.Indent + Style.ContinuationIndentWidth; + } // This ensure that we correctly format ObjC methods calls without inputs, // i.e. where the last element isn't selector like: [callee method]; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 437e7b62a15d10..1180d3dbbdbc35 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -20560,6 +20560,21 @@ TEST_F(FormatTest, UnderstandsPragmas) { "(including parentheses).", format("#pragma mark Any non-hyphenated or hyphenated string " "(including parentheses).")); + + EXPECT_EQ("#pragma mark Any non-hyphenated or hyphenated string " + "(including parentheses).", + format("#pragma mark Any non-hyphenated or hyphenated string " + "(including parentheses).")); + + EXPECT_EQ( + "#pragma comment(linker, \\\n" + " \"argument\" \\\n" + " \"argument\"", + format("#pragma comment(linker, \\\n" + " \"argument\" \\\n" + " \"argument\"", + getStyleWithColumns( + getChromiumStyle(FormatStyle::LanguageKind::LK_Cpp), 32))); } TEST_F(FormatTest, UnderstandsPragmaOmpTarget) {