[PATCH] D144884: [clang-format] Only add pragma continuation indentation for 'omp' clauses
Joseph Huber via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 28 13:16:08 PST 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG466b4327f8fc: [clang-format] Only add pragma continuation indentation for 'omp' clauses (authored by jhuber6).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144884/new/
https://reviews.llvm.org/D144884
Files:
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ 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) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ 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];
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144884.501275.patch
Type: text/x-patch
Size: 1955 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230228/be36242b/attachment.bin>
More information about the cfe-commits
mailing list