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

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 19 03:17:33 PDT 2023


https://github.com/sam-mccall created https://github.com/llvm/llvm-project/pull/66757

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


>From 1923a5142f9cbd3556bba599b611ae8a1bbec776 Mon Sep 17 00:00:00 2001
From: Sam McCall <sam.mccall at gmail.com>
Date: Tue, 19 Sep 2023 12:16:54 +0200
Subject: [PATCH] [clangd] Allow --query-driver to match a dot-normalized form
 of the path

(In addition to the un-normalized form, so this is back-compatible)
---
 clang-tools-extra/clangd/SystemIncludeExtractor.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

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;
   }



More information about the cfe-commits mailing list