Skip to content

[clang-tidy] Normalize windows line filter paths - #217038

Merged
cjappl merged 7 commits into
llvm:mainfrom
cjappl:cjappl/tidy_normalize_windows
Sep 5, 2026
Merged

cjappl merged 7 commits into
llvm:mainfrom
cjappl:cjappl/tidy_normalize_windows

Conversation

@cjappl

@cjappl cjappl commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

git | clang-tidy-diff.py emits line-filter paths with forward slashes, while Windows compilation databases use a mix of forwards and backwards slashes. These paths are then silently rejected (and no report is emitted).

Reproduce on windows via:

git.exe diff -U0 main -- . | python clang-tidy-diff.py -p1 -path .\build"

Git will produce a path like:

my/source/file.cpp

The compilation database has files with entries like this:

  "file": "C:\\dev\\repo\\my\\source\\file.cpp",
  "output": "my\\source\\CMakeFiles\\source.dir\\file.cpp.obj"

Clang tidy tries to match these paths, but fails on the slash comparison.

Do a few things to fix this:

  • Normalize filter paths with llvm::sys::path::convert_to_slash() before matching the compilation database. This is a no-op on posix, but converts windows forward slashes to backwards.
  • Normalize Filter.Name paths when parsed
  • Write a couple more unit tests for windows specific paths that expose this behavior
  • Enable another UNSUPPORTED test for windows clang-tidy-diff (and make it run in a nested directory to exercise the issue
  • As another way to fix this just for clang-tidy-diff, use Path to normalize that path. This fix is included as kind of a second "cover your butt" style fix, but isn't strictly necessary if the first is merged.

Initial versions of this fix were created by codex after I encountered the bug on my windows dev machine.

Tested with check-clang-extra-clang-tidy on both windows and mac.

Fixes #112038.

@llvmorg-github-actions

llvmorg-github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

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

@llvm/pr-subscribers-clang-tidy

Author: Chris Apple (cjappl)

Changes

git | clang-tidy-diff.py emits line-filter paths with forward slashes, while Windows compilation databases use a mix of forwards and backwards slashes. These paths are then silently rejected (and no report is emitted).

Reproduce on windows via:

git.exe diff -U0 main -- . | python clang-tidy-diff.py -p1 -path .\build"

Git will produce a path like:

my/source/file.cpp

The compilation database has files with entries like this:

  "file": "C:\\dev\\repo\\my\\source\\file.cpp",
  "output": "my\\source\\CMakeFiles\\source.dir\\file.cpp.obj"

Clang tidy tries to match these paths, but fails on the slash comparison.

Do a few things to fix this:

  • Normalize filter paths with llvm::sys::path::convert_to_slash() before matching the compilation database. This is a no-op on posix, but converts windows forward slashes to backwards.
  • Normalize Filter.Name paths when parsed
  • Write a couple more unit tests for windows specific paths that expose this behavior
  • Enable another UNSUPPORTED test for windows clang-tidy-diff (and make it run in a nested directory to exercise the issue
  • As another way to fix this just for clang-tidy-diff, use Path to normalize that path. This fix is included as kind of a second "cover your butt" style fix, but isn't strictly necessary if the first is merged.

Initial versions of this fix were created by codex after I encountered the bug on my windows dev machine.

Tested with check-clang-extra-clang-tidy on both windows and mac.


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

7 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp (+4-1)
  • (modified) clang-tools-extra/clang-tidy/ClangTidyOptions.cpp (+6-1)
  • (modified) clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py (+2-1)
  • (modified) clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp (+9-9)
  • (modified) clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp (+70)
  • (modified) clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp (+8)
  • (modified) clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h (+10-10)
diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 48d8c76bd4db6..61eacd5df6c25 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -36,6 +36,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
 #include <optional>
 #include <tuple>
@@ -484,8 +485,10 @@ bool ClangTidyDiagnosticConsumer::passesLineFilter(StringRef FileName,
                                                    unsigned LineNumber) const {
   if (Context.getGlobalOptions().LineFilter.empty())
     return true;
+  const std::string NormalizedFileName =
+      llvm::sys::path::convert_to_slash(FileName);
   for (const FileFilter &Filter : Context.getGlobalOptions().LineFilter) {
-    if (FileName.ends_with(Filter.Name)) {
+    if (StringRef(NormalizedFileName).ends_with(Filter.Name)) {
       if (Filter.LineRanges.empty())
         return true;
       return llvm::any_of(
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 2ef23ede09972..6a77ecb8cb661 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -531,7 +531,12 @@ std::error_code parseLineFilter(StringRef LineFilter,
                                 clang::tidy::ClangTidyGlobalOptions &Options) {
   llvm::yaml::Input Input(LineFilter);
   Input >> Options.LineFilter;
-  return Input.error();
+  if (std::error_code Error = Input.error())
+    return Error;
+
+  for (FileFilter &Filter : Options.LineFilter)
+    Filter.Name = llvm::sys::path::convert_to_slash(Filter.Name);
+  return {};
 }
 
 llvm::ErrorOr<ClangTidyOptions>
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 059b2a2e8f476..f52f063c270eb 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -394,8 +394,9 @@ def main():
         common_clang_tidy_args.append("-warnings-as-errors=" + args.warnings_as_errors)
 
     for name in lines_by_file:
+        line_filter_name = str((Path.cwd() / name).resolve())
         line_filter_json = json.dumps(
-            [{"name": name, "lines": lines_by_file[name]}], separators=(",", ":")
+            [{"name": line_filter_name, "lines": lines_by_file[name]}], separators=(",", ":"),
         )
 
         # Run clang-tidy on files containing changes.
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 63fe155df7817..3064eca9354ab 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
@@ -1,17 +1,17 @@
-// UNSUPPORTED: system-windows
-// RUN: sed 's/placeholder_for_f/f/' %s > %t.cpp
-// RUN: clang-tidy -checks=-*,modernize-use-override %t.cpp -- -std=c++11 | FileCheck -check-prefix=CHECK-SANITY %s
-// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -- -std=c++11 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-JMAX
-// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -quiet -- -std=c++11 2>&1 | FileCheck -check-prefix=CHECK-QUIET %s
+// RUN: mkdir -p %t.dir/src
+// RUN: sed 's/placeholder_for_f/f/' %s > %t.dir/src/test.cpp
+// RUN: clang-tidy -checks=-*,modernize-use-override %t.dir/src/test.cpp -- -std=c++11 | FileCheck -check-prefix=CHECK-SANITY %s
+// RUN: not diff -U0 %s %t.dir/src/test.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -- -std=c++11 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-JMAX
+// RUN: not diff -U0 %s %t.dir/src/test.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -quiet -- -std=c++11 2>&1 | FileCheck -check-prefix=CHECK-QUIET %s
 // RUN: mkdir -p %t.dir/compilation-database-test/
-// RUN: echo '[{"directory": "%t.dir", "command": "clang++ -o test.o -std=c++11 %t.cpp", "file": "%t.cpp"}]' > %t.dir/compilation-database-test/compile_commands.json
-// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -path %t.dir/compilation-database-test 2>&1 | FileCheck -check-prefix=CHECK %s
+// RUN: echo '[{"directory": "%/t.dir", "command": "clang++ -o test.o -std=c++11 %/t.dir/src/test.cpp", "file": "%/t.dir/src/test.cpp"}]' > %t.dir/compilation-database-test/compile_commands.json
+// RUN: not diff -U0 %s %t.dir/src/test.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -path %t.dir/compilation-database-test 2>&1 | FileCheck -check-prefix=CHECK %s
 
-// 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
+// RUN: not diff -U0 %s %t.dir/src/test.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: not diff -U0 %s %t.dir/src/test.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
diff --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp b/clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
index 11c9ac9928221..39b86c7d62ef7 100644
--- a/clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
@@ -111,6 +111,76 @@ TEST(ClangTidyDiagnosticConsumer, InvalidSourceLocationRangesIgnored) {
   EXPECT_EQ(1ul, Errors[3].Message.Ranges.size());
 }
 
+#ifdef _WIN32
+
+namespace {
+class LineFilterTestCheck : public ClangTidyCheck {
+public:
+  LineFilterTestCheck(StringRef Name, ClangTidyContext *Context)
+      : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override {
+    Finder->addMatcher(ast_matchers::varDecl().bind("var"), this);
+  }
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override {
+    diag(Result.Nodes.getNodeAs<VarDecl>("var")->getLocation(), "variable");
+  }
+};
+} // namespace
+
+TEST(ClangTidyDiagnosticConsumer, LineFilterNormalizesWindowsPaths) {
+  const auto ParsedDiagnosticsFor = [](StringRef FileName,
+                                       StringRef LineFilter) {
+    ClangTidyGlobalOptions GlobalOptions;
+    EXPECT_FALSE(parseLineFilter(LineFilter, GlobalOptions));
+    std::vector<ClangTidyError> Errors;
+    runCheckOnCode<LineFilterTestCheck>("int x;", &Errors, FileName, {},
+                                        ClangTidyOptions(), {}, GlobalOptions);
+    return Errors;
+  };
+  const auto DiagnosticsFor =
+      [](StringRef FileName, StringRef FilterName,
+         std::vector<FileFilter::LineRange> LineRanges = {}) {
+        ClangTidyGlobalOptions GlobalOptions;
+        GlobalOptions.LineFilter.push_back(
+            {FilterName.str(), std::move(LineRanges)});
+        std::vector<ClangTidyError> Errors;
+        runCheckOnCode<LineFilterTestCheck>("int x;", &Errors, FileName, {},
+                                            ClangTidyOptions(), {},
+                                            GlobalOptions);
+        return Errors;
+      };
+
+  EXPECT_EQ(1u, ParsedDiagnosticsFor(R"(C:\root\project\src\input.cc)",
+                                     R"([{"name":"project/src/input.cc"}])")
+                    .size());
+  EXPECT_EQ(1u, ParsedDiagnosticsFor(R"(C:\root\project\src\input.cc)",
+                                     R"([{"name":"project\\src\\input.cc"}])")
+                    .size());
+  EXPECT_EQ(1u, ParsedDiagnosticsFor("C:/root/project/src/input.cc",
+                                     R"([{"name":"project/src/input.cc"}])")
+                    .size());
+  EXPECT_EQ(1u, ParsedDiagnosticsFor("C:/root/project/src/input.cc",
+                                     R"([{"name":"project\\src\\input.cc"}])")
+                    .size());
+
+  EXPECT_EQ(
+      1u, DiagnosticsFor(R"(C:\root\project\src\input.cc)", "input.cc").size());
+  EXPECT_EQ(
+      1u,
+      DiagnosticsFor(R"(C:\root\project\src\input.cc)", "src/input.cc").size());
+  EXPECT_TRUE(
+      DiagnosticsFor(R"(C:\root\project\src\input.cc)", "other/src/input.cc")
+          .empty());
+
+  EXPECT_EQ(1u, DiagnosticsFor(R"(C:\root\project\src\input.cc)",
+                               "project/src/input.cc", {{1, 1}})
+                    .size());
+  EXPECT_TRUE(DiagnosticsFor(R"(C:\root\project\src\input.cc)",
+                             "project/src/input.cc", {{2, 2}})
+                  .empty());
+}
+#endif
+
 } // namespace test
 } // namespace tidy
 } // namespace clang
diff --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp b/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
index 3f86f65c1ce65..145538c137913 100644
--- a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -75,6 +75,14 @@ TEST(ParseLineFilter, ValidFilter) {
   EXPECT_EQ(1000u, Options.LineFilter[2].LineRanges[0].second);
 }
 
+TEST(ParseLineFilter, NormalizesWindowsPathSeparators) {
+  ClangTidyGlobalOptions Options;
+  EXPECT_FALSE(
+      parseLineFilter(R"([{"name":"project\\src\\input.cc"}])", Options));
+  ASSERT_EQ(1u, Options.LineFilter.size());
+  EXPECT_EQ("project/src/input.cc", Options.LineFilter[0].Name);
+}
+
 TEST(ParseConfiguration, ValidConfiguration) {
   llvm::ErrorOr<ClangTidyOptions> Options =
       parseConfiguration(llvm::MemoryBufferRef(
diff --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
index 195d6a6c60918..040388338bc95 100644
--- a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
+++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
@@ -83,19 +83,19 @@ class TestClangTidyAction : public ASTFrontendAction {
 };
 
 template <typename... CheckTypes>
-std::string
-runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
-               const Twine &Filename = "input.cc",
-               ArrayRef<std::string> ExtraArgs = {},
-               const ClangTidyOptions &ExtraOptions = ClangTidyOptions(),
-               std::map<StringRef, StringRef> PathsToContent =
-                   std::map<StringRef, StringRef>()) {
+std::string runCheckOnCode(
+    StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
+    const Twine &Filename = "input.cc", ArrayRef<std::string> ExtraArgs = {},
+    const ClangTidyOptions &ExtraOptions = ClangTidyOptions(),
+    std::map<StringRef, StringRef> PathsToContent =
+        std::map<StringRef, StringRef>(),
+    const ClangTidyGlobalOptions &GlobalOptions = ClangTidyGlobalOptions()) {
   static_assert(sizeof...(CheckTypes) > 0, "No checks specified");
   ClangTidyOptions Options = ExtraOptions;
   Options.Checks = "*";
-  ClangTidyContext Context(std::make_unique<DefaultOptionsProvider>(
-                               ClangTidyGlobalOptions(), Options),
-                           false, false, false);
+  ClangTidyContext Context(
+      std::make_unique<DefaultOptionsProvider>(GlobalOptions, Options), false,
+      false, false);
   ClangTidyDiagnosticConsumer DiagConsumer(Context);
   auto DiagOpts = std::make_unique<DiagnosticOptions>();
   DiagnosticsEngine DE(DiagnosticIDs::create(), *DiagOpts, &DiagConsumer,

// RUN: clang-tidy -checks=-*,modernize-use-override %t.cpp -- -std=c++11 | FileCheck -check-prefix=CHECK-SANITY %s
// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -- -std=c++11 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-JMAX
// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -quiet -- -std=c++11 2>&1 | FileCheck -check-prefix=CHECK-QUIET %s
// RUN: mkdir -p %t.dir/src

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The changes in this file were:

  1. Make this test supported on windows
  2. Make the test run in a deeper nested directory, to make sure this problem is accentuated.

The second can be reverted if people don't like it. I hope there is enough unit tests elsewhere to cover everything.

const ClangTidyOptions &ExtraOptions = ClangTidyOptions(),
std::map<StringRef, StringRef> PathsToContent =
std::map<StringRef, StringRef>()) {
std::string runCheckOnCode(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I recommend looking at this file without whitespace changes, there is only a minimal change to the global options so I can override the global options filter in the unit test.

@github-actions

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

✅ With the latest revision this PR passed the Python code formatter.

@github-actions

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code linter.

@github-actions

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 5386 tests passed
  • 8 tests skipped

✅ The build succeeded and all tests passed.

@vbvictor vbvictor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add release notes

Comment thread clang-tools-extra/docs/ReleaseNotes.md Resolved
Comment on lines +396 to +400
for name in lines_by_file:
line_filter_name = str((Path.cwd() / name).resolve())
line_filter_json = json.dumps(
[{"name": name, "lines": lines_by_file[name]}], separators=(",", ":")
[{"name": line_filter_name, "lines": lines_by_file[name]}],
separators=(",", ":"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this isn't necessary, can we land in a separate patch after this first one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reverted in the most recent

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it is not. Or I'm missing smth

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

apologies, forgot to push!

@jurf

jurf commented Sep 1, 2026

Copy link
Copy Markdown

Seems to be the same issue: #112038

@cjappl

cjappl commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Seems to be the same issue: #112038

Ah! Yes, this does seem to be the same. Looks like the same way I stumbled on it.

@cjappl

cjappl commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Also, friendly ping for review @EugeneZelenko @vbvictor @zeyi2

@vbvictor vbvictor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, with nit

Comment on lines +396 to +400
for name in lines_by_file:
line_filter_name = str((Path.cwd() / name).resolve())
line_filter_json = json.dumps(
[{"name": name, "lines": lines_by_file[name]}], separators=(",", ":")
[{"name": line_filter_name, "lines": lines_by_file[name]}],
separators=(",", ":"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it is not. Or I'm missing smth

@cjappl
cjappl merged commit 9faf317 into llvm:main Sep 5, 2026
14 checks passed
@cjappl
cjappl deleted the cjappl/tidy_normalize_windows branch September 5, 2026 00:05
@cjappl

cjappl commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

/cherry-pick 9faf317

@llvmbot

llvmbot commented Sep 5, 2026

Copy link
Copy Markdown
Member

/cherry-pick 9faf317

Error: Command failed due to missing milestone.

@EugeneZelenko EugeneZelenko removed this from the LLVM 23.x Release milestone Sep 5, 2026
@EugeneZelenko

Copy link
Copy Markdown
Contributor

@cjappl: Cherry-picking should be in issue, not pull request.

addmisol pushed a commit to addmisol/llvm-project2 that referenced this pull request Sep 6, 2026
`git | clang-tidy-diff.py` emits line-filter paths with forward slashes,
while Windows compilation databases use a mix of forwards and backwards
slashes. These paths are then silently rejected (and no report is
emitted).

Reproduce on windows via:
```
git.exe diff -U0 main -- . | python clang-tidy-diff.py -p1 -path .\build"
```

Git will produce a path like:
```
my/source/file.cpp
```

The compilation database has files with entries like this:
```
  "file": "C:\\dev\\repo\\my\\source\\file.cpp",
  "output": "my\\source\\CMakeFiles\\source.dir\\file.cpp.obj"
```

Clang tidy tries to match these paths, but fails on the slash
comparison.


Do a few things to fix this:
* Normalize filter paths with `llvm::sys::path::convert_to_slash()`
before matching the compilation database. This is a no-op on posix, but
converts windows forward slashes to backwards.
* Normalize `Filter.Name` paths when parsed
* Write a couple more unit tests for windows specific paths that expose
this behavior
* Enable another UNSUPPORTED test for windows clang-tidy-diff (and make
it run in a nested directory to exercise the issue

Fixes llvm#112038.
vadimkotov pushed a commit to vadimkotov/llvm-project that referenced this pull request Sep 8, 2026
`git | clang-tidy-diff.py` emits line-filter paths with forward slashes,
while Windows compilation databases use a mix of forwards and backwards
slashes. These paths are then silently rejected (and no report is
emitted).

Reproduce on windows via:
```
git.exe diff -U0 main -- . | python clang-tidy-diff.py -p1 -path .\build"
```

Git will produce a path like:
```
my/source/file.cpp
```

The compilation database has files with entries like this:
```
  "file": "C:\\dev\\repo\\my\\source\\file.cpp",
  "output": "my\\source\\CMakeFiles\\source.dir\\file.cpp.obj"
```

Clang tidy tries to match these paths, but fails on the slash
comparison.


Do a few things to fix this:
* Normalize filter paths with `llvm::sys::path::convert_to_slash()`
before matching the compilation database. This is a no-op on posix, but
converts windows forward slashes to backwards.
* Normalize `Filter.Name` paths when parsed
* Write a couple more unit tests for windows specific paths that expose
this behavior
* Enable another UNSUPPORTED test for windows clang-tidy-diff (and make
it run in a nested directory to exercise the issue

Fixes llvm#112038.
dyung pushed a commit that referenced this pull request Sep 10, 2026
`git | clang-tidy-diff.py` emits line-filter paths with forward slashes,
while Windows compilation databases use a mix of forwards and backwards
slashes. These paths are then silently rejected (and no report is
emitted).

Reproduce on windows via:
```
git.exe diff -U0 main -- . | python clang-tidy-diff.py -p1 -path .\build"
```

Git will produce a path like:
```
my/source/file.cpp
```

The compilation database has files with entries like this:
```
  "file": "C:\\dev\\repo\\my\\source\\file.cpp",
  "output": "my\\source\\CMakeFiles\\source.dir\\file.cpp.obj"
```

Clang tidy tries to match these paths, but fails on the slash
comparison.

Do a few things to fix this:
* Normalize filter paths with `llvm::sys::path::convert_to_slash()`
before matching the compilation database. This is a no-op on posix, but
converts windows forward slashes to backwards.
* Normalize `Filter.Name` paths when parsed
* Write a couple more unit tests for windows specific paths that expose
this behavior
* Enable another UNSUPPORTED test for windows clang-tidy-diff (and make
it run in a nested directory to exercise the issue

Fixes #112038.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

[clang-tidy] -line-filter only works with windows path separators on Windows

5 participants