[clang-tools-extra] [clangd] Allow --query-driver to match a dot-normalized form of the path (PR #66757)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 19 03:18:43 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clangd

<details>
<summary>Changes</summary>

(In addition to the un-normalized form, so this is back-compatible)


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


1 Files Affected:

- (modified) clang-tools-extra/clangd/SystemIncludeExtractor.cpp (+7-1) 


``````````diff
diff --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index 88df5b04ccb09f3..3f93927434dbfa8 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -343,7 +343,13 @@ extractSystemIncludesAndTarget(const DriverArgs &InputArgs,
   SPAN_ATTACH(Tracer, "driver", Driver);
   SPAN_ATTACH(Tracer, "lang", InputArgs.Lang);
 
-  if (!QueryDriverRegex.match(Driver)) {
+  // If driver was "../foo" then having to allowlist "/path/a/../foo" rather
+  // than "/path/foo" is absurd.
+  // Allow either to match the whitelist, then proceed with "/path/a/../foo".
+  // This was our historical behavior, and it *could* resolve to something else.
+  llvm::SmallString<256> NoDots(Driver);
+  llvm::sys::path::remove_dots(NoDots, /*remove_dot_dot=*/true);
+  if (!QueryDriverRegex.match(Driver) && !QueryDriverRegex.match(NoDots)) {
     vlog("System include extraction: not allowed driver {0}", Driver);
     return std::nullopt;
   }

``````````

</details>


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


More information about the cfe-commits mailing list