Skip to content

Commit c9e31ca

Browse files
kazutakahirataAnthony Tran
authored andcommitted
[clang] Use llvm::is_contained instead of llvm::all_of (NFC) (llvm#145843)
llvm::is_contained is shorter than llvm::all_of plus a lambda.
1 parent 061a719 commit c9e31ca

File tree

7 files changed

+13
-18
lines changed

7 files changed

+13
-18
lines changed

clang/lib/AST/ExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ CXXConstructExpr::CXXConstructExpr(
12081208

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

12131213
// CXXTemporaryObjectExpr does this itself after setting its TypeSourceInfo.
12141214
if (SC == CXXConstructExprClass)

clang/lib/AST/StmtOpenACC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ OpenACCWaitConstruct *OpenACCWaitConstruct::Create(
209209
ArrayRef<Expr *> QueueIdExprs, SourceLocation RParenLoc, SourceLocation End,
210210
ArrayRef<const OpenACCClause *> Clauses) {
211211

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

214214
void *Mem = C.Allocate(
215215
OpenACCWaitConstruct::totalSizeToAlloc<Expr *, OpenACCClause *>(

clang/lib/Analysis/FlowSensitive/CNFFormula.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ struct CNFFormulaBuilder {
4949
// Contains literals of the simplified clause.
5050
llvm::SmallVector<Literal> Simplified;
5151
for (auto L : Literals) {
52-
assert(L != NullLit &&
53-
llvm::all_of(Simplified, [L](Literal S) { return S != L; }));
52+
assert(L != NullLit && !llvm::is_contained(Simplified, L));
5453
auto X = var(L);
5554
if (trueVars.contains(X)) { // X must be true
5655
if (isPosLit(L))
@@ -103,7 +102,7 @@ CNFFormula::CNFFormula(Variable LargestVar)
103102
}
104103

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

108107
if (lits.empty())
109108
KnownContradictory = true;

clang/lib/Basic/Attributes.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ static constexpr const char *AttrScopeSpellingList[] = {
260260
std::optional<StringRef>
261261
AttributeCommonInfo::tryGetCorrectedScopeName(StringRef ScopeName) const {
262262
if (ScopeName.size() > 0 &&
263-
llvm::none_of(AttrScopeSpellingList,
264-
[&](const char *S) { return S == ScopeName; })) {
263+
!llvm::is_contained(AttrScopeSpellingList, ScopeName)) {
265264
SimpleTypoCorrection STC(ScopeName);
266265
for (const auto &Scope : AttrScopeSpellingList)
267266
STC.add(Scope);
@@ -275,8 +274,7 @@ AttributeCommonInfo::tryGetCorrectedScopeName(StringRef ScopeName) const {
275274
std::optional<StringRef> AttributeCommonInfo::tryGetCorrectedAttrName(
276275
StringRef ScopeName, StringRef AttrName, const TargetInfo &Target,
277276
const LangOptions &LangOpts) const {
278-
if (llvm::none_of(AttrSpellingList,
279-
[&](const char *A) { return A == AttrName; })) {
277+
if (!llvm::is_contained(AttrSpellingList, AttrName)) {
280278
SimpleTypoCorrection STC(AttrName);
281279
for (const auto &Attr : AttrSpellingList)
282280
STC.add(Attr);

clang/lib/Driver/ToolChains/Arch/LoongArch.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,16 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
214214
if (MSIMD == "lsx") {
215215
// Option -msimd=lsx depends on 64-bit FPU.
216216
// -m*-float and -mfpu=none/0/32 conflict with -msimd=lsx.
217-
if (llvm::find(Features, "-d") != Features.end())
217+
if (llvm::is_contained(Features, "-d"))
218218
D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0;
219219
else
220220
Features.push_back("+lsx");
221221
} else if (MSIMD == "lasx") {
222222
// Option -msimd=lasx depends on 64-bit FPU and LSX.
223223
// -m*-float, -mfpu=none/0/32 and -mno-lsx conflict with -msimd=lasx.
224-
if (llvm::find(Features, "-d") != Features.end())
224+
if (llvm::is_contained(Features, "-d"))
225225
D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
226-
else if (llvm::find(Features, "-lsx") != Features.end())
226+
else if (llvm::is_contained(Features, "-lsx"))
227227
D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
228228

229229
// The command options do not contain -mno-lasx.
@@ -232,9 +232,9 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
232232
Features.push_back("+lasx");
233233
}
234234
} else if (MSIMD == "none") {
235-
if (llvm::find(Features, "+lsx") != Features.end())
235+
if (llvm::is_contained(Features, "+lsx"))
236236
Features.push_back("-lsx");
237-
if (llvm::find(Features, "+lasx") != Features.end())
237+
if (llvm::is_contained(Features, "+lasx"))
238238
Features.push_back("-lasx");
239239
} else {
240240
D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;

clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ TEST(DependencyScanner, ScanDepsWithModuleLookup) {
299299
ScanTool.getDependencyFile(CommandLine, CWD).moveInto(DepFile),
300300
llvm::Failed());
301301

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

clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,8 +1657,7 @@ void clang::EmitClangDiagsEnums(const RecordKeeper &Records, raw_ostream &OS,
16571657

16581658
llvm::SmallVector<std::string> EnumeratorNames;
16591659
for (auto &Enumerator : Enumeration.second) {
1660-
if (llvm::find(EnumeratorNames, Enumerator.second) !=
1661-
EnumeratorNames.end())
1660+
if (llvm::is_contained(EnumeratorNames, Enumerator.second))
16621661
PrintError(&R,
16631662
"Duplicate enumerator name '" + Enumerator.second + "'");
16641663
EnumeratorNames.push_back(Enumerator.second);

0 commit comments

Comments
 (0)