1//===--- NoIntToPtrCheck.cpp - clang-tidy ---------------------------------===//
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-exception
6//
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(NodeMatch: castExpr(hasCastKind(Kind: CK_IntegralToPointer),
18 unless(hasSourceExpression(InnerMatcher: integerLiteral())))
19 .bind(ID: "x"),
20 Action: this);
21}
22
23void NoIntToPtrCheck::check(const MatchFinder::MatchResult &Result) {
24 const auto *MatchedCast = Result.Nodes.getNodeAs<CastExpr>(ID: "x");
25 diag(MatchedCast->getBeginLoc(),
26 "integer to pointer cast pessimizes optimization opportunities");
27}
28
29} // namespace clang::tidy::performance
30

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.cpp