-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Driver] Use range-based for loops (NFC) #146987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Driver] Use range-based for loops (NFC) #146987
Conversation
Note that LLVM Coding Standards discourages std::for_each and llvm::for_each unless the callable object already exists.
|
@llvm/pr-subscribers-clang-driver Author: Kazu Hirata (kazutakahirata) ChangesNote that LLVM Coding Standards discourages std::for_each and Full diff: https://github.com/llvm/llvm-project/pull/146987.diff 2 Files Affected:
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();
|
|
@llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) ChangesNote that LLVM Coding Standards discourages std::for_each and Full diff: https://github.com/llvm/llvm-project/pull/146987.diff 2 Files Affected:
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();
|
Note that LLVM Coding Standards discourages std::for_each and
llvm::for_each unless the callable object already exists.