CloexecEpollCreateCheck.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. //===--- CloexecEpollCreateCheck.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. #include "CloexecEpollCreateCheck.h"
  9. #include "clang/AST/ASTContext.h"
  10. #include "clang/ASTMatchers/ASTMatchFinder.h"
  11. using namespace clang::ast_matchers;
  12. namespace clang::tidy::android {
  13. void CloexecEpollCreateCheck::registerMatchers(MatchFinder *Finder) {
  14. registerMatchersImpl(
  15. Finder, functionDecl(returns(isInteger()), hasName("epoll_create"),
  16. hasParameter(0, hasType(isInteger()))));
  17. }
  18. void CloexecEpollCreateCheck::check(const MatchFinder::MatchResult &Result) {
  19. replaceFunc(Result,
  20. "prefer epoll_create() to epoll_create1() "
  21. "because epoll_create1() allows "
  22. "EPOLL_CLOEXEC",
  23. "epoll_create1(EPOLL_CLOEXEC)");
  24. }
  25. } // namespace clang::tidy::android