Skip to content

[clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). #96804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 12, 2024

Conversation

ichaer
Copy link
Contributor

@ichaer ichaer commented Jun 26, 2024

  • Convert ReflowComments from boolean into a new enum which can take on the value RCS_Never, RCS_IndentOnly, or RCS_Always. The first one is equivalent to the old false, the third one is true, and the middle one means that multiline comments should only have their indentation corrected, which is what Doxygen users will want.
  • Preserve backward compatibility while parsing ReflowComments.

…mments without breaking internal structure (think Doxygen).

* Convert `ReflowComments` from boolean into a new `enum` which can take on the value `RCS_Never`, `RCS_IndentOnly`, or `RCS_Always`. The first one is equivalent to the old `false`, the third one is `true`, and the middle one means that multiline comments should only have their indentation corrected, which is what Doxygen users will want.
* Preserve backward compatibility while parsing `ReflowComments`.
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jun 26, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-format

Author: Iuri Chaer (ichaer)

Changes
  • Convert ReflowComments from boolean into a new enum which can take on the value RCS_Never, RCS_IndentOnly, or RCS_Always. The first one is equivalent to the old false, the third one is true, and the middle one means that multiline comments should only have their indentation corrected, which is what Doxygen users will want.
  • Preserve backward compatibility while parsing ReflowComments.

Full diff: https://github.com/llvm/llvm-project/pull/96804.diff

