clang-tools  14.0.0git
AndroidTidyModule.cpp
Go to the documentation of this file.
1 //===--- AndroidTidyModule.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 
9 #include "../ClangTidy.h"
10 #include "../ClangTidyModule.h"
11 #include "../ClangTidyModuleRegistry.h"
12 #include "CloexecAccept4Check.h"
13 #include "CloexecAcceptCheck.h"
14 #include "CloexecCreatCheck.h"
15 #include "CloexecDupCheck.h"
18 #include "CloexecFopenCheck.h"
22 #include "CloexecOpenCheck.h"
23 #include "CloexecPipe2Check.h"
24 #include "CloexecPipeCheck.h"
25 #include "CloexecSocketCheck.h"
27 
28 using namespace clang::ast_matchers;
29 
30 namespace clang {
31 namespace tidy {
32 namespace android {
33 
34 /// This module is for Android specific checks.
36 public:
37  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
38  CheckFactories.registerCheck<CloexecAccept4Check>("android-cloexec-accept4");
39  CheckFactories.registerCheck<CloexecAcceptCheck>("android-cloexec-accept");
40  CheckFactories.registerCheck<CloexecCreatCheck>("android-cloexec-creat");
41  CheckFactories.registerCheck<CloexecDupCheck>("android-cloexec-dup");
43  "android-cloexec-epoll-create1");
44  CheckFactories.registerCheck<CloexecEpollCreateCheck>(
45  "android-cloexec-epoll-create");
46  CheckFactories.registerCheck<CloexecFopenCheck>("android-cloexec-fopen");
48  "android-cloexec-inotify-init1");
49  CheckFactories.registerCheck<CloexecInotifyInitCheck>(
50  "android-cloexec-inotify-init");
51  CheckFactories.registerCheck<CloexecMemfdCreateCheck>(
52  "android-cloexec-memfd-create");
53  CheckFactories.registerCheck<CloexecOpenCheck>("android-cloexec-open");
54  CheckFactories.registerCheck<CloexecPipeCheck>("android-cloexec-pipe");
55  CheckFactories.registerCheck<CloexecPipe2Check>("android-cloexec-pipe2");
56  CheckFactories.registerCheck<CloexecSocketCheck>("android-cloexec-socket");
58  "android-comparison-in-temp-failure-retry");
59  }
60 };
61 
62 // Register the AndroidTidyModule using this statically initialized variable.
63 static ClangTidyModuleRegistry::Add<AndroidModule>
64  X("android-module", "Adds Android platform checks.");
65 
66 } // namespace android
67 
68 // This anchor is used to force the linker to link in the generated object file
69 // and thus register the AndroidModule.
70 volatile int AndroidModuleAnchorSource = 0;
71 
72 } // namespace tidy
73 } // namespace clang
clang::tidy::android::CloexecEpollCreate1Check
Finds code that uses epoll_create1() without using the EPOLL_CLOEXEC flag.
Definition: CloexecEpollCreate1Check.h:22
CloexecCreatCheck.h
clang::tidy::android::CloexecCreatCheck
creat() is better to be replaced by open().
Definition: CloexecCreatCheck.h:22
CloexecSocketCheck.h
CloexecFopenCheck.h
ComparisonInTempFailureRetryCheck.h
clang::tidy::android::CloexecPipeCheck
Suggests to replace calls to pipe() with calls to pipe2().
Definition: CloexecPipeCheck.h:22
clang::tidy::android::ComparisonInTempFailureRetryCheck
Attempts to catch calls to TEMP_FAILURE_RETRY with a top-level comparison operation,...
Definition: ComparisonInTempFailureRetryCheck.h:26
CloexecDupCheck.h
clang::tidy::android::CloexecInotifyInit1Check
Finds code that uses inotify_init1() without using the IN_CLOEXEC flag.
Definition: CloexecInotifyInit1Check.h:22
clang::tidy::android::CloexecInotifyInitCheck
inotify_init() is better to be replaced by inotify_init1().
Definition: CloexecInotifyInitCheck.h:22
CloexecPipe2Check.h
clang::ast_matchers
Definition: AbseilMatcher.h:14
clang::tidy::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:28
clang::tidy::android::CloexecAccept4Check
Finds code that uses accept4() without using the SOCK_CLOEXEC flag.
Definition: CloexecAccept4Check.h:22
X
int X
Definition: LSPBinderTests.cpp:25
clang::tidy::android::CloexecPipe2Check
Finds code that uses pipe2() without using the O_CLOEXEC flag.
Definition: CloexecPipe2Check.h:22
clang::tidy::android::AndroidModule::addCheckFactories
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module.
Definition: AndroidTidyModule.cpp:37
clang::tidy::AndroidModuleAnchorSource
volatile int AndroidModuleAnchorSource
Definition: AndroidTidyModule.cpp:70
clang::tidy::android::AndroidModule
This module is for Android specific checks.
Definition: AndroidTidyModule.cpp:35
CloexecInotifyInitCheck.h
CloexecEpollCreate1Check.h
CloexecAcceptCheck.h
clang::tidy::android::CloexecAcceptCheck
accept() is better to be replaced by accept4().
Definition: CloexecAcceptCheck.h:22
CloexecOpenCheck.h
clang::tidy::android::CloexecFopenCheck
fopen() is suggested to include "e" in their mode string; like "re" would be better than "r".
Definition: CloexecFopenCheck.h:25
CloexecMemfdCreateCheck.h
clang::tidy::android::CloexecOpenCheck
Finds code that opens file without using the O_CLOEXEC flag.
Definition: CloexecOpenCheck.h:27
CloexecPipeCheck.h
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
CloexecAccept4Check.h
clang::tidy::android::CloexecEpollCreateCheck
epoll_create() is better to be replaced by epoll_create1().
Definition: CloexecEpollCreateCheck.h:22
clang::tidy::android::CloexecSocketCheck
Finds code that uses socket() without using the SOCK_CLOEXEC flag.
Definition: CloexecSocketCheck.h:22
clang::tidy::android::CloexecMemfdCreateCheck
Finds code that uses memfd_create() without using the MFD_CLOEXEC flag.
Definition: CloexecMemfdCreateCheck.h:22
clang::tidy::android::CloexecDupCheck
dup() is better to be replaced by fcntl(), which has close-on-exec flag.
Definition: CloexecDupCheck.h:23
CloexecEpollCreateCheck.h
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:81
CloexecInotifyInit1Check.h
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:59