diff options
Diffstat (limited to 'clang-tools-extra/clang-tidy/android')
4 files changed, 75 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp b/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp index 800c27ac734..aec1007756b 100644 --- a/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp @@ -14,6 +14,7 @@ #include "CloexecAcceptCheck.h" #include "CloexecCreatCheck.h" #include "CloexecEpollCreate1Check.h" +#include "CloexecEpollCreateCheck.h" #include "CloexecDupCheck.h" #include "CloexecFopenCheck.h" #include "CloexecInotifyInit1Check.h" @@ -37,6 +38,8 @@ public: CheckFactories.registerCheck<CloexecCreatCheck>("android-cloexec-creat"); CheckFactories.registerCheck<CloexecEpollCreate1Check>( "android-cloexec-epoll-create1"); + CheckFactories.registerCheck<CloexecEpollCreateCheck>( + "android-cloexec-epoll-create"); 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 17bf2cd7a4a..6b2d45253c2 100644 --- a/clang-tools-extra/clang-tidy/android/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/android/CMakeLists.txt @@ -7,6 +7,7 @@ add_clang_library(clangTidyAndroidModule CloexecCheck.cpp CloexecCreatCheck.cpp CloexecEpollCreate1Check.cpp + CloexecEpollCreateCheck.cpp CloexecDupCheck.cpp CloexecFopenCheck.cpp CloexecInotifyInit1Check.cpp diff --git a/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.cpp new file mode 100644 index 00000000000..7165d24f53f --- /dev/null +++ b/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.cpp @@ -0,0 +1,36 @@ +//===--- CloexecEpollCreateCheck.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 "CloexecEpollCreateCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang { +namespace tidy { +namespace android { + +void CloexecEpollCreateCheck::registerMatchers(MatchFinder *Finder) { + registerMatchersImpl( + Finder, functionDecl(returns(isInteger()), hasName("epoll_create"), + hasParameter(0, hasType(isInteger())))); +} + +void CloexecEpollCreateCheck::check(const MatchFinder::MatchResult &Result) { + replaceFunc(Result, + "prefer epoll_create() to epoll_create1() " + "because epoll_create1() allows " + "EPOLL_CLOEXEC", + "epoll_create1(EPOLL_CLOEXEC)"); +} + +} // namespace android +} // namespace tidy +} // namespace clang diff --git a/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.h b/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.h new file mode 100644 index 00000000000..21d2b2ab3d4 --- /dev/null +++ b/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.h @@ -0,0 +1,35 @@ +//===--- CloexecEpollCreateCheck.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_CREATE_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE_H + +#include "CloexecCheck.h" + +namespace clang { +namespace tidy { +namespace android { + +/// epoll_create() is better to be replaced by epoll_create1(). +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-epoll-create.html +class CloexecEpollCreateCheck : public CloexecCheck { +public: + CloexecEpollCreateCheck(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_CREATE_H |