CloexecAccept4Check.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. //===--- CloexecAccept4Check.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 "CloexecAccept4Check.h"
  9. #include "../utils/ASTUtils.h"
  10. #include "clang/AST/ASTContext.h"
  11. #include "clang/ASTMatchers/ASTMatchFinder.h"
  12. using namespace clang::ast_matchers;
  13. namespace clang::tidy::android {
  14. void CloexecAccept4Check::registerMatchers(MatchFinder *Finder) {
  15. auto SockAddrPointerType =
  16. hasType(pointsTo(recordDecl(isStruct(), hasName("sockaddr"))));
  17. auto SockLenPointerType = hasType(pointsTo(namedDecl(hasName("socklen_t"))));
  18. registerMatchersImpl(Finder,
  19. functionDecl(returns(isInteger()), hasName("accept4"),
  20. hasParameter(0, hasType(isInteger())),
  21. hasParameter(1, SockAddrPointerType),
  22. hasParameter(2, SockLenPointerType),
  23. hasParameter(3, hasType(isInteger()))));
  24. }
  25. void CloexecAccept4Check::check(const MatchFinder::MatchResult &Result) {
  26. insertMacroFlag(Result, /*MacroFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/3);
  27. }
  28. } // namespace clang::tidy::android