[clang] [Driver] Use range-based for loops (NFC) (PR #146987)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 3 19:29:53 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/146987
Note that LLVM Coding Standards discourages std::for_each and
llvm::for_each unless the callable object already exists.
>From 9a696b94c3ff9aa8bd64305570f1ef9b6d14be19 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 3 Jul 2025 18:24:54 -0700
Subject: [PATCH] [Driver] Use range-based for loops (NFC)
Note that LLVM Coding Standards discourages std::for_each and
llvm::for_each unless the callable object already exists.
---
clang/lib/Driver/ToolChains/HIPAMD.cpp | 11 +++++++----
clang/lib/Driver/ToolChains/HIPSPV.cpp | 11 +++++++----
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index b8f3a70ee827e..5fe0f85ef09af 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -372,19 +372,22 @@ HIPAMDToolChain::getDeviceLibs(const llvm::opt::ArgList &DriverArgs) const {
// Maintain compatability with --hip-device-lib.
auto BCLibArgs = DriverArgs.getAllArgValues(options::OPT_hip_device_lib_EQ);
if (!BCLibArgs.empty()) {
- llvm::for_each(BCLibArgs, [&](StringRef BCName) {
+ for (StringRef BCName : BCLibArgs) {
StringRef FullName;
+ bool Found = false;
for (StringRef LibraryPath : LibraryPaths) {
SmallString<128> Path(LibraryPath);
llvm::sys::path::append(Path, BCName);
FullName = Path;
if (llvm::sys::fs::exists(FullName)) {
BCLibs.emplace_back(FullName);
- return;
+ Found = true;
+ break;
}
}
- getDriver().Diag(diag::err_drv_no_such_file) << BCName;
- });
+ if (!Found)
+ getDriver().Diag(diag::err_drv_no_such_file) << BCName;
+ }
} else {
if (!RocmInstallation->hasDeviceLibrary()) {
getDriver().Diag(diag::err_drv_no_rocm_device_lib) << 0;
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index 7c83ebcface2a..53649ca40d99b 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -226,7 +226,8 @@ HIPSPVToolChain::getDeviceLibs(const llvm::opt::ArgList &DriverArgs) const {
// Maintain compatability with --hip-device-lib.
auto BCLibArgs = DriverArgs.getAllArgValues(options::OPT_hip_device_lib_EQ);
if (!BCLibArgs.empty()) {
- llvm::for_each(BCLibArgs, [&](StringRef BCName) {
+ bool Found = false;
+ for (StringRef BCName : BCLibArgs) {
StringRef FullName;
for (std::string LibraryPath : LibraryPaths) {
SmallString<128> Path(LibraryPath);
@@ -234,11 +235,13 @@ HIPSPVToolChain::getDeviceLibs(const llvm::opt::ArgList &DriverArgs) const {
FullName = Path;
if (llvm::sys::fs::exists(FullName)) {
BCLibs.emplace_back(FullName.str());
- return;
+ Found = true;
+ break;
}
}
- getDriver().Diag(diag::err_drv_no_such_file) << BCName;
- });
+ if (!Found)
+ getDriver().Diag(diag::err_drv_no_such_file) << BCName;
+ }
} else {
// Search device library named as 'hipspv-<triple>.bc'.
auto TT = getTriple().normalize();
More information about the cfe-commits
mailing list