CloexecSocketCheck.cpp 1.2 KB

123456789101112131415161718192021222324252627282930
  1. //===--- CloexecSocketCheck.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 "CloexecSocketCheck.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 CloexecSocketCheck::registerMatchers(MatchFinder *Finder) {
  14. registerMatchersImpl(Finder,
  15. functionDecl(isExternC(), returns(isInteger()),
  16. hasName("socket"),
  17. hasParameter(0, hasType(isInteger())),
  18. hasParameter(1, hasType(isInteger())),
  19. hasParameter(2, hasType(isInteger()))));
  20. }
  21. void CloexecSocketCheck::check(const MatchFinder::MatchResult &Result) {
  22. insertMacroFlag(Result, /*MacroFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/1);
  23. }
  24. } // namespace clang::tidy::android