clang-tools 20.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
28using namespace clang::ast_matchers;
29
30namespace clang::tidy {
31namespace android {
32
33/// This module is for Android specific checks.
35public:
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");
42 "android-cloexec-epoll-create1");
44 "android-cloexec-epoll-create");
45 CheckFactories.registerCheck<CloexecFopenCheck>("android-cloexec-fopen");
47 "android-cloexec-inotify-init1");
49 "android-cloexec-inotify-init");
51 "android-cloexec-memfd-create");
52 CheckFactories.registerCheck<CloexecOpenCheck>("android-cloexec-open");
53 CheckFactories.registerCheck<CloexecPipeCheck>("android-cloexec-pipe");
54 CheckFactories.registerCheck<CloexecPipe2Check>("android-cloexec-pipe2");
55 CheckFactories.registerCheck<CloexecSocketCheck>("android-cloexec-socket");
57 "android-comparison-in-temp-failure-retry");
58 }
59};
60
61// Register the AndroidTidyModule using this statically initialized variable.
62static ClangTidyModuleRegistry::Add<AndroidModule>
63 X("android-module", "Adds Android platform checks.");
64
65} // namespace android
66
67// This anchor is used to force the linker to link in the generated object file
68// and thus register the AndroidModule.
70
71} // namespace clang::tidy
int X
A collection of ClangTidyCheckFactory instances.
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
This module is for Android specific checks.
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module.
Finds code that uses accept4() without using the SOCK_CLOEXEC flag.
accept() is better to be replaced by accept4().
creat() is better to be replaced by open().
dup() is better to be replaced by fcntl(), which has close-on-exec flag.
Finds code that uses epoll_create1() without using the EPOLL_CLOEXEC flag.
epoll_create() is better to be replaced by epoll_create1().
fopen() is suggested to include "e" in their mode string; like "re" would be better than "r".
Finds code that uses inotify_init1() without using the IN_CLOEXEC flag.
inotify_init() is better to be replaced by inotify_init1().
Finds code that uses memfd_create() without using the MFD_CLOEXEC flag.
Finds code that opens file without using the O_CLOEXEC flag.
Finds code that uses pipe2() without using the O_CLOEXEC flag.
Suggests to replace calls to pipe() with calls to pipe2().
Finds code that uses socket() without using the SOCK_CLOEXEC flag.
Attempts to catch calls to TEMP_FAILURE_RETRY with a top-level comparison operation,...
volatile int AndroidModuleAnchorSource