[clang] f5ef2c5 - [clang] Convert for_each to range-based for loops (NFC)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 10 22:39:51 PDT 2022
Author: Kazu Hirata
Date: 2022-06-10T22:39:45-07:00
New Revision: f5ef2c58381fb8056bf919c7a0862bb8d65e1e28
URL: https://github.com/llvm/llvm-project/commit/f5ef2c58381fb8056bf919c7a0862bb8d65e1e28
DIFF: https://github.com/llvm/llvm-project/commit/f5ef2c58381fb8056bf919c7a0862bb8d65e1e28.diff
LOG: [clang] Convert for_each to range-based for loops (NFC)
Added:
Modified:
clang/include/clang/Sema/ParsedTemplate.h
clang/lib/Basic/Targets/AMDGPU.h
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
clang/lib/Driver/ToolChains/HIPAMD.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Sema/ParsedTemplate.h b/clang/include/clang/Sema/ParsedTemplate.h
index 926cec2c547cd..65182d57246ae 100644
--- a/clang/include/clang/Sema/ParsedTemplate.h
+++ b/clang/include/clang/Sema/ParsedTemplate.h
@@ -212,9 +212,9 @@ namespace clang {
}
void Destroy() {
- std::for_each(
- getTemplateArgs(), getTemplateArgs() + NumArgs,
- [](ParsedTemplateArgument &A) { A.~ParsedTemplateArgument(); });
+ for (ParsedTemplateArgument &A :
+ llvm::make_range(getTemplateArgs(), getTemplateArgs() + NumArgs))
+ A.~ParsedTemplateArgument();
this->~TemplateIdAnnotation();
free(this);
}
diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index 4e3db7a181f58..5e73a3cb8019a 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -435,17 +435,17 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
DiagnosticsEngine &Diags) override {
auto TargetIDFeatures =
getAllPossibleTargetIDFeatures(getTriple(), getArchNameAMDGCN(GPUKind));
- llvm::for_each(Features, [&](const auto &F) {
+ for (const auto &F : Features) {
assert(F.front() == '+' || F.front() == '-');
if (F == "+wavefrontsize64")
WavefrontSize = 64;
bool IsOn = F.front() == '+';
StringRef Name = StringRef(F).drop_front();
if (!llvm::is_contained(TargetIDFeatures, Name))
- return;
+ continue;
assert(OffloadArchFeatures.find(Name) == OffloadArchFeatures.end());
OffloadArchFeatures[Name] = IsOn;
- });
+ }
return true;
}
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 123d92664495e..b450f335b5a2a 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -863,10 +863,10 @@ void ROCMToolChain::addClangTargetOptions(
DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
FastRelaxedMath, CorrectSqrt, ABIVer, false));
- llvm::for_each(BCLibs, [&](StringRef BCFile) {
+ for (StringRef BCFile : BCLibs) {
CC1Args.push_back("-mlink-builtin-bitcode");
CC1Args.push_back(DriverArgs.MakeArgString(BCFile));
- });
+ }
}
bool RocmInstallationDetector::checkCommonBitcodeLibs(
diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index fa9b8b64029d5..efcd565b510b7 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -125,9 +125,8 @@ const char *AMDGCN::OpenMPLinker::constructLLVMLinkCommand(
// the device-libs bitcode through that on the way to this llvm-link
SmallVector<std::string, 12> BCLibs =
AMDGPUOpenMPTC.getCommonDeviceLibNames(Args, SubArchName.str());
- llvm::for_each(BCLibs, [&](StringRef BCFile) {
+ for (StringRef BCFile : BCLibs)
CmdArgs.push_back(Args.MakeArgString(BCFile));
- });
}
}
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index bce3e729f7eea..0111477430eb7 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -246,11 +246,11 @@ void HIPAMDToolChain::addClangTargetOptions(
CC1Args.push_back("-fapply-global-visibility-to-externs");
}
- llvm::for_each(getHIPDeviceLibs(DriverArgs), [&](auto BCFile) {
+ for (auto BCFile : getHIPDeviceLibs(DriverArgs)) {
CC1Args.push_back(BCFile.ShouldInternalize ? "-mlink-builtin-bitcode"
: "-mlink-bitcode-file");
CC1Args.push_back(DriverArgs.MakeArgString(BCFile.Path));
- });
+ }
}
llvm::opt::DerivedArgList *
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 24bcb0d47d247..57a034d3c61e9 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -17732,20 +17732,18 @@ void Sema::CheckTCBEnforcement(const SourceLocation CallExprLoc,
// Search through the enforce_tcb and enforce_tcb_leaf attributes to find
// all TCBs the callee is a part of.
llvm::StringSet<> CalleeTCBs;
- for_each(Callee->specific_attrs<EnforceTCBAttr>(),
- [&](const auto *A) { CalleeTCBs.insert(A->getTCBName()); });
- for_each(Callee->specific_attrs<EnforceTCBLeafAttr>(),
- [&](const auto *A) { CalleeTCBs.insert(A->getTCBName()); });
+ for (const auto *A : Callee->specific_attrs<EnforceTCBAttr>())
+ CalleeTCBs.insert(A->getTCBName());
+ for (const auto *A : Callee->specific_attrs<EnforceTCBLeafAttr>())
+ CalleeTCBs.insert(A->getTCBName());
// Go through the TCBs the caller is a part of and emit warnings if Caller
// is in a TCB that the Callee is not.
- for_each(
- Caller->specific_attrs<EnforceTCBAttr>(),
- [&](const auto *A) {
- StringRef CallerTCB = A->getTCBName();
- if (CalleeTCBs.count(CallerTCB) == 0) {
- this->Diag(CallExprLoc, diag::warn_tcb_enforcement_violation)
- << Callee << CallerTCB;
- }
- });
+ for (const auto *A : Caller->specific_attrs<EnforceTCBAttr>()) {
+ StringRef CallerTCB = A->getTCBName();
+ if (CalleeTCBs.count(CallerTCB) == 0) {
+ this->Diag(CallExprLoc, diag::warn_tcb_enforcement_violation)
+ << Callee << CallerTCB;
+ }
+ }
}
diff --git a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
index e1319a4c2e413..ad31107925929 100644
--- a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
@@ -97,12 +97,12 @@ static std::string fileNameToURI(StringRef Filename) {
assert(Iter != End && "Expected there to be a non-root path component.");
// Add the rest of the path components, encoding any reserved characters;
// we skip past the first path component, as it was handled it above.
- std::for_each(++Iter, End, [&Ret](StringRef Component) {
+ for (StringRef Component : llvm::make_range(++Iter, End)) {
// For reasons unknown to me, we may get a backslash with Windows native
// paths for the initial backslash following the drive component, which
// we need to ignore as a URI path part.
if (Component == "\\")
- return;
+ continue;
// Add the separator between the previous path part and the one being
// currently processed.
@@ -112,7 +112,7 @@ static std::string fileNameToURI(StringRef Filename) {
for (char C : Component) {
Ret += percentEncodeURICharacter(C);
}
- });
+ }
return std::string(Ret);
}
@@ -341,14 +341,14 @@ static json::Array createRules(std::vector<const PathDiagnostic *> &Diags,
json::Array Rules;
llvm::StringSet<> Seen;
- llvm::for_each(Diags, [&](const PathDiagnostic *D) {
+ for (const PathDiagnostic *D : Diags) {
StringRef RuleID = D->getCheckerName();
std::pair<llvm::StringSet<>::iterator, bool> P = Seen.insert(RuleID);
if (P.second) {
RuleMapping[RuleID] = Rules.size(); // Maps RuleID to an Array Index.
Rules.push_back(createRule(*D));
}
- });
+ }
return Rules;
}
@@ -368,10 +368,9 @@ static json::Object createRun(const LangOptions &LO,
json::Array Results, Artifacts;
StringMap<unsigned> RuleMapping;
json::Object Tool = createTool(Diags, RuleMapping);
-
- llvm::for_each(Diags, [&](const PathDiagnostic *D) {
+
+ for (const PathDiagnostic *D : Diags)
Results.push_back(createResult(LO, *D, Artifacts, RuleMapping));
- });
return json::Object{{"tool", std::move(Tool)},
{"results", std::move(Results)},
diff --git a/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp b/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
index a69b76a3c9712..de11263efd5aa 100644
--- a/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ b/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -145,14 +145,12 @@ class AdditionalUSRFinder : public RecursiveASTVisitor<AdditionalUSRFinder> {
void handleVarTemplateDecl(const VarTemplateDecl *VTD) {
USRSet.insert(getUSRForDecl(VTD));
USRSet.insert(getUSRForDecl(VTD->getTemplatedDecl()));
- llvm::for_each(VTD->specializations(), [&](const auto *Spec) {
+ for (const auto *Spec : VTD->specializations())
USRSet.insert(getUSRForDecl(Spec));
- });
SmallVector<VarTemplatePartialSpecializationDecl *, 4> PartialSpecs;
VTD->getPartialSpecializations(PartialSpecs);
- llvm::for_each(PartialSpecs, [&](const auto *Spec) {
+ for (const auto *Spec : PartialSpecs)
USRSet.insert(getUSRForDecl(Spec));
- });
}
void addUSRsOfCtorDtors(const CXXRecordDecl *RD) {
More information about the cfe-commits
mailing list