clang-tools  9.0.0
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 "CloexecPipeCheck.h"
24 #include "CloexecPipe2Check.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
creat() is better to be replaced by open().
epoll_create() is better to be replaced by epoll_create1().
Finds code that opens file without using the O_CLOEXEC flag.
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
static ClangTidyModuleRegistry::Add< AndroidModule > X("android-module", "Adds Android platform checks.")
volatile int AndroidModuleAnchorSource
A collection of ClangTidyCheckFactory instances.
Attempts to catch calls to TEMP_FAILURE_RETRY with a top-level comparison operation, like TEMP_FAILURE_RETRY(read(...) != N).
inotify_init() is better to be replaced by inotify_init1().
Finds code that uses epoll_create1() without using the EPOLL_CLOEXEC flag.
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Finds code that uses pipe2() without using the O_CLOEXEC flag.
fopen() is suggested to include "e" in their mode string; like "re" would be better than "r"...
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module...
Finds code that uses inotify_init1() without using the IN_CLOEXEC flag.
Finds code that uses accept4() without using the SOCK_CLOEXEC flag.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
accept() is better to be replaced by accept4().
This module is for Android specific checks.
Suggests to replace calls to pipe() with calls to pipe2().
Finds code that uses socket() without using the SOCK_CLOEXEC flag.
Finds code that uses memfd_create() without using the MFD_CLOEXEC flag.
dup() is better to be replaced by fcntl(), which has close-on-exec flag.