[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
Mon Feb 27 08:39:25 PST 2023
jhuber6 created this revision.
jhuber6 added reviewers: owenpan, MyDeveloperDay, HazardyKnusperkeks, hans.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.
The patch in D136100 <https://reviews.llvm.org/D136100> added custom handling for pragmas to assist in
formatting OpenMP clauses correctly. One of these changes added extra
indentation. This is desirable for OpenMP pragmas as they are several
complete tokens that would otherwise we on the exact same line. However,
this is not desired for the other pragmas.
This solution is extremely hacky, I'm not overly familiar with the
`clang-format` codebase. A better solution would probably require
actually parsing these as tokens, but I just wanted to propose a
solution.
Fixes https://github.com/llvm/llvm-project/issues/59473
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D144884
Files:
clang/lib/Format/ContinuationIndenter.cpp
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.500811.patch
Type: text/x-patch
Size: 863 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230227/4b19d040/attachment-0001.bin>
More information about the cfe-commits
mailing list