Skip to content

Commit 21fb7e6

Browse files
[Driver] Use range-based for loops (NFC) (#146987)
Note that LLVM Coding Standards discourages std::for_each and llvm::for_each unless the callable object already exists.
1 parent add2c58 commit 21fb7e6

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,19 +372,22 @@ HIPAMDToolChain::getDeviceLibs(const llvm::opt::ArgList &DriverArgs) const {
372372
// Maintain compatability with --hip-device-lib.
373373
auto BCLibArgs = DriverArgs.getAllArgValues(options::OPT_hip_device_lib_EQ);
374374
if (!BCLibArgs.empty()) {
375-
llvm::for_each(BCLibArgs, [&](StringRef BCName) {
375+
for (StringRef BCName : BCLibArgs) {
376376
StringRef FullName;
377+
bool Found = false;
377378
for (StringRef LibraryPath : LibraryPaths) {
378379
SmallString<128> Path(LibraryPath);
379380
llvm::sys::path::append(Path, BCName);
380381
FullName = Path;
381382
if (llvm::sys::fs::exists(FullName)) {
382383
BCLibs.emplace_back(FullName);
383-
return;
384+
Found = true;
385+
break;
384386
}
385387
}
386-
getDriver().Diag(diag::err_drv_no_such_file) << BCName;
387-
});
388+
if (!Found)
389+
getDriver().Diag(diag::err_drv_no_such_file) << BCName;
390+
}
388391
} else {
389392
if (!RocmInstallation->hasDeviceLibrary()) {
390393
getDriver().Diag(diag::err_drv_no_rocm_device_lib) << 0;

clang/lib/Driver/ToolChains/HIPSPV.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,22 @@ HIPSPVToolChain::getDeviceLibs(const llvm::opt::ArgList &DriverArgs) const {
226226
// Maintain compatability with --hip-device-lib.
227227
auto BCLibArgs = DriverArgs.getAllArgValues(options::OPT_hip_device_lib_EQ);
228228
if (!BCLibArgs.empty()) {
229-
llvm::for_each(BCLibArgs, [&](StringRef BCName) {
229+
bool Found = false;
230+
for (StringRef BCName : BCLibArgs) {
230231
StringRef FullName;
231232
for (std::string LibraryPath : LibraryPaths) {
232233
SmallString<128> Path(LibraryPath);
233234
llvm::sys::path::append(Path, BCName);
234235
FullName = Path;
235236
if (llvm::sys::fs::exists(FullName)) {
236237
BCLibs.emplace_back(FullName.str());
237-
return;
238+
Found = true;
239+
break;
238240
}
239241
}
240-
getDriver().Diag(diag::err_drv_no_such_file) << BCName;
241-
});
242+
if (!Found)
243+
getDriver().Diag(diag::err_drv_no_such_file) << BCName;
244+
}
242245
} else {
243246
// Search device library named as 'hipspv-<triple>.bc'.
244247
auto TT = getTriple().normalize();

0 commit comments

Comments
 (0)