11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
14 using namespace clang::ast_matchers;
19 void ProBoundsPointerArithmeticCheck::registerMatchers(MatchFinder *
Finder) {
20 if (!getLangOpts().CPlusPlus)
26 anyOf(hasOperatorName(
"+"), hasOperatorName(
"-"),
27 hasOperatorName(
"+="), hasOperatorName(
"-=")),
28 hasType(pointerType()),
29 unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit()))))))
34 unaryOperator(anyOf(hasOperatorName(
"++"), hasOperatorName(
"--")),
35 hasType(pointerType()))
42 hasBase(ignoringImpCasts(
43 anyOf(hasType(pointerType()),
44 hasType(decayedType(hasDecayedType(pointerType())))))))
50 ProBoundsPointerArithmeticCheck::check(
const MatchFinder::MatchResult &
Result) {
51 const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>(
"expr");
53 diag(MatchedExpr->getExprLoc(),
"do not use pointer arithmetic");
std::unique_ptr< ast_matchers::MatchFinder > Finder