llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

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

Author: Zeyi Xu (zeyi2)

<details>
<summary>Changes</summary>

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

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


3 Files Affected:

- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/Tooling/CommonOptionsParser.cpp (+1) 
- (modified) clang/test/Tooling/clang-check-mac-libcxx-relpath.cpp (+5) 


``````````diff
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 9a5a23f3d8542..df0b3df12708e 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -94,6 +94,9 @@ Improvements to clang-query
 Improvements to clang-tidy
 --------------------------
 
+- Improved :program:`clang-tidy` by resolving tool names without a path in
+  compilation databases through ``PATH``.
+
 New checks
 ^^^^^^^^^^
 
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;

``````````

</details>


https://github.com/llvm/llvm-project/pull/213681
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to