xref: /llvm-project/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp (revision 5ac20c9c2527f9deee70405155798e37ab56b332)
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 "CloexecFopenCheck.h"
18 #include "CloexecInotifyInit1Check.h"
19 #include "CloexecInotifyInitCheck.h"
20 #include "CloexecMemfdCreateCheck.h"
21 #include "CloexecOpenCheck.h"
22 #include "CloexecSocketCheck.h"
23 
24 using namespace clang::ast_matchers;
25 
26 namespace clang {
27 namespace tidy {
28 namespace android {
29 
30 /// This module is for Android specific checks.
31 class AndroidModule : public ClangTidyModule {
32 public:
33   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
34     CheckFactories.registerCheck<CloexecAccept4Check>("android-cloexec-accept4");
35     CheckFactories.registerCheck<CloexecAcceptCheck>("android-cloexec-accept");
36     CheckFactories.registerCheck<CloexecCreatCheck>("android-cloexec-creat");
37     CheckFactories.registerCheck<CloexecDupCheck>("android-cloexec-dup");
38     CheckFactories.registerCheck<CloexecFopenCheck>("android-cloexec-fopen");
39     CheckFactories.registerCheck<CloexecInotifyInitCheck>(
40         "android-cloexec-inotify-init");
41     CheckFactories.registerCheck<CloexecInotifyInit1Check>(
42         "android-cloexec-inotify-init1");
43     CheckFactories.registerCheck<CloexecMemfdCreateCheck>(
44         "android-cloexec-memfd-create");
45     CheckFactories.registerCheck<CloexecOpenCheck>("android-cloexec-open");
46     CheckFactories.registerCheck<CloexecSocketCheck>("android-cloexec-socket");
47   }
48 };
49 
50 // Register the AndroidTidyModule using this statically initialized variable.
51 static ClangTidyModuleRegistry::Add<AndroidModule>
52     X("android-module", "Adds Android platform checks.");
53 
54 } // namespace android
55 
56 // This anchor is used to force the linker to link in the generated object file
57 // and thus register the AndroidModule.
58 volatile int AndroidModuleAnchorSource = 0;
59 
60 } // namespace tidy
61 } // namespace clang
62