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