30 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "NoIntToPtrCheck.h"10#include "clang/ASTMatchers/ASTMatchFinder.h"11 12using namespace clang::ast_matchers;13 14namespace clang::tidy::performance {15 16void NoIntToPtrCheck::registerMatchers(MatchFinder *Finder) {17 Finder->addMatcher(castExpr(hasCastKind(CK_IntegralToPointer),18 unless(hasSourceExpression(integerLiteral())))19 .bind("x"),20 this);21}22 23void NoIntToPtrCheck::check(const MatchFinder::MatchResult &Result) {24 const auto *MatchedCast = Result.Nodes.getNodeAs<CastExpr>("x");25 diag(MatchedCast->getBeginLoc(),26 "integer to pointer cast pessimizes optimization opportunities");27}28 29} // namespace clang::tidy::performance30