diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -1273,8 +1273,13 @@ 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 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -20560,6 +20560,21 @@ "(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) {