[PATCH] D92753: [clang-format] Add IndentPragma style to eliminate common clang-format off scenario

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 7 03:34:13 PST 2020


MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: curdeius, JakeMerdichAMD, krasimir.
MyDeveloperDay added projects: clang-format, clang.
MyDeveloperDay requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

A quick search of github.com, shows one common scenario for excessive use of //clang-format off/on is the indentation of #pragma's, especially around the areas of loop optimization or OpenMP

This revision aims to help that by introducing an `IndentPragmas` style, the aim of which is to keep the pragma at the current level of scope

      for (int i = 0; i < 5; i++) {
  // clang-format off
          #pragma HLS UNROLL
          // clang-format on
          for (int j = 0; j < 5; j++) {
  // clang-format off
              #pragma HLS UNROLL
              // clang-format on
       ....

can become

  for (int i = 0; i < 5; i++) {
      #pragma HLS UNROLL
      for (int j = 0; j < 5; j++) {
          #pragma HLS UNROLL
      ....

This revision also support working alongside the `IndentPPDirective` of `BeforeHash` and `AfterHash` (see unit tests for examples)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92753

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92753.309859.patch
Type: text/x-patch
Size: 13621 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201207/ca92114b/attachment-0001.bin>


More information about the cfe-commits mailing list