[llvm-branch-commits] [clang-tools-extra] release/20.x: [clang-tidy] Fix broken HeaderFilterRegex when read from config file (#133582) (PR #134215)
carlosgalvezp wrote: @tstellar Can you advice on what the next steps are to get this merged into the release branch? https://github.com/llvm/llvm-project/pull/134215 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] release/20.x: [clang-tidy] Do not pass any file when listing checks in run_clang_ti… (#137286) (PR #137775)
https://github.com/carlosgalvezp updated https://github.com/llvm/llvm-project/pull/137775 >From 387c2886b68b1eaf68916e4b08e8d92966a1 Mon Sep 17 00:00:00 2001 From: Carlos Galvez Date: Tue, 29 Apr 2025 11:13:30 +0200 Subject: [PATCH] =?UTF-8?q?[clang-tidy]=20Do=20not=20pass=20any=20file=20w?= =?UTF-8?q?hen=20listing=20checks=20in=20run=5Fclang=5Fti=E2=80=A6=20(#137?= =?UTF-8?q?286)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …dy.py Currently, run_clang_tidy.py does not correctly display the list of checks picked up from the top-level .clang-tidy file. The reason for that is that we are passing an empty string as input file. However, that's not how we are supposed to use clang-tidy to list checks. Per https://github.com/llvm/llvm-project/commit/65eccb463df7fe511c813ee6a1794c80d7489ff2, we simply should not pass any file at all - the internal code of clang-tidy will pass a "dummy" file if that's the case and get the .clang-tidy file from the current working directory. Fixes #136659 Co-authored-by: Carlos Gálvez (cherry picked from commit 014ab736dc741f24c007f9861e24b31faba0e1e7) --- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py | 7 --- clang-tools-extra/docs/ReleaseNotes.rst | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) 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 f1b934f7139e9..8741147a4f8a3 100755 --- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py +++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py @@ -87,7 +87,7 @@ def find_compilation_database(path: str) -> str: def get_tidy_invocation( -f: str, +f: Optional[str], clang_tidy_binary: str, checks: str, tmpdir: Optional[str], @@ -147,7 +147,8 @@ def get_tidy_invocation( start.append(f"--warnings-as-errors={warnings_as_errors}") if allow_no_checks: start.append("--allow-no-checks") -start.append(f) +if f: +start.append(f) return start @@ -490,7 +491,7 @@ async def main() -> None: try: invocation = get_tidy_invocation( -"", +None, clang_tidy_binary, args.checks, None, diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 2ab597eb37048..0b2e9c5fabc36 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -190,6 +190,9 @@ Improvements to clang-tidy - Fixed bug in :program:`clang-tidy` by which `HeaderFilterRegex` did not take effect when passed via the `.clang-tidy` file. +- Fixed bug in :program:`run_clang_tidy.py` where the program would not + correctly display the checks enabled by the top-level `.clang-tidy` file. + New checks ^^ ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] release/20.x: [clang-tidy] Do not pass any file when listing checks in run_clang_ti… (#137286) (PR #137775)
carlosgalvezp wrote: @HerrCai0907 Could you approve the PR so we can bring it to the release? https://github.com/llvm/llvm-project/pull/137775 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] release/20.x: [clang-tidy] Fix broken HeaderFilterRegex when read from config file (#133582) (PR #134215)
carlosgalvezp wrote: > It's ok as far as it works. Personally if we do not utilize that optional, > then probably it should be removed. It's essentially a revert. I agree that our usage of optional in the Options is not good, we should improve that on a separate patch. https://github.com/llvm/llvm-project/pull/134215 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] release/20.x: [clang-tidy] Fix broken HeaderFilterRegex when read from config file (#133582) (PR #134215)
https://github.com/carlosgalvezp updated https://github.com/llvm/llvm-project/pull/134215 >From d868cc50a9aa0884a360c20179a8a921417d867c Mon Sep 17 00:00:00 2001 From: Carlos Galvez Date: Thu, 3 Apr 2025 09:28:34 +0200 Subject: [PATCH] [clang-tidy] Fix broken HeaderFilterRegex when read from config file (#133582) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR https://github.com/llvm/llvm-project/pull/91400 broke the usage of HeaderFilterRegex via config file, because it is now created at a different point in the execution and leads to a different value. The result of that is that using HeaderFilterRegex only in the config file does NOT work, in other words clang-tidy stops triggering warnings on header files, thereby losing a lot of coverage. This patch reverts the logic so that the header filter is created upon calling the getHeaderFilter() function. Additionally, this patch adds 2 unit tests to prevent regressions in the future: - One of them, "simple", tests the most basic use case with a single top-level .clang-tidy file. - The second one, "inheritance", demonstrates that the subfolder only gets warnings from headers within it, and not from parent headers. Fixes #118009 Fixes #121969 Fixes #133453 Co-authored-by: Carlos Gálvez (cherry picked from commit 6333fa5160fbde4bd2cf6afe8856695c13ab621f) --- .../ClangTidyDiagnosticConsumer.cpp | 36 ++- .../clang-tidy/ClangTidyDiagnosticConsumer.h | 4 +++ .../clang-tidy/ClangTidyOptions.cpp | 4 +-- clang-tools-extra/docs/ReleaseNotes.rst | 3 ++ .../inheritance/.clang-tidy | 1 + .../inheritance/foo.cpp | 3 ++ .../inheritance/foo.h | 1 + .../inheritance/subfolder/.clang-tidy | 2 ++ .../inheritance/subfolder/bar.cpp | 8 + .../inheritance/subfolder/bar.h | 1 + .../simple/.clang-tidy| 1 + .../simple/foo.cpp| 3 ++ .../simple/foo.h | 1 + 13 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/inheritance/.clang-tidy create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/inheritance/foo.cpp create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/inheritance/foo.h create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/inheritance/subfolder/.clang-tidy create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/inheritance/subfolder/bar.cpp create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/inheritance/subfolder/bar.h create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/simple/.clang-tidy create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/simple/foo.cpp create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/simple/foo.h diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp index 4c75b42270114..71e852545203e 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -311,18 +311,7 @@ ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer( : Context(Ctx), ExternalDiagEngine(ExternalDiagEngine), RemoveIncompatibleErrors(RemoveIncompatibleErrors), GetFixesFromNotes(GetFixesFromNotes), - EnableNolintBlocks(EnableNolintBlocks) { - - if (Context.getOptions().HeaderFilterRegex && - !Context.getOptions().HeaderFilterRegex->empty()) -HeaderFilter = -std::make_unique(*Context.getOptions().HeaderFilterRegex); - - if (Context.getOptions().ExcludeHeaderFilterRegex && - !Context.getOptions().ExcludeHeaderFilterRegex->empty()) -ExcludeHeaderFilter = std::make_unique( -*Context.getOptions().ExcludeHeaderFilterRegex); -} + EnableNolintBlocks(EnableNolintBlocks) {} void ClangTidyDiagnosticConsumer::finalizeLastError() { if (!Errors.empty()) { @@ -571,17 +560,30 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location, } StringRef FileName(File->getName()); - LastErrorRelatesToUserCode = - LastErrorRelatesToUserCode || Sources.isInMainFile(Location) || - (HeaderFilter && - (HeaderFilter->match(FileName) && -!(ExcludeHeaderFilter && ExcludeHeaderFilter->match(FileName; + LastErrorRelatesToUserCode = LastErrorRelatesToUserCode || + Sources.isInMainFile(Location) || + (getHeade