[clang-tools-extra] Use resolved path when filtering in IncludeInserter (PR #148371)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 31 22:16:32 PDT 2025


================
@@ -306,14 +306,14 @@ IncludeInserter::calculateIncludePath(const HeaderFile &InsertedHeader,
     return std::nullopt;
   bool IsAngled = false;
   for (auto &Filter : AngledHeaders) {
-    if (Filter(Suggested)) {
+    if (Filter(InsertedHeader.File)) {
----------------
HighCommander4 wrote:

Thanks for the patch, and sorry I didn't get a chance to look at it sooner!

> I would be curious to know whether other instances should be modified

The only other place that comes to mind is the use of `Suggested` in the error message a few lines below.

> or whether new tests would be beneficial to be added

I think the patch would benefit from one new testcase in `HeadersTests.cpp` similar to [this one](https://searchfox.org/llvm/rev/49b001474229cd935bf71340bb327f03721d9d00/clang-tools-extra/clangd/unittests/HeadersTests.cpp#337-339), but where the filter matches something like `sub/.*`. This would test that, even though `sub/` is on the include search path (that's hardcoded in the test harness [here](https://searchfox.org/llvm/rev/49b001474229cd935bf71340bb327f03721d9d00/clang-tools-extra/clangd/unittests/HeadersTests.cpp#141-142)) and so the include **spelling** gets shortened to `bar.h`, the filter is applied to the full path and so the include still ends up angled.

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


More information about the cfe-commits mailing list