[clang-tools-extra] [clang-tidy] Properly escape printed clang-tidy command in `run-clang-tidy.py` (PR #189974)

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 1 08:13:29 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tidy

@llvm/pr-subscribers-clang-tools-extra

Author: Thorsten Klein (thorsten-klein)

<details>
<summary>Changes</summary>

The `run-clang-tidy.py` script now uses `shlex.join()` to construct the command string for printing.

This ensures that arguments containing shell metacharacters, such as the asterisk in `--warnings-as-errors=*`, are correctly quoted. This allows the command to be safely copied and pasted into any shell for manual execution, fixing errors previously seen with shells like `fish` that are strict about wildcard expansion.

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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/tool/run-clang-tidy.py (+2-1) 


``````````diff
diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index f4c3d00734389..f827ef492f01c 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -42,6 +42,7 @@
 import multiprocessing
 import os
 import re
+import shlex
 import shutil
 import subprocess
 import sys
@@ -732,7 +733,7 @@ async def main() -> None:
             progress = f"[{i + 1: >{len(f'{len(files)}')}}/{len(files)}]"
             runtime = f"[{result.elapsed:.1f}s]"
             if not args.hide_progress:
-                print(f"{progress}{runtime} {' '.join(result.invocation)}")
+                print(f"{progress}{runtime} {shlex.join(result.invocation)}")
             if result.stdout:
                 print(result.stdout, end=("" if result.stderr else "\n"))
             if result.stderr:

``````````

</details>


https://github.com/llvm/llvm-project/pull/189974


More information about the cfe-commits mailing list