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];
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];
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits