Skip to content

[clang] Use llvm::is_contained instead of llvm::all_of (NFC) #145843

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/AST/ExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ CXXConstructExpr::CXXConstructExpr(

Stmt **TrailingArgs = getTrailingArgs();
llvm::copy(Args, TrailingArgs);
assert(llvm::all_of(Args, [](const Stmt *Arg) { return Arg != nullptr; }));
assert(!llvm::is_contained(Args, nullptr));

// CXXTemporaryObjectExpr does this itself after setting its TypeSourceInfo.
if (SC == CXXConstructExprClass)
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/StmtOpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ OpenACCWaitConstruct *OpenACCWaitConstruct::Create(
ArrayRef<Expr *> QueueIdExprs, SourceLocation RParenLoc, SourceLocation End,
ArrayRef<const OpenACCClause *> Clauses) {

assert(llvm::all_of(QueueIdExprs, [](Expr *E) { return E != nullptr; }));
assert(!llvm::is_contained(QueueIdExprs, nullptr));

void *Mem = C.Allocate(
OpenACCWaitConstruct::totalSizeToAlloc<Expr *, OpenACCClause *>(
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/Analysis/FlowSensitive/CNFFormula.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ struct CNFFormulaBuilder {
// Contains literals of the simplified clause.
llvm::SmallVector<Literal> Simplified;
for (auto L : Literals) {
assert(L != NullLit &&
llvm::all_of(Simplified, [L](Literal S) { return S != L; }));
assert(L != NullLit && !llvm::is_contained(Simplified, L));
auto X = var(L);
if (trueVars.contains(X)) { // X must be true
if (isPosLit(L))
Expand Down Expand Up @@ -103,7 +102,7 @@ CNFFormula::CNFFormula(Variable LargestVar)
}

void CNFFormula::addClause(ArrayRef<Literal> lits) {
assert(llvm::all_of(lits, [](Literal L) { return L != NullLit; }));
assert(!llvm::is_contained(lits, NullLit));

if (lits.empty())
KnownContradictory = true;
Expand Down
6 changes: 2 additions & 4 deletions clang/lib/Basic/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ static constexpr const char *AttrScopeSpellingList[] = {
std::optional<StringRef>
AttributeCommonInfo::tryGetCorrectedScopeName(StringRef ScopeName) const {
if (ScopeName.size() > 0 &&
llvm::none_of(AttrScopeSpellingList,
[&](const char *S) { return S == ScopeName; })) {
!llvm::is_contained(AttrScopeSpellingList, ScopeName)) {
SimpleTypoCorrection STC(ScopeName);
for (const auto &Scope : AttrScopeSpellingList)
STC.add(Scope);
Expand All @@ -275,8 +274,7 @@ AttributeCommonInfo::tryGetCorrectedScopeName(StringRef ScopeName) const {
std::optional<StringRef> AttributeCommonInfo::tryGetCorrectedAttrName(
StringRef ScopeName, StringRef AttrName, const TargetInfo &Target,
const LangOptions &LangOpts) const {
if (llvm::none_of(AttrSpellingList,
[&](const char *A) { return A == AttrName; })) {
if (!llvm::is_contained(AttrSpellingList, AttrName)) {
SimpleTypoCorrection STC(AttrName);
for (const auto &Attr : AttrSpellingList)
STC.add(Attr);
Expand Down
10 changes: 5 additions & 5 deletions clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,16 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
if (MSIMD == "lsx") {
// Option -msimd=lsx depends on 64-bit FPU.
// -m*-float and -mfpu=none/0/32 conflict with -msimd=lsx.
if (llvm::find(Features, "-d") != Features.end())
if (llvm::is_contained(Features, "-d"))
D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0;
else
Features.push_back("+lsx");
} else if (MSIMD == "lasx") {
// Option -msimd=lasx depends on 64-bit FPU and LSX.
// -m*-float, -mfpu=none/0/32 and -mno-lsx conflict with -msimd=lasx.
if (llvm::find(Features, "-d") != Features.end())
if (llvm::is_contained(Features, "-d"))
D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
else if (llvm::find(Features, "-lsx") != Features.end())
else if (llvm::is_contained(Features, "-lsx"))
D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);

// The command options do not contain -mno-lasx.
Expand All @@ -232,9 +232,9 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
Features.push_back("+lasx");
}
} else if (MSIMD == "none") {
if (llvm::find(Features, "+lsx") != Features.end())
if (llvm::is_contained(Features, "+lsx"))
Features.push_back("-lsx");
if (llvm::find(Features, "+lasx") != Features.end())
if (llvm::is_contained(Features, "+lasx"))
Features.push_back("-lasx");
} else {
D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ TEST(DependencyScanner, ScanDepsWithModuleLookup) {
ScanTool.getDependencyFile(CommandLine, CWD).moveInto(DepFile),
llvm::Failed());

EXPECT_TRUE(llvm::find(InterceptFS->StatPaths, OtherPath) ==
InterceptFS->StatPaths.end());
EXPECT_TRUE(!llvm::is_contained(InterceptFS->StatPaths, OtherPath));
EXPECT_EQ(InterceptFS->ReadFiles, std::vector<std::string>{"test.m"});
}

Expand Down
3 changes: 1 addition & 2 deletions clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1657,8 +1657,7 @@ void clang::EmitClangDiagsEnums(const RecordKeeper &Records, raw_ostream &OS,

llvm::SmallVector<std::string> EnumeratorNames;
for (auto &Enumerator : Enumeration.second) {
if (llvm::find(EnumeratorNames, Enumerator.second) !=
EnumeratorNames.end())
if (llvm::is_contained(EnumeratorNames, Enumerator.second))
PrintError(&R,
"Duplicate enumerator name '" + Enumerator.second + "'");
EnumeratorNames.push_back(Enumerator.second);
Expand Down