https://github.com/HazardyKnusperkeks updated https://github.com/llvm/llvm-project/pull/218022
From 63a0206996f4ee25970af99ce450f8ad4e68df6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= <[email protected]> Date: Fri, 21 Aug 2026 22:21:28 +0200 Subject: [PATCH 1/2] [clang-format] Honor new lines before // clang-format on And as a drive by don't recalculate the new line count for something we won't touch anyway. Fixes #217872. --- clang/lib/Format/UnwrappedLineFormatter.cpp | 2 ++ clang/unittests/Format/FormatTest.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 7afc7a46dd1c0..b44dd71b2084c 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -1637,6 +1637,8 @@ static auto computeNewlines(const AnnotatedLine &Line, const SmallVectorImpl<AnnotatedLine *> &Lines, const FormatStyle &Style) { const auto &RootToken = *Line.First; + if (RootToken.Finalized || isClangFormatOn(RootToken.TokenText)) + return RootToken.NewlinesBefore; auto Newlines = std::min(RootToken.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1); // Remove empty lines before "}" where applicable. diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 6f604167f785c..6df5b4eb18c50 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -22420,6 +22420,14 @@ TEST_F(FormatTest, DisableRegions) { " #endif\n" "#endif\n" "// clang-format on"); + + verifyNoChange("// clang-format off\n" + "int i;\n" + "\n" + "\n" + "\n" + "\n" + "// clang-format on"); } TEST_F(FormatTest, OneLineFormatOffRegex) { From 010d151b86e24dd82d408776b0c094f74660437b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= <[email protected]> Date: Sat, 22 Aug 2026 12:05:15 +0200 Subject: [PATCH 2/2] Update clang/unittests/Format/FormatTest.cpp Co-authored-by: owenca <[email protected]> --- clang/unittests/Format/FormatTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 6df5b4eb18c50..99561f12c51c8 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -22422,9 +22422,9 @@ TEST_F(FormatTest, DisableRegions) { "// clang-format on"); verifyNoChange("// clang-format off\n" - "int i;\n" "\n" "\n" + " int i ;\n" "\n" "\n" "// clang-format on"); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
