[clang] 7e42b97 - [Tooling] Resolve tool names from PATH in CommonOptionsParser (#213681)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 14 09:04:45 PDT 2026
Author: Zeyi Xu
Date: 2026-08-15T00:04:38+08:00
New Revision: 7e42b97db3c1b574dae3af4d82bb48676bd5005f
URL: https://github.com/llvm/llvm-project/commit/7e42b97db3c1b574dae3af4d82bb48676bd5005f
DIFF: https://github.com/llvm/llvm-project/commit/7e42b97db3c1b574dae3af4d82bb48676bd5005f.diff
LOG: [Tooling] Resolve tool names from PATH in CommonOptionsParser (#213681)
Resolve tool names through `PATH` before passing compilation commands to
the Clang driver.
Compilation databases may specify the tool by name rather than by
absolute path:
e.g.
```json
[
{
"directory": "/path/to/project",
"command": "clang -c test.c",
"file": "test.c"
}
]
```
LibTooling invokes the driver in-process, so the compiler name in the
example is not resolved by a shell. As a result, the driver can't find
installation-relative resources.
This could be problematic with Homebrew Clang, where the missing
executable path prevents the driver from loading the SDK configuration
and causes system headers to be unavailable.
Closes #213633
Added:
Modified:
clang/docs/ReleaseNotes.md
clang/lib/Tooling/CommonOptionsParser.cpp
clang/test/Tooling/clang-check-mac-libcxx-relpath.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 6548e8a6028cb..a7a31946610ae 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -179,6 +179,9 @@ features cannot lower the translation-unit ABI level;
### Non-comprehensive list of changes in this release
+- Clang tools now resolve tool names without a path in compilation databases
+ through `PATH`.
+
- Clang now allows GNU computed `goto` extension in `constexpr` functions, matching the relaxed
`constexpr` function body rules introduced in C++23.
diff --git a/clang/lib/Tooling/CommonOptionsParser.cpp b/clang/lib/Tooling/CommonOptionsParser.cpp
index c8c3ca98323e2..454e7ca68a65f 100644
--- a/clang/lib/Tooling/CommonOptionsParser.cpp
+++ b/clang/lib/Tooling/CommonOptionsParser.cpp
@@ -139,6 +139,7 @@ llvm::Error CommonOptionsParser::init(
new FixedCompilationDatabase(".", std::vector<std::string>()));
}
}
+ Compilations = inferToolLocation(std::move(Compilations));
auto AdjustingCompilations =
std::make_unique<ArgumentsAdjustingCompilations>(
std::move(Compilations));
diff --git a/clang/test/Tooling/clang-check-mac-libcxx-relpath.cpp b/clang/test/Tooling/clang-check-mac-libcxx-relpath.cpp
index 7a801a2814402..bcee5ad949fbe 100644
--- a/clang/test/Tooling/clang-check-mac-libcxx-relpath.cpp
+++ b/clang/test/Tooling/clang-check-mac-libcxx-relpath.cpp
@@ -12,6 +12,11 @@
// RUN: cp "%s" "%t/test.cpp"
// clang-check will produce an error code if the mock library is not found.
// RUN: clang-check -p "%t" "%t/test.cpp"
+//
+// Resolve a driver without a path through PATH.
+// RUN: chmod +x %t/mock-libcxx/bin/clang
+// RUN: echo '[{"directory":"%t","command":"clang -stdlib=libc++ -target x86_64-apple-darwin -c test.cpp","file":"test.cpp"}]' | sed -e 's/\\/\//g' > %t/compile_commands.json
+// RUN: env "PATH=%t/mock-libcxx/bin%{pathsep}%PATH%" clang-check -p "%t" "%t/test.cpp"
#include <mock_vector>
vector v;
More information about the cfe-commits
mailing list