xref: /llvm-project/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp (revision 04d38c5f527d06e43aad5bba55d2eb2f8131e0f5)
1 //===--- AndroidTidyModule.cpp - clang-tidy--------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "../ClangTidy.h"
11 #include "../ClangTidyModule.h"
12 #include "../ClangTidyModuleRegistry.h"
13 #include "CloexecAccept4Check.h"
14 #include "CloexecAcceptCheck.h"
15 #include "CloexecCreatCheck.h"
16 #include "CloexecDupCheck.h"
17 #include "CloexecEpollCreate1Check.h"
18 #include "CloexecEpollCreateCheck.h"
19 #include "CloexecFopenCheck.h"
20 #include "CloexecInotifyInit1Check.h"
21 #include "CloexecInotifyInitCheck.h"
22 #include "CloexecMemfdCreateCheck.h"
23 #include "CloexecOpenCheck.h"
24 #include "CloexecSocketCheck.h"
25 #include "ComparisonInTempFailureRetryCheck.h"
26 
27 using namespace clang::ast_matchers;
28 
29 namespace clang {
30 namespace tidy {
31 namespace android {
32 
33 /// This module is for Android specific checks.
34 class AndroidModule : public ClangTidyModule {
35 public:
36   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
37     CheckFactories.registerCheck<CloexecAccept4Check>("android-cloexec-accept4");
38     CheckFactories.registerCheck<CloexecAcceptCheck>("android-cloexec-accept");
39     CheckFactories.registerCheck<CloexecCreatCheck>("android-cloexec-creat");
40     CheckFactories.registerCheck<CloexecDupCheck>("android-cloexec-dup");
41     CheckFactories.registerCheck<CloexecEpollCreate1Check>(
42         "android-cloexec-epoll-create1");
43     CheckFactories.registerCheck<CloexecEpollCreateCheck>(
44         "android-cloexec-epoll-create");
45     CheckFactories.registerCheck<CloexecFopenCheck>("android-cloexec-fopen");
46     CheckFactories.registerCheck<CloexecInotifyInit1Check>(
47         "android-cloexec-inotify-init1");
48     CheckFactories.registerCheck<CloexecInotifyInitCheck>(
49         "android-cloexec-inotify-init");
50     CheckFactories.registerCheck<CloexecMemfdCreateCheck>(
51         "android-cloexec-memfd-create");
52     CheckFactories.registerCheck<CloexecOpenCheck>("android-cloexec-open");
53     CheckFactories.registerCheck<CloexecSocketCheck>("android-cloexec-socket");
54     CheckFactories.registerCheck<ComparisonInTempFailureRetryCheck>(
55         "android-comparison-in-temp-failure-retry");
56   }
57 };
58 
59 // Register the AndroidTidyModule using this statically initialized variable.
60 static ClangTidyModuleRegistry::Add<AndroidModule>
61     X("android-module", "Adds Android platform checks.");
62 
63 } // namespace android
64 
65 // This anchor is used to force the linker to link in the generated object file
66 // and thus register the AndroidModule.
67 volatile int AndroidModuleAnchorSource = 0;
68 
69 } // namespace tidy
70 } // namespace clang
71