https://github.com/vbvictor created 
https://github.com/llvm/llvm-project/pull/213873

clang-tidy-diff.py unconditionally wrote `stdout + "\n"` for every file it 
processed, even when clang-tidy produced no output so this bloated output with 
needless blank line (happened with `-quiet` flag enabled which made tidy 
produce 0  diagnostics).

>From 5334b35f3c0572a2ffca4501fcd7e7add1f03fa2 Mon Sep 17 00:00:00 2001
From: Victor Baranov <[email protected]>
Date: Tue, 4 Aug 2026 11:33:21 +0300
Subject: [PATCH] [clang-tidy] Fix clang-tidy-diff with not producing blank
 lines

---
 clang-tools-extra/clang-tidy/.clang-tidy                  | 5 ++++-
 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py      | 5 +++--
 .../infrastructure/Inputs/clang-tidy-diff/test.cpp        | 1 +
 .../test/clang-tidy/infrastructure/clang-tidy-diff.cpp    | 8 ++++++++
 4 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/clang-tidy-diff/test.cpp

diff --git a/clang-tools-extra/clang-tidy/.clang-tidy 
b/clang-tools-extra/clang-tidy/.clang-tidy
index 04ff2727618f7..53db717f411fb 100644
--- a/clang-tools-extra/clang-tidy/.clang-tidy
+++ b/clang-tools-extra/clang-tidy/.clang-tidy
@@ -14,7 +14,8 @@ Checks: >
   cppcoreguidelines-rvalue-reference-param-not-moved,
   cppcoreguidelines-virtual-class-destructor,
   google-readability-casting,
-  misc-const-correctness,
+  -misc-const-correctness,
+  -misc-explicit-constructor,
   misc-include-cleaner,
   modernize-*,
   -modernize-avoid-c-arrays,
@@ -33,6 +34,8 @@ Checks: >
   -readability-identifier-length,
   -readability-implicit-bool-conversion,
   -readability-isolate-declaration,
+  -readability-trailing-comma,
+  -readability-redundant-lambda-parameter-list,
   -readability-magic-numbers,
   -readability-named-parameter,
   -readability-qualified-auto,
diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py 
b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index 07f2b911a03a2..059b2a2e8f476 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -68,8 +68,9 @@ def run_tidy(task_queue, lock, timeout, failed_files):
                 failed_files.append(command)
 
             with lock:
-                sys.stdout.write(stdout.decode("utf-8") + "\n")
-                sys.stdout.flush()
+                if stdout:
+                    sys.stdout.write(stdout.decode("utf-8") + "\n")
+                    sys.stdout.flush()
                 if stderr:
                     sys.stderr.write(stderr.decode("utf-8") + "\n")
                     sys.stderr.flush()
diff --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/clang-tidy-diff/test.cpp
 
b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/clang-tidy-diff/test.cpp
new file mode 100644
index 0000000000000..63fe1d0109392
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/clang-tidy-diff/test.cpp
@@ -0,0 +1 @@
+int add(int a, int b) { return PLACEHOLDER; }
diff --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp
index 43b7d781e6a7a..63fe155df7817 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp
@@ -9,6 +9,14 @@
 
 // RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff 
-checks=-*,modernize-use-override -j 1 -- -std=c++11 2>&1 | FileCheck %s 
--check-prefix=CHECK-J1
 // CHECK-J1: Running clang-tidy in 1 threads...
+
+// Test that running over multiple files don't produce blank lines in output
+// RUN: not diff -U0 %s %t.cpp > %t.diff
+// RUN: sed 's/PLACEHOLDER/a + b + 0/' %S/Inputs/clang-tidy-diff/test.cpp > 
%t.clean.cpp
+// RUN: not diff -U0 %S/Inputs/clang-tidy-diff/test.cpp %t.clean.cpp > 
%t.clean.diff
+// RUN: cat %t.clean.diff %t.diff | %clang_tidy_diff 
-checks=-*,modernize-use-override -j 1 -- -std=c++11 2>&1 | FileCheck %s 
--check-prefix=CHECK-NOBLANK
+// CHECK-NOBLANK: Running clang-tidy in 1 threads...
+// CHECK-NOBLANK-NEXT: :8: warning: annotate this
 struct A {
   virtual void f() {}
   virtual void g() {}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to