xref: /llvm-project/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.cpp (revision 7d2ea6c422d3f5712b7253407005e1a465a76946)
141d29b15SChih-Hung Hsieh //===--- CloexecEpollCreateCheck.cpp - clang-tidy--------------------------===//
241d29b15SChih-Hung Hsieh //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
641d29b15SChih-Hung Hsieh //
741d29b15SChih-Hung Hsieh //===----------------------------------------------------------------------===//
841d29b15SChih-Hung Hsieh 
941d29b15SChih-Hung Hsieh #include "CloexecEpollCreateCheck.h"
1041d29b15SChih-Hung Hsieh #include "clang/AST/ASTContext.h"
1141d29b15SChih-Hung Hsieh #include "clang/ASTMatchers/ASTMatchFinder.h"
1241d29b15SChih-Hung Hsieh 
1341d29b15SChih-Hung Hsieh using namespace clang::ast_matchers;
1441d29b15SChih-Hung Hsieh 
15*7d2ea6c4SCarlos Galvez namespace clang::tidy::android {
1641d29b15SChih-Hung Hsieh 
registerMatchers(MatchFinder * Finder)1741d29b15SChih-Hung Hsieh void CloexecEpollCreateCheck::registerMatchers(MatchFinder *Finder) {
1841d29b15SChih-Hung Hsieh   registerMatchersImpl(
1941d29b15SChih-Hung Hsieh       Finder, functionDecl(returns(isInteger()), hasName("epoll_create"),
2041d29b15SChih-Hung Hsieh                            hasParameter(0, hasType(isInteger()))));
2141d29b15SChih-Hung Hsieh }
2241d29b15SChih-Hung Hsieh 
check(const MatchFinder::MatchResult & Result)2341d29b15SChih-Hung Hsieh void CloexecEpollCreateCheck::check(const MatchFinder::MatchResult &Result) {
2441d29b15SChih-Hung Hsieh   replaceFunc(Result,
2541d29b15SChih-Hung Hsieh               "prefer epoll_create() to epoll_create1() "
2641d29b15SChih-Hung Hsieh               "because epoll_create1() allows "
2741d29b15SChih-Hung Hsieh               "EPOLL_CLOEXEC",
2841d29b15SChih-Hung Hsieh               "epoll_create1(EPOLL_CLOEXEC)");
2941d29b15SChih-Hung Hsieh }
3041d29b15SChih-Hung Hsieh 
31*7d2ea6c4SCarlos Galvez } // namespace clang::tidy::android
32