diff options
Diffstat (limited to 'clang-tools-extra/clang-tidy/android')
4 files changed, 72 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp b/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp index 33c12d1cc05..800c27ac734 100644 --- a/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp @@ -13,6 +13,7 @@ #include "CloexecAccept4Check.h" #include "CloexecAcceptCheck.h" #include "CloexecCreatCheck.h" +#include "CloexecEpollCreate1Check.h" #include "CloexecDupCheck.h" #include "CloexecFopenCheck.h" #include "CloexecInotifyInit1Check.h" @@ -34,6 +35,8 @@ public: CheckFactories.registerCheck<CloexecAccept4Check>("android-cloexec-accept4"); CheckFactories.registerCheck<CloexecAcceptCheck>("android-cloexec-accept"); CheckFactories.registerCheck<CloexecCreatCheck>("android-cloexec-creat"); + CheckFactories.registerCheck<CloexecEpollCreate1Check>( + "android-cloexec-epoll-create1"); CheckFactories.registerCheck<CloexecDupCheck>("android-cloexec-dup"); CheckFactories.registerCheck<CloexecFopenCheck>("android-cloexec-fopen"); CheckFactories.registerCheck<CloexecInotifyInitCheck>( diff --git a/clang-tools-extra/clang-tidy/android/CMakeLists.txt b/clang-tools-extra/clang-tidy/android/CMakeLists.txt index 15228401d1a..17bf2cd7a4a 100644 --- a/clang-tools-extra/clang-tidy/android/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/android/CMakeLists.txt @@ -6,6 +6,7 @@ add_clang_library(clangTidyAndroidModule CloexecAcceptCheck.cpp CloexecCheck.cpp CloexecCreatCheck.cpp + CloexecEpollCreate1Check.cpp CloexecDupCheck.cpp CloexecFopenCheck.cpp CloexecInotifyInit1Check.cpp diff --git a/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.cpp b/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.cpp new file mode 100644 index 00000000000..a42476220e8 --- /dev/null +++ b/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.cpp @@ -0,0 +1,33 @@ +//===--- CloexecEpollCreate1Check.cpp - clang-tidy-------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "CloexecEpollCreate1Check.h" +#include "../utils/ASTUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang { +namespace tidy { +namespace android { + +void CloexecEpollCreate1Check::registerMatchers(MatchFinder *Finder) { + registerMatchersImpl( + Finder, functionDecl(returns(isInteger()), hasName("epoll_create1"), + hasParameter(0, hasType(isInteger())))); +} + +void CloexecEpollCreate1Check::check(const MatchFinder::MatchResult &Result) { + insertMacroFlag(Result, /*MarcoFlag=*/"EPOLL_CLOEXEC", /*ArgPos=*/0); +} + +} // namespace android +} // namespace tidy +} // namespace clang diff --git a/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.h b/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.h new file mode 100644 index 00000000000..9890d5f0b0a --- /dev/null +++ b/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.h @@ -0,0 +1,35 @@ +//===--- CloexecEpollCreate1Check.h - clang-tidy-----------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H + +#include "CloexecCheck.h" + +namespace clang { +namespace tidy { +namespace android { + +/// Finds code that uses epoll_create1() without using the EPOLL_CLOEXEC flag. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-epoll-create1.html +class CloexecEpollCreate1Check : public CloexecCheck { +public: + CloexecEpollCreate1Check(StringRef Name, ClangTidyContext *Context) + : CloexecCheck(Name, Context) {} + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; +}; + +} // namespace android +} // namespace tidy +} // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H |