[clang] Use llvm::{count,count_if,find_if,all_of,none_of} (NFC)

This commit is contained in:
Kazu Hirata 2021-10-25 09:14:45 -07:00
parent e2b7aabb57
commit 16ceb44e62
17 changed files with 51 additions and 70 deletions

View File

@ -5168,11 +5168,8 @@ QualType ASTContext::getObjCObjectType(
// sorted-and-uniqued list of protocols and the type arguments
// canonicalized.
QualType canonical;
bool typeArgsAreCanonical = std::all_of(effectiveTypeArgs.begin(),
effectiveTypeArgs.end(),
[&](QualType type) {
return type.isCanonical();
});
bool typeArgsAreCanonical = llvm::all_of(
effectiveTypeArgs, [&](QualType type) { return type.isCanonical(); });
bool protocolsSorted = areSortedAndUniqued(protocols);
if (!typeArgsAreCanonical || !protocolsSorted || !baseType.isCanonical()) {
// Determine the canonical type arguments.

View File

@ -11713,11 +11713,11 @@ getNDSWDS(const FunctionDecl *FD, ArrayRef<ParamAttrTy> ParamAttrs) {
assert(!Sizes.empty() && "Unable to determine NDS and WDS.");
// The LS of a function parameter / return value can only be a power
// of 2, starting from 8 bits, up to 128.
assert(std::all_of(Sizes.begin(), Sizes.end(),
[](unsigned Size) {
return Size == 8 || Size == 16 || Size == 32 ||
Size == 64 || Size == 128;
}) &&
assert(llvm::all_of(Sizes,
[](unsigned Size) {
return Size == 8 || Size == 16 || Size == 32 ||
Size == 64 || Size == 128;
}) &&
"Invalid size");
return std::make_tuple(*std::min_element(std::begin(Sizes), std::end(Sizes)),

View File

@ -201,7 +201,7 @@ CodeGenFunction::GenerateVarArgsThunk(llvm::Function *Fn,
Address ThisPtr(&*AI, CGM.getClassPointerAlignment(MD->getParent()));
llvm::BasicBlock *EntryBB = &Fn->front();
llvm::BasicBlock::iterator ThisStore =
std::find_if(EntryBB->begin(), EntryBB->end(), [&](llvm::Instruction &I) {
llvm::find_if(*EntryBB, [&](llvm::Instruction &I) {
return isa<llvm::StoreInst>(I) &&
I.getOperand(0) == ThisPtr.getPointer();
});

View File

@ -1810,8 +1810,8 @@ llvm::GlobalVariable *MicrosoftCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
#endif
}
const std::unique_ptr<VPtrInfo> *VFPtrI = std::find_if(
VFPtrs.begin(), VFPtrs.end(), [&](const std::unique_ptr<VPtrInfo>& VPI) {
const std::unique_ptr<VPtrInfo> *VFPtrI =
llvm::find_if(VFPtrs, [&](const std::unique_ptr<VPtrInfo> &VPI) {
return VPI->FullOffsetInMDC == VPtrOffset;
});
if (VFPtrI == VFPtrs.end()) {

View File

@ -879,10 +879,9 @@ bool Driver::loadConfigFile() {
std::vector<std::string> ConfigFiles =
CLOptions->getAllArgValues(options::OPT_config);
if (ConfigFiles.size() > 1) {
if (!std::all_of(ConfigFiles.begin(), ConfigFiles.end(),
[ConfigFiles](const std::string &s) {
return s == ConfigFiles[0];
})) {
if (!llvm::all_of(ConfigFiles, [ConfigFiles](const std::string &s) {
return s == ConfigFiles[0];
})) {
Diag(diag::err_drv_duplicate_config);
return true;
}

View File

@ -796,9 +796,9 @@ llvm::Error AMDGPUToolChain::getSystemGPUArch(const ArgList &Args,
}
GPUArch = GPUArchs[0];
if (GPUArchs.size() > 1) {
bool AllSame = std::all_of(
GPUArchs.begin(), GPUArchs.end(),
[&](const StringRef &GPUArch) { return GPUArch == GPUArchs.front(); });
bool AllSame = llvm::all_of(GPUArchs, [&](const StringRef &GPUArch) {
return GPUArch == GPUArchs.front();
});
if (!AllSame)
return llvm::createStringError(
std::error_code(), "Multiple AMD GPUs found with different archs");

View File

@ -247,9 +247,7 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple &Triple,
Multilibs.FilterOut([&](const Multilib &M) {
std::vector<std::string> RD = FilePaths(M);
return std::all_of(RD.begin(), RD.end(), [&](std::string P) {
return !getVFS().exists(P);
});
return llvm::all_of(RD, [&](std::string P) { return !getVFS().exists(P); });
});
Multilib::flags_list Flags;

View File

@ -779,8 +779,7 @@ BreakableLineCommentSection::BreakableLineCommentSection(
Lines[i] = Lines[i].ltrim(Blanks);
StringRef IndentPrefix = getLineCommentIndentPrefix(Lines[i], Style);
OriginalPrefix[i] = IndentPrefix;
const unsigned SpacesInPrefix =
std::count(IndentPrefix.begin(), IndentPrefix.end(), ' ');
const unsigned SpacesInPrefix = llvm::count(IndentPrefix, ' ');
// On the first line of the comment section we calculate how many spaces
// are to be added or removed, all lines after that just get only the

View File

@ -39,8 +39,8 @@ bool Preprocessor::isInPrimaryFile() const {
// If there are any stacked lexers, we're in a #include.
assert(IsFileLexer(IncludeMacroStack[0]) &&
"Top level include stack isn't our primary lexer?");
return std::none_of(
IncludeMacroStack.begin() + 1, IncludeMacroStack.end(),
return llvm::none_of(
llvm::drop_begin(IncludeMacroStack),
[&](const IncludeStackInfo &ISI) -> bool { return IsFileLexer(ISI); });
}

View File

@ -6316,13 +6316,12 @@ bool Sema::DiagnoseSwiftName(Decl *D, StringRef Name, SourceLocation Loc,
// might be because we've transformed some of them. Check for potential
// "out" parameters and err on the side of not warning.
unsigned MaybeOutParamCount =
std::count_if(Params.begin(), Params.end(),
[](const ParmVarDecl *Param) -> bool {
QualType ParamTy = Param->getType();
if (ParamTy->isReferenceType() || ParamTy->isPointerType())
return !ParamTy->getPointeeType().isConstQualified();
return false;
});
llvm::count_if(Params, [](const ParmVarDecl *Param) -> bool {
QualType ParamTy = Param->getType();
if (ParamTy->isReferenceType() || ParamTy->isPointerType())
return !ParamTy->getPointeeType().isConstQualified();
return false;
});
ParamCountValid = SwiftParamCount + MaybeOutParamCount >= ParamCount;
}

View File

@ -1384,9 +1384,8 @@ static bool checkMemberDecomposition(Sema &S, ArrayRef<BindingDecl*> Bindings,
DecompType.getQualifiers());
auto DiagnoseBadNumberOfBindings = [&]() -> bool {
unsigned NumFields =
std::count_if(RD->field_begin(), RD->field_end(),
[](FieldDecl *FD) { return !FD->isUnnamedBitfield(); });
unsigned NumFields = llvm::count_if(
RD->fields(), [](FieldDecl *FD) { return !FD->isUnnamedBitfield(); });
assert(Bindings.size() != NumFields);
S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
<< DecompType << (unsigned)Bindings.size() << NumFields << NumFields

View File

@ -485,8 +485,7 @@ bool Sema::LookupTemplateName(LookupResult &Found,
// all language modes, and diagnose the empty lookup in ActOnCallExpr if we
// successfully form a call to an undeclared template-id.
bool AllFunctions =
getLangOpts().CPlusPlus20 &&
std::all_of(Found.begin(), Found.end(), [](NamedDecl *ND) {
getLangOpts().CPlusPlus20 && llvm::all_of(Found, [](NamedDecl *ND) {
return isa<FunctionDecl>(ND->getUnderlyingDecl());
});
if (AllFunctions || (Found.empty() && !IsDependent)) {

View File

@ -7701,24 +7701,17 @@ void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) {
void ASTReader::PrintStats() {
std::fprintf(stderr, "*** AST File Statistics:\n");
unsigned NumTypesLoaded
= TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(),
QualType());
unsigned NumDeclsLoaded
= DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(),
(Decl *)nullptr);
unsigned NumIdentifiersLoaded
= IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(),
IdentifiersLoaded.end(),
(IdentifierInfo *)nullptr);
unsigned NumMacrosLoaded
= MacrosLoaded.size() - std::count(MacrosLoaded.begin(),
MacrosLoaded.end(),
(MacroInfo *)nullptr);
unsigned NumSelectorsLoaded
= SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(),
SelectorsLoaded.end(),
Selector());
unsigned NumTypesLoaded =
TypesLoaded.size() - llvm::count(TypesLoaded, QualType());
unsigned NumDeclsLoaded =
DeclsLoaded.size() - llvm::count(DeclsLoaded, (Decl *)nullptr);
unsigned NumIdentifiersLoaded =
IdentifiersLoaded.size() -
llvm::count(IdentifiersLoaded, (IdentifierInfo *)nullptr);
unsigned NumMacrosLoaded =
MacrosLoaded.size() - llvm::count(MacrosLoaded, (MacroInfo *)nullptr);
unsigned NumSelectorsLoaded =
SelectorsLoaded.size() - llvm::count(SelectorsLoaded, Selector());
if (unsigned TotalNumSLocEntries = getTotalNumSLocs())
std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n",

View File

@ -155,9 +155,8 @@ private:
} // namespace
static CallExpr::arg_range dropDefaultArgs(CallExpr::arg_range Args) {
auto FirstDefaultArg = std::find_if(Args.begin(), Args.end(), [](auto It) {
return isa<CXXDefaultArgExpr>(It);
});
auto FirstDefaultArg =
llvm::find_if(Args, [](auto It) { return isa<CXXDefaultArgExpr>(It); });
return llvm::make_range(Args.begin(), FirstDefaultArg);
}

View File

@ -377,8 +377,8 @@ int main(int Argc, const char **Argv) {
// Handle -cc1 integrated tools, even if -cc1 was expanded from a response
// file.
auto FirstArg = std::find_if(Args.begin() + 1, Args.end(),
[](const char *A) { return A != nullptr; });
auto FirstArg = llvm::find_if(llvm::drop_begin(Args),
[](const char *A) { return A != nullptr; });
if (FirstArg != Args.end() && StringRef(*FirstArg).startswith("-cc1")) {
// If -cc1 came from a response file, remove the EOL sentinels.
if (MarkEOLs) {

View File

@ -496,10 +496,10 @@ void BuiltinNameEmitter::GetOverloads() {
auto Signature = B->getValueAsListOfDefs("Signature");
// Reuse signatures to avoid unnecessary duplicates.
auto it =
std::find_if(SignaturesList.begin(), SignaturesList.end(),
[&](const std::pair<std::vector<Record *>, unsigned> &a) {
return a.first == Signature;
});
llvm::find_if(SignaturesList,
[&](const std::pair<std::vector<Record *>, unsigned> &a) {
return a.first == Signature;
});
unsigned SignIndex;
if (it == SignaturesList.end()) {
VerifySignature(Signature, B);

View File

@ -1914,10 +1914,9 @@ Intrinsic &NeonEmitter::getIntrinsic(StringRef Name, ArrayRef<Type> Types,
continue;
unsigned ArgNum = 0;
bool MatchingArgumentTypes =
std::all_of(Types.begin(), Types.end(), [&](const auto &Type) {
return Type == I.getParamType(ArgNum++);
});
bool MatchingArgumentTypes = llvm::all_of(Types, [&](const auto &Type) {
return Type == I.getParamType(ArgNum++);
});
if (MatchingArgumentTypes)
GoodVec.push_back(&I);