clang-tools
22.0.0git
llvm-project
clang-tools-extra
clang-tidy
performance
NoIntToPtrCheck.cpp
Go to the documentation of this file.
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-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "
NoIntToPtrCheck.h
"
10
#include "clang/ASTMatchers/ASTMatchFinder.h"
11
12
using namespace
clang::ast_matchers
;
13
14
namespace
clang::tidy::performance
{
15
16
void
NoIntToPtrCheck::registerMatchers
(MatchFinder *Finder) {
17
Finder->addMatcher(castExpr(hasCastKind(CK_IntegralToPointer),
18
unless(hasSourceExpression(integerLiteral())))
19
.bind(
"x"
),
20
this
);
21
}
22
23
void
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::performance
NoIntToPtrCheck.h
clang::tidy::performance::NoIntToPtrCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Definition
NoIntToPtrCheck.cpp:23
clang::tidy::performance::NoIntToPtrCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Definition
NoIntToPtrCheck.cpp:16
clang::ast_matchers
Definition
AbseilMatcher.h:13
clang::tidy::performance
Definition
AvoidEndlCheck.cpp:20
Generated on
for clang-tools by
1.14.0