10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 19 void IntegerDivisionCheck::registerMatchers(MatchFinder *Finder) {
20 const auto IntType = hasType(isInteger());
22 const auto BinaryOperators = binaryOperator(anyOf(
23 hasOperatorName(
"%"), hasOperatorName(
"<<"), hasOperatorName(
">>"),
24 hasOperatorName(
"<<"), hasOperatorName(
"^"), hasOperatorName(
"|"),
25 hasOperatorName(
"&"), hasOperatorName(
"||"), hasOperatorName(
"&&"),
26 hasOperatorName(
"<"), hasOperatorName(
">"), hasOperatorName(
"<="),
27 hasOperatorName(
">="), hasOperatorName(
"=="), hasOperatorName(
"!=")));
29 const auto UnaryOperators =
30 unaryOperator(anyOf(hasOperatorName(
"~"), hasOperatorName(
"!")));
32 const auto Exceptions =
33 anyOf(BinaryOperators, conditionalOperator(), binaryConditionalOperator(),
34 callExpr(IntType), explicitCastExpr(IntType), UnaryOperators);
38 hasOperatorName(
"/"), hasLHS(expr(IntType)), hasRHS(expr(IntType)),
40 castExpr(hasCastKind(CK_IntegralToFloating)).bind(
"FloatCast")),
43 hasAncestor(castExpr(equalsBoundNode(
"FloatCast")))))))
48 void IntegerDivisionCheck::check(
const MatchFinder::MatchResult &
Result) {
49 const auto *IntDiv = Result.Nodes.getNodeAs<BinaryOperator>(
"IntDiv");
50 diag(IntDiv->getBeginLoc(),
"result of integer division used in a floating " 51 "point context; possible loss of precision");
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result