// Match [=!]= with a zero on one side and a string.find on the other.
binaryOperator(
hasAnyOperatorName("==", "!="),
- hasEitherOperand(ignoringParenImpCasts(ZeroLiteral)),
- hasEitherOperand(ignoringParenImpCasts(StringFind.bind("findexpr"))))
+ hasOperands(ignoringParenImpCasts(ZeroLiteral),
+ ignoringParenImpCasts(StringFind.bind("findexpr"))))
.bind("expr"),
this);
}
if (WarnOnSizeOfCompareToConstant) {
Finder->addMatcher(
binaryOperator(matchers::isRelationalOperator(),
- hasEitherOperand(ignoringParenImpCasts(SizeOfExpr)),
- hasEitherOperand(ignoringParenImpCasts(
- anyOf(integerLiteral(equals(0)),
- integerLiteral(isBiggerThan(0x80000))))))
+ hasOperands(ignoringParenImpCasts(SizeOfExpr),
+ ignoringParenImpCasts(anyOf(
+ integerLiteral(equals(0)),
+ integerLiteral(isBiggerThan(0x80000))))))
.bind("sizeof-compare-constant"),
this);
}
Finder->addMatcher(
binaryOperator(hasOperatorName("*"),
- hasEitherOperand(ignoringParenImpCasts(SizeOfExpr)),
- hasEitherOperand(ignoringParenImpCasts(binaryOperator(
- hasOperatorName("*"),
- hasEitherOperand(ignoringParenImpCasts(SizeOfExpr))))))
+ hasOperands(ignoringParenImpCasts(SizeOfExpr),
+ ignoringParenImpCasts(binaryOperator(
+ hasOperatorName("*"),
+ hasEitherOperand(
+ ignoringParenImpCasts(SizeOfExpr))))))
.bind("sizeof-multiply-sizeof"),
this);
Finder->addMatcher(
binaryOperator(
hasAnyOperatorName("==", "!=", "<", "<=", ">", ">=", "+", "-"),
- hasEitherOperand(expr(anyOf(
- ignoringParenImpCasts(SizeOfExpr),
- ignoringParenImpCasts(binaryOperator(
- hasOperatorName("*"),
- hasEitherOperand(ignoringParenImpCasts(SizeOfExpr))))))),
- hasEitherOperand(ignoringParenImpCasts(PtrDiffExpr)))
+ hasOperands(expr(anyOf(ignoringParenImpCasts(SizeOfExpr),
+ ignoringParenImpCasts(binaryOperator(
+ hasOperatorName("*"),
+ hasEitherOperand(
+ ignoringParenImpCasts(SizeOfExpr)))))),
+ ignoringParenImpCasts(PtrDiffExpr)))
.bind("sizeof-in-ptr-arithmetic-mul"),
this);
this);
Finder->addMatcher(
- binaryOperator(hasAnyOperatorName("+", "|"),
- hasEitherOperand(
- expr(hasType(isInteger()), unless(enumExpr("", "")))),
- hasEitherOperand(enumExpr("enumExpr", "enumDecl"))),
+ binaryOperator(
+ hasAnyOperatorName("+", "|"),
+ hasOperands(expr(hasType(isInteger()), unless(enumExpr("", ""))),
+ enumExpr("enumExpr", "enumDecl"))),
this);
Finder->addMatcher(binaryOperator(hasAnyOperatorName("|=", "+="),
has(ignoringParenImpCasts(integerLiteral(unless(equals(0)))))),
characterLiteral(), cxxBoolLiteral()));
- Finder->addMatcher(binaryOperator(isComparisonOperator(),
- hasEitherOperand(StringCompareCallExpr),
- hasEitherOperand(InvalidLiteral))
- .bind("invalid-comparison"),
- this);
+ Finder->addMatcher(
+ binaryOperator(isComparisonOperator(),
+ hasOperands(StringCompareCallExpr, InvalidLiteral))
+ .bind("invalid-comparison"),
+ this);
}
void SuspiciousStringCompareCheck::check(
matchBinOpIntegerConstantExpr(StringRef Id) {
const auto BinOpCstExpr =
expr(anyOf(binaryOperator(hasAnyOperatorName("+", "|", "&"),
- hasEitherOperand(matchSymbolicExpr(Id)),
- hasEitherOperand(matchIntegerConstantExpr(Id))),
+ hasOperands(matchSymbolicExpr(Id),
+ matchIntegerConstantExpr(Id))),
binaryOperator(hasOperatorName("-"),
hasLHS(matchSymbolicExpr(Id)),
hasRHS(matchIntegerConstantExpr(Id)))))
// Match expressions like: (X << 8) & 0xFF
Finder->addMatcher(
- binaryOperator(hasOperatorName("&"),
- hasEitherOperand(ignoringParenImpCasts(binaryOperator(
- hasOperatorName("<<"),
- hasRHS(ignoringParenImpCasts(
- integerLiteral().bind("shift-const")))))),
- hasEitherOperand(ignoringParenImpCasts(
- integerLiteral().bind("and-const"))))
+ binaryOperator(
+ hasOperatorName("&"),
+ hasOperands(
+ ignoringParenImpCasts(
+ binaryOperator(hasOperatorName("<<"),
+ hasRHS(ignoringParenImpCasts(
+ integerLiteral().bind("shift-const"))))),
+ ignoringParenImpCasts(integerLiteral().bind("and-const"))))
.bind("left-right-shift-confusion"),
this);
// Match expressions like: x <op> 0xFF == 0xF00.
Finder->addMatcher(binaryOperator(isComparisonOperator(),
- hasEitherOperand(BinOpCstLeft),
- hasEitherOperand(CstRight))
+ hasOperands(BinOpCstLeft, CstRight))
.bind("binop-const-compare-to-const"),
this);
const auto PointerCondition = castExpr(hasCastKind(CK_PointerToBoolean),
hasSourceExpression(PointerExpr));
- const auto BinaryPointerCheckCondition =
- binaryOperator(hasEitherOperand(castExpr(hasCastKind(CK_NullToPointer))),
- hasEitherOperand(PointerExpr));
+ const auto BinaryPointerCheckCondition = binaryOperator(
+ hasOperands(castExpr(hasCastKind(CK_NullToPointer)), PointerExpr));
Finder->addMatcher(
ifStmt(hasCondition(anyOf(PointerCondition, BinaryPointerCheckCondition)),
// Matches against nullptr.
Finder->addMatcher(
binaryOperator(hasAnyOperatorName("==", "!="),
- hasEitherOperand(ignoringImpCasts(
- anyOf(cxxNullPtrLiteralExpr(), gnuNullExpr(),
- integerLiteral(equals(0))))),
- hasEitherOperand(callToGet(knownSmartptr()))),
+ hasOperands(ignoringImpCasts(anyOf(
+ cxxNullPtrLiteralExpr(), gnuNullExpr(),
+ integerLiteral(equals(0)))),
+ callToGet(knownSmartptr()))),
Callback);
// FIXME: Match and fix if (l.get() == r.get()).
// Third and fourth case: str.compare(str) == 0 and str.compare(str) != 0.
Finder->addMatcher(
binaryOperator(hasAnyOperatorName("==", "!="),
- hasEitherOperand(StrCompare.bind("compare")),
- hasEitherOperand(integerLiteral(equals(0)).bind("zero")))
+ hasOperands(StrCompare.bind("compare"),
+ integerLiteral(equals(0)).bind("zero")))
.bind("match2"),
this);
}