8 Files Affected:

  • (modified) clang/include/clang/Format/Format.h (+14-3)
  • (modified) clang/lib/Format/BreakableToken.cpp (+10-4)
  • (modified) clang/lib/Format/ContinuationIndenter.cpp (+2-2)
  • (modified) clang/lib/Format/Format.cpp (+11-1)
  • (modified) clang/lib/Format/UnwrappedLineParser.cpp (+9-9)
  • (modified) clang/unittests/Format/ConfigParseTest.cpp (+10-1)
  • (modified) clang/unittests/Format/FormatTest.cpp (+3-3)
  • (modified) clang/unittests/Format/FormatTestComments.cpp (+19-3)
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 7d257be10af42..971e9347df127 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3749,23 +3749,34 @@ struct FormatStyle {
   /// \version 13
   ReferenceAlignmentStyle ReferenceAlignment;
 
+  enum ReflowCommentsStyle : int8_t { RCS_Never, RCS_IndentOnly, RCS_Always };
   // clang-format off
   /// If ``true``, clang-format will attempt to re-flow comments. That is it
   /// will touch a comment and *reflow* long comments into new lines, trying to
   /// obey the ``ColumnLimit``.
   /// \code
-  ///    false:
+  ///    RCS_Never:
   ///    // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
   ///    /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
+  ///    /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
+  ///         * and a misaligned second line */
   ///
-  ///    true:
+  ///    RCS_IndentOnly:
+  ///    // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
+  ///    /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
+  ///    /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
+  ///     * and a misaligned second line */
+  ///
+  ///    RCS_Always:
   ///    // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
   ///    // information
   ///    /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
   ///     * information */
+  ///    /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
+  ///     * information and a misaligned second line */
   /// \endcode
   /// \version 3.8
-  bool ReflowComments;
+  ReflowCommentsStyle ReflowComments;
   // clang-format on
 
   /// Remove optional braces of control statements (``if``, ``else``, ``for``,
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp
index 75304908dc650..0ccc8a690c208 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -420,8 +420,10 @@ BreakableComment::getSplit(unsigned LineIndex, unsigned TailOffset,
                            unsigned ColumnLimit, unsigned ContentStartColumn,
                            const llvm::Regex &CommentPragmasRegex) const {
   // Don't break lines matching the comment pragmas regex.
-  if (CommentPragmasRegex.match(Content[LineIndex]))
+  if (Style.ReflowComments != FormatStyle::RCS_Always ||
+      CommentPragmasRegex.match(Content[LineIndex])) {
     return Split(StringRef::npos, 0);
+  }
   return getCommentSplit(Content[LineIndex].substr(TailOffset),
                          ContentStartColumn, ColumnLimit, Style.TabWidth,
                          Encoding, Style);
@@ -608,8 +610,10 @@ BreakableToken::Split BreakableBlockComment::getSplit(
     unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit,
     unsigned ContentStartColumn, const llvm::Regex &CommentPragmasRegex) const {
   // Don't break lines matching the comment pragmas regex.
-  if (CommentPragmasRegex.match(Content[LineIndex]))
+  if (Style.ReflowComments != FormatStyle::RCS_Always ||
+      CommentPragmasRegex.match(Content[LineIndex])) {
     return Split(StringRef::npos, 0);
+  }
   return getCommentSplit(Content[LineIndex].substr(TailOffset),
                          ContentStartColumn, ColumnLimit, Style.TabWidth,
                          Encoding, Style, Decoration.ends_with("*"));
@@ -855,7 +859,8 @@ bool BreakableBlockComment::mayReflow(
   StringRef IndentContent = Content[LineIndex];
   if (Lines[LineIndex].ltrim(Blanks).starts_with("*"))
     IndentContent = Lines[LineIndex].ltrim(Blanks).substr(1);
-  return LineIndex > 0 && !CommentPragmasRegex.match(IndentContent) &&
+  return LineIndex > 0 && Style.ReflowComments == FormatStyle::RCS_Always &&
+         !CommentPragmasRegex.match(IndentContent) &&
          mayReflowContent(Content[LineIndex]) && !Tok.Finalized &&
          !switchesFormatting(tokenAt(LineIndex));
 }
@@ -1160,7 +1165,8 @@ bool BreakableLineCommentSection::mayReflow(
   // // text that protrudes
   // //    into text with different indent
   // We do reflow in that case in block comments.
-  return LineIndex > 0 && !CommentPragmasRegex.match(IndentContent) &&
+  return LineIndex > 0 && Style.ReflowComments == FormatStyle::RCS_Always &&
+         !CommentPragmasRegex.match(IndentContent) &&
          mayReflowContent(Content[LineIndex]) && !Tok.Finalized &&
          !switchesFormatting(tokenAt(LineIndex)) &&
          OriginalPrefix[LineIndex] == OriginalPrefix[LineIndex - 1];
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index b07360425ca6e..7d592a31bc0eb 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -2400,7 +2400,7 @@ ContinuationIndenter::createBreakableToken(const FormatToken &Current,
           State.Line->InPPDirective, Encoding, Style);
     }
   } else if (Current.is(TT_BlockComment)) {
-    if (!Style.ReflowComments ||
+    if (Style.ReflowComments == FormatStyle::RCS_Never ||
         // If a comment token switches formatting, like
         // /* clang-format on */, we don't want to break it further,
         // but we may still want to adjust its indentation.
@@ -2421,7 +2421,7 @@ ContinuationIndenter::createBreakableToken(const FormatToken &Current,
       }
       return true;
     }();
-    if (!Style.ReflowComments ||
+    if (Style.ReflowComments == FormatStyle::RCS_Never ||
         CommentPragmasRegex.match(Current.TokenText.substr(2)) ||
         switchesFormatting(Current) || !RegularComments) {
       return nullptr;
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index cd21fbb2221ac..ee1f5651b4f98 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -497,6 +497,16 @@ template <> struct MappingTraits<FormatStyle::RawStringFormat> {
   }
 };
 
+template <> struct ScalarEnumerationTraits<FormatStyle::ReflowCommentsStyle> {
+  static void enumeration(IO &IO, FormatStyle::ReflowCommentsStyle &Value) {
+    IO.enumCase(Value, "Never", FormatStyle::RCS_Never);
+    IO.enumCase(Value, "IndentOnly", FormatStyle::RCS_IndentOnly);
+    IO.enumCase(Value, "Always", FormatStyle::RCS_Always);
+    IO.enumCase(Value, "false", FormatStyle::RCS_Never);
+    IO.enumCase(Value, "true", FormatStyle::RCS_Always);
+  }
+};
+
 template <>
 struct ScalarEnumerationTraits<FormatStyle::ReferenceAlignmentStyle> {
   static void enumeration(IO &IO, FormatStyle::ReferenceAlignmentStyle &Value) {
@@ -1534,7 +1544,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
   LLVMStyle.PPIndentWidth = -1;
   LLVMStyle.QualifierAlignment = FormatStyle::QAS_Leave;
   LLVMStyle.ReferenceAlignment = FormatStyle::RAS_Pointer;
-  LLVMStyle.ReflowComments = true;
+  LLVMStyle.ReflowComments = FormatStyle::RCS_Always;
   LLVMStyle.RemoveBracesLLVM = false;
   LLVMStyle.RemoveParentheses = FormatStyle::RPS_Leave;
   LLVMStyle.RemoveSemicolon = false;
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index d406a531a5c0c..0e239c9362027 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4588,11 +4588,11 @@ bool UnwrappedLineParser::isOnNewLine(const FormatToken &FormatTok) {
 
 // Checks if \p FormatTok is a line comment that continues the line comment
 // section on \p Line.
-static bool
-continuesLineCommentSection(const FormatToken &FormatTok,
-                            const UnwrappedLine &Line,
-                            const llvm::Regex &CommentPragmasRegex) {
-  if (Line.Tokens.empty())
+static bool continuesLineCommentSection(
+    const FormatToken &FormatTok, const UnwrappedLine &Line,
+    const FormatStyle::ReflowCommentsStyle ReflowCommentsStyle,
+    const llvm::Regex &CommentPragmasRegex) {
+  if (Line.Tokens.empty() || ReflowCommentsStyle != FormatStyle::RCS_Always)
     return false;
 
   StringRef IndentContent = FormatTok.TokenText;
@@ -4704,8 +4704,8 @@ void UnwrappedLineParser::flushComments(bool NewlineBeforeNext) {
     //
     // FIXME: Consider putting separate line comment sections as children to the
     // unwrapped line instead.
-    Tok->ContinuesLineCommentSection =
-        continuesLineCommentSection(*Tok, *Line, CommentPragmasRegex);
+    Tok->ContinuesLineCommentSection = continuesLineCommentSection(
+        *Tok, *Line, Style.ReflowComments, CommentPragmasRegex);
     if (isOnNewLine(*Tok) && JustComments && !Tok->ContinuesLineCommentSection)
       addUnwrappedLine();
     pushToken(Tok);
@@ -4778,8 +4778,8 @@ void UnwrappedLineParser::distributeComments(
     if (HasTrailAlignedWithNextToken && i == StartOfTrailAlignedWithNextToken) {
       FormatTok->ContinuesLineCommentSection = false;
     } else {
-      FormatTok->ContinuesLineCommentSection =
-          continuesLineCommentSection(*FormatTok, *Line, CommentPragmasRegex);
+      FormatTok->ContinuesLineCommentSection = continuesLineCommentSection(
+          *FormatTok, *Line, Style.ReflowComments, CommentPragmasRegex);
     }
     if (!FormatTok->ContinuesLineCommentSection &&
         (isOnNewLine(*FormatTok) || FormatTok->IsFirst)) {
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index aded3ed2a6596..a8a985f8fa94b 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -183,7 +183,6 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(ObjCSpaceAfterProperty);
   CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
   CHECK_PARSE_BOOL(Cpp11BracedListStyle);
-  CHECK_PARSE_BOOL(ReflowComments);
   CHECK_PARSE_BOOL(RemoveBracesLLVM);
   CHECK_PARSE_BOOL(RemoveSemicolon);
   CHECK_PARSE_BOOL(SkipMacroDefinitionBody);
@@ -372,6 +371,16 @@ TEST(ConfigParseTest, ParsesConfiguration) {
   CHECK_PARSE("PointerBindsToType: Middle", PointerAlignment,
               FormatStyle::PAS_Middle);
 
+  Style.ReflowComments = FormatStyle::RCS_Always;
+  CHECK_PARSE("ReflowComments: Never", ReflowComments, FormatStyle::RCS_Never);
+  CHECK_PARSE("ReflowComments: IndentOnly", ReflowComments,
+              FormatStyle::RCS_IndentOnly);
+  CHECK_PARSE("ReflowComments: Always", ReflowComments,
+              FormatStyle::RCS_Always);
+  // For backward compatibility:
+  CHECK_PARSE("ReflowComments: false", ReflowComments, FormatStyle::RCS_Never);
+  CHECK_PARSE("ReflowComments: true", ReflowComments, FormatStyle::RCS_Always);
+
   Style.Standard = FormatStyle::LS_Auto;
   CHECK_PARSE("Standard: c++03", Standard, FormatStyle::LS_Cpp03);
   CHECK_PARSE("Standard: c++11", Standard, FormatStyle::LS_Cpp11);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index db1decb20d626..80d4958806f19 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -17851,7 +17851,7 @@ TEST_F(FormatTest, AlignConsecutiveMacros) {
 
   // Test across comments
   Style.MaxEmptyLinesToKeep = 10;
-  Style.ReflowComments = false;
+  Style.ReflowComments = FormatStyle::RCS_Never;
   Style.AlignConsecutiveMacros.AcrossComments = true;
   verifyFormat("#define a    3\n"
                "// line comment\n"
@@ -18598,7 +18598,7 @@ TEST_F(FormatTest, AlignConsecutiveAssignmentsAcrossEmptyLinesAndComments) {
                "y = 1;",
                Alignment);
 
-  Alignment.ReflowComments = true;
+  Alignment.ReflowComments = FormatStyle::RCS_Always;
   Alignment.ColumnLimit = 50;
   verifyFormat("int x   = 0;\n"
                "int yy  = 1; /// specificlennospace\n"
@@ -18996,7 +18996,7 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
                "y = 1;",
                Alignment);
 
-  EXPECT_EQ(Alignment.ReflowComments, true);
+  EXPECT_EQ(Alignment.ReflowComments, FormatStyle::RCS_Always);
   Alignment.ColumnLimit = 50;
   verifyFormat("int x   = 0;\n"
                "int yy  = 1; /// specificlennospace\n"
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp
index 3e75707a9faec..a89016758719c 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -493,9 +493,25 @@ TEST_F(FormatTestComments, AlignsBlockComments) {
 
 TEST_F(FormatTestComments, CommentReflowingCanBeTurnedOff) {
   FormatStyle Style = getLLVMStyleWithColumns(20);
-  Style.ReflowComments = false;
-  verifyFormat("// aaaaaaaaa aaaaaaaaaa aaaaaaaaaa", Style);
-  verifyFormat("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa */", Style);
+  Style.ReflowComments = FormatStyle::RCS_Never;
+  verifyNoChange("// aaaaaaaaa aaaaaaaaaa aaaaaaaaaa", Style);
+  verifyNoChange("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa */", Style);
+  verifyNoChange("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\naaaaaaaaa*/", Style);
+  verifyNoChange("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\n    aaaaaaaaa*/", Style);
+  verifyNoChange("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\n *    aaaaaaaaa*/",
+                 Style);
+}
+
+TEST_F(FormatTestComments, CommentReflowingCanApplyOnlyToIndents) {
+  FormatStyle Style = getLLVMStyleWithColumns(20);
+  Style.ReflowComments = FormatStyle::RCS_IndentOnly;
+  verifyNoChange("// aaaaaaaaa aaaaaaaaaa aaaaaaaaaa", Style);
+  verifyNoChange("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa */", Style);
+  verifyNoChange("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\naaaaaaaaa*/", Style);
+  verifyNoChange("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\n    aaaaaaaaa*/", Style);
+  verifyFormat("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\n * aaaaaaaaa*/",
+               "/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\n      * aaaaaaaaa*/",
+               Style);
 }
 
 TEST_F(FormatTestComments, CorrectlyHandlesLengthOfBlockComments) {

Copy link
Contributor

@mydeveloperday mydeveloperday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to regenerate the clang-format-style options rst page using the tool in clang/doc/tools

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jun 27, 2024
@ichaer
Copy link
Contributor Author

ichaer commented Jun 27, 2024

Thanks, @mydeveloperday :). That made me realise I had to fix the comments as well, I think they are OK now. Let me know what you think.

@ichaer
Copy link
Contributor Author

ichaer commented Jul 24, 2024

@mydeveloperday, @HazardyKnusperkeks, do you have any more feedback?

I just noticed I didn't share this information before, but this is functionality Splunk is using internally to ensure clang-format fixes the indentation of our legacy doxygen comments without breaking their internal structure, and we'd like to contribute it upstream as we expect others must have similar problems.

@HazardyKnusperkeks
Copy link
Contributor

Fine by me, let's wait for @mydeveloperday .

@ichaer
Copy link
Contributor Author

ichaer commented Aug 7, 2024

Hi @mydeveloperday, any more feedback?

Copy link
Contributor

@mydeveloperday mydeveloperday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the rst is correct

@mydeveloperday mydeveloperday requested a review from owenca August 7, 2024 17:13
@mydeveloperday
Copy link
Contributor

I trust @owenca and @HazardyKnusperkeks's opinion more than I trust my own.

ichaer added 2 commits August 14, 2024 11:37
…ent-indentonly

* llvm-trunk/main: (5388 commits)
  [SPIR-V] Add implementation of the non-const G_BUILD_VECTOR and fix emission of the OpGroupBroadcast instruction (llvm#103050)
  [RISCV][compiler-rt] Update __init_riscv_feature_bits prototype (llvm#101472)
  [LAA] Also clear DiffChecks in LAI::reset().
  [LV] Add test for diff check creation order.
  [Flang][OpenMP][Lower] Clause lowering cleanup (llvm#103058)
  [DAG] Support saturated truncate (llvm#99418)
  [RISCV] Add scheduling model for Syntacore SCR4 and SCR5  (llvm#102909)
  [clang][Interp] Diagnose pointer subtraction on zero-size arrays (llvm#103015)
  Reland logf128 constant folding (llvm#103217)
  [DataLayout] Split StructAlignment into two fields (NFC) (llvm#103700)
  [Transforms][NFC] Remove second CodeExtractor constructor
  [IR] Cache llvm.module.flags metadata in Module
  [Analysis][NFC] Don't use BitVector for nobuiltin overrides
  [SCEV] Look through multiply in computeConstantDifference() (llvm#103051)
  [LLVM][NewPM] Add a C API for setting the PassBuilder AA pipeline. (llvm#102482)
  [libc++] <experimental/simd> Add ++/-- operators for simd reference (llvm#88091)
  [APInt] Correct backwards static_assert condition. (llvm#103641)
  [MC] Remove Darwin SDK/Version from ObjFileInfo (llvm#103025)
  [NewGVN] Prevent cyclic dependencies by ensuring Leader has min RPO number (llvm#82110)
  AtomicExpand: Add assert that atomicrmw is an xchg
  ...
* and a misaligned second line */

* ``RCS_Always`` (in configuration: ``Always``)
Apply indentation rules and re-flow long comments into new lines, trying
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to rerun dump_format_style.py after updating Format.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man, I remembered it while making the changes and then forgot before committing =(

Have you considered adding that to the build system and perhaps also a CI test? It must be tricky for reviewers, having to remember to check this stuff every time, and the additional review roundtrips... I can propose a separate PR that introduces something like this to clang/docs/CMakeLists.txt:

add_custom_target(clang-format-style-options
    COMMAND "${Python3_EXECUTABLE}" dump_format_style.py
    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tools"
    DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../include/clang/Format/Format.h")
add_dependencies(clang-format clang-format-style-options)

And maybe add the clang-format-style-options target to .github/workflows/docs.yml, with a validation that git status --porcelain clang/docs/ClangFormatStyleOptions.rst returns an empty output. If this is something you think could help reduce the burden on reviewers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be very helpful. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I'd manage some time for opening the new PR before leaving on holiday, but I'm always too optimistic about the number of things I have to wrap up before leaving =(, sorry about this, @owenca. I'm adding it to my calendar to make sure I don't forget, I should be back in late September.

@ichaer
Copy link
Contributor Author

ichaer commented Aug 16, 2024

@mydeveloperday, what do you think, is this good to merge?

@owenca
Copy link
Contributor

owenca commented Aug 23, 2024

@mydeveloperday, what do you think, is this good to merge?

@mydeveloperday can we merge this?

@ichaer
Copy link
Contributor Author

ichaer commented Oct 2, 2024

@mydeveloperday?

@owenca
Copy link
Contributor

owenca commented Oct 10, 2024

@ichaer I forgot to mention that you would need to update docs/ReleaseNotes.rst.

…ent-indentonly

* llvm-trunk/main: (6379 commits)
  [gn build] Port 1c94388
  [RISCV] Introduce VLOptimizer pass (llvm#108640)
  [mlir][vector] Add more tests for ConvertVectorToLLVM (7/n) (llvm#111895)
  [libc++] Add output groups to run-buildbot (llvm#111739)
  [libc++abi] Remove unused LIBCXXABI_LIBCXX_INCLUDES CMake option (llvm#111824)
  [clang] Ignore inline namespace for `hasName` (llvm#109147)
  [AArch64] Disable consecutive store merging when Neon is unavailable (llvm#111519)
  [lldb] Fix finding make tool for tests (llvm#111980)
  Turn `-Wdeprecated-literal-operator` on by default (llvm#111027)
  [AMDGPU] Rewrite RegSeqNames using !foreach. NFC. (llvm#111994)
  Revert "Reland: [clang] Finish implementation of P0522 (llvm#111711)"
  Revert "[clang] CWG2398: improve overload resolution backwards compat (llvm#107350)"
  Revert "[clang] Implement TTP P0522 pack matching for deduced function template calls. (llvm#111457)"
  [Clang] Replace Intrinsic::getDeclaration with getOrInsertDeclaration (llvm#111990)
  Revert "[NVPTX] Prefer prmt.b32 over bfi.b32 (llvm#110766)"
  [RISCV] Add DAG combine to turn (sub (shl X, 8-Y), (shr X, Y)) into orc.b (llvm#111828)
  [libc] Fix compilation of new trig functions (llvm#111987)
  [NFC] Rename `Intrinsic::getDeclaration` to `getOrInsertDeclaration` (llvm#111752)
  [NFC][CodingStandard] Add additional example for if-else brace rule (llvm#111733)
  CodeGen: Remove redundant REQUIRES registered-target from tests (llvm#111982)
  ...
@owenca owenca merged commit 0fba838 into llvm:main Oct 12, 2024
7 of 9 checks passed
Copy link

@ichaer Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
…mments without breaking internal structure (think Doxygen). (llvm#96804)

* Convert `ReflowComments` from boolean into a new `enum` which can take
on the value `RCS_Never`, `RCS_IndentOnly`, or `RCS_Always`. The first
one is equivalent to the old `false`, the third one is `true`, and the
middle one means that multiline comments should only have their
indentation corrected, which is what Doxygen users will want.
* Preserve backward compatibility while parsing `ReflowComments`.
owenca added a commit that referenced this pull request Dec 5, 2024
…ng ClangFormatStyleOptions.rst (#111513)

* Create a new `clang-format-style-options` build target which
re-generates ClangFormatStyleOptions.rst from its source header files.

As discussed in
#96804 (comment)

---------

Co-authored-by: Owen Pan <[email protected]>
@owenca owenca removed the clang Clang issues not falling into any other category label Jan 3, 2025
kbore pushed a commit to kbore/llvm-project that referenced this pull request Jan 10, 2025
…mments without breaking internal structure (think Doxygen). (llvm#96804)

* Convert `ReflowComments` from boolean into a new `enum` which can take
on the value `RCS_Never`, `RCS_IndentOnly`, or `RCS_Always`. The first
one is equivalent to the old `false`, the third one is `true`, and the
middle one means that multiline comments should only have their
indentation corrected, which is what Doxygen users will want.
* Preserve backward compatibility while parsing `ReflowComments`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants