[clang] [clang][Driver] NFC: Share -B and --ld-path lookup helpers (PR #238477)

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 3 21:49:58 PST 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- clang/include/clang/Driver/CommonArgs.h clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChain.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/include/clang/Driver/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h
index da01ccf28..70fff756f 100644
--- a/clang/include/clang/Driver/CommonArgs.h
+++ b/clang/include/clang/Driver/CommonArgs.h
@@ -49,7 +49,7 @@ findProgramInPrefixDirs(StringRef Name, ArrayRef<std::string> PrefixDirs);
 
 std::optional<std::string>
 resolveLdPath(StringRef LdPath,
-              llvm::function_ref<std::string(StringRef)> GetProgramPath);        
+              llvm::function_ref<std::string(StringRef)> GetProgramPath);
 
 void addPathIfExists(const Driver &D, const Twine &Path,
                      ToolChain::path_list &Paths);
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 0c3ce9a4e..6c1e5a98c 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1321,9 +1321,10 @@ std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD) const {
   // -fuse-ld=lld can be used with --ld-path= to inform clang that the binary
   // that --ld-path= points to is lld.
   if (const Arg *A = Args.getLastArg(options::OPT_ld_path_EQ)) {
-    if (std::optional<std::string> Path = tools::resolveLdPath(
-            A->getValue(),
-            [&](StringRef Name) { return GetProgramPath(Name.str().c_str()); })) {
+    if (std::optional<std::string> Path =
+            tools::resolveLdPath(A->getValue(), [&](StringRef Name) {
+              return GetProgramPath(Name.str().c_str());
+            })) {
       if (LinkerIsLLD)
         *LinkerIsLLD = UseLinker == "lld";
       return *Path;
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index cc620d8d4..51c594885 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -127,7 +127,7 @@ tools::findProgramInPrefixDirs(StringRef Name,
 
 std::optional<std::string> tools::resolveLdPath(
     StringRef LdPath,
-    llvm::function_ref<std::string(StringRef)> GetProgramPath) {              
+    llvm::function_ref<std::string(StringRef)> GetProgramPath) {
   std::string Path(LdPath);
   if (Path.empty())
     return std::nullopt;

``````````

</details>


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


More information about the cfe-commits mailing list