aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/clang14/tools/extra/clang-tidy/android
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@yandex-team.com>2023-06-29 10:00:50 +0300
committervitalyisaev <vitalyisaev@yandex-team.com>2023-06-29 10:00:50 +0300
commit6ffe9e53658409f212834330e13564e4952558f6 (patch)
tree85b1e00183517648b228aafa7c8fb07f5276f419 /contrib/libs/clang14/tools/extra/clang-tidy/android
parent726057070f9c5a91fc10fde0d5024913d10f1ab9 (diff)
downloadydb-6ffe9e53658409f212834330e13564e4952558f6.tar.gz
YQ Connector: support managed ClickHouse
Со стороны dqrun можно обратиться к инстансу коннектора, который работает на streaming стенде, и извлечь данные из облачного CH.
Diffstat (limited to 'contrib/libs/clang14/tools/extra/clang-tidy/android')
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/AndroidTidyModule.cpp73
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAccept4Check.cpp39
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAccept4Check.h34
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAcceptCheck.cpp46
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAcceptCheck.h34
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCheck.cpp113
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCheck.h104
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCreatCheck.cpp42
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCreatCheck.h34
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecDupCheck.cpp37
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecDupCheck.h35
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreate1Check.cpp32
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreate1Check.h34
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreateCheck.cpp35
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreateCheck.h34
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecFopenCheck.cpp36
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecFopenCheck.h37
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInit1Check.cpp32
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInit1Check.h34
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInitCheck.cpp33
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInitCheck.h34
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecMemfdCreateCheck.cpp31
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecMemfdCreateCheck.h34
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecOpenCheck.cpp43
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecOpenCheck.h39
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipe2Check.cpp33
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipe2Check.h34
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipeCheck.cpp37
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipeCheck.h34
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecSocketCheck.cpp34
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecSocketCheck.h34
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp95
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.h42
-rw-r--r--contrib/libs/clang14/tools/extra/clang-tidy/android/ya.make51
34 files changed, 1473 insertions, 0 deletions
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/AndroidTidyModule.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/AndroidTidyModule.cpp
new file mode 100644
index 0000000000..b24c0d992e
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/AndroidTidyModule.cpp
@@ -0,0 +1,73 @@
+//===--- AndroidTidyModule.cpp - clang-tidy--------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "CloexecAccept4Check.h"
+#include "CloexecAcceptCheck.h"
+#include "CloexecCreatCheck.h"
+#include "CloexecDupCheck.h"
+#include "CloexecEpollCreate1Check.h"
+#include "CloexecEpollCreateCheck.h"
+#include "CloexecFopenCheck.h"
+#include "CloexecInotifyInit1Check.h"
+#include "CloexecInotifyInitCheck.h"
+#include "CloexecMemfdCreateCheck.h"
+#include "CloexecOpenCheck.h"
+#include "CloexecPipe2Check.h"
+#include "CloexecPipeCheck.h"
+#include "CloexecSocketCheck.h"
+#include "ComparisonInTempFailureRetryCheck.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// This module is for Android specific checks.
+class AndroidModule : public ClangTidyModule {
+public:
+ void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+ CheckFactories.registerCheck<CloexecAccept4Check>("android-cloexec-accept4");
+ CheckFactories.registerCheck<CloexecAcceptCheck>("android-cloexec-accept");
+ CheckFactories.registerCheck<CloexecCreatCheck>("android-cloexec-creat");
+ CheckFactories.registerCheck<CloexecDupCheck>("android-cloexec-dup");
+ CheckFactories.registerCheck<CloexecEpollCreate1Check>(
+ "android-cloexec-epoll-create1");
+ CheckFactories.registerCheck<CloexecEpollCreateCheck>(
+ "android-cloexec-epoll-create");
+ CheckFactories.registerCheck<CloexecFopenCheck>("android-cloexec-fopen");
+ CheckFactories.registerCheck<CloexecInotifyInit1Check>(
+ "android-cloexec-inotify-init1");
+ CheckFactories.registerCheck<CloexecInotifyInitCheck>(
+ "android-cloexec-inotify-init");
+ CheckFactories.registerCheck<CloexecMemfdCreateCheck>(
+ "android-cloexec-memfd-create");
+ CheckFactories.registerCheck<CloexecOpenCheck>("android-cloexec-open");
+ CheckFactories.registerCheck<CloexecPipeCheck>("android-cloexec-pipe");
+ CheckFactories.registerCheck<CloexecPipe2Check>("android-cloexec-pipe2");
+ CheckFactories.registerCheck<CloexecSocketCheck>("android-cloexec-socket");
+ CheckFactories.registerCheck<ComparisonInTempFailureRetryCheck>(
+ "android-comparison-in-temp-failure-retry");
+ }
+};
+
+// Register the AndroidTidyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add<AndroidModule>
+ X("android-module", "Adds Android platform checks.");
+
+} // namespace android
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the AndroidModule.
+volatile int AndroidModuleAnchorSource = 0;
+
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAccept4Check.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAccept4Check.cpp
new file mode 100644
index 0000000000..fe1f341fa1
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAccept4Check.cpp
@@ -0,0 +1,39 @@
+//===--- CloexecAccept4Check.cpp - clang-tidy------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecAccept4Check.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecAccept4Check::registerMatchers(MatchFinder *Finder) {
+ auto SockAddrPointerType =
+ hasType(pointsTo(recordDecl(isStruct(), hasName("sockaddr"))));
+ auto SockLenPointerType = hasType(pointsTo(namedDecl(hasName("socklen_t"))));
+
+ registerMatchersImpl(Finder,
+ functionDecl(returns(isInteger()), hasName("accept4"),
+ hasParameter(0, hasType(isInteger())),
+ hasParameter(1, SockAddrPointerType),
+ hasParameter(2, SockLenPointerType),
+ hasParameter(3, hasType(isInteger()))));
+}
+
+void CloexecAccept4Check::check(const MatchFinder::MatchResult &Result) {
+ insertMacroFlag(Result, /*MacroFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/3);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAccept4Check.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAccept4Check.h
new file mode 100644
index 0000000000..21196de33c
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAccept4Check.h
@@ -0,0 +1,34 @@
+//===--- CloexecAccept4Check.h - clang-tidy----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT4_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT4_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// Finds code that uses accept4() without using the SOCK_CLOEXEC flag.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-accept4.html
+class CloexecAccept4Check : public CloexecCheck {
+public:
+ CloexecAccept4Check(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT4_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAcceptCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAcceptCheck.cpp
new file mode 100644
index 0000000000..b79c554170
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAcceptCheck.cpp
@@ -0,0 +1,46 @@
+//===--- CloexecAcceptCheck.cpp - clang-tidy-------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecAcceptCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecAcceptCheck::registerMatchers(MatchFinder *Finder) {
+ auto SockAddrPointerType =
+ hasType(pointsTo(recordDecl(isStruct(), hasName("sockaddr"))));
+ auto SockLenPointerType = hasType(pointsTo(namedDecl(hasName("socklen_t"))));
+
+ registerMatchersImpl(Finder,
+ functionDecl(returns(isInteger()), hasName("accept"),
+ hasParameter(0, hasType(isInteger())),
+ hasParameter(1, SockAddrPointerType),
+ hasParameter(2, SockLenPointerType)));
+}
+
+void CloexecAcceptCheck::check(const MatchFinder::MatchResult &Result) {
+ std::string ReplacementText =
+ (Twine("accept4(") + getSpellingArg(Result, 0) + ", " +
+ getSpellingArg(Result, 1) + ", " + getSpellingArg(Result, 2) +
+ ", SOCK_CLOEXEC)")
+ .str();
+
+ replaceFunc(
+ Result,
+ "prefer accept4() to accept() because accept4() allows SOCK_CLOEXEC",
+ ReplacementText);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAcceptCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAcceptCheck.h
new file mode 100644
index 0000000000..304ac51f3c
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecAcceptCheck.h
@@ -0,0 +1,34 @@
+//===--- CloexecAcceptCheck.h - clang-tidy-----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// accept() is better to be replaced by accept4().
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-accept.html
+class CloexecAcceptCheck : public CloexecCheck {
+public:
+ CloexecAcceptCheck(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCheck.cpp
new file mode 100644
index 0000000000..d373877713
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCheck.cpp
@@ -0,0 +1,113 @@
+//===--- CloexecCheck.cpp - clang-tidy-------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecCheck.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+namespace {
+// Helper function to form the correct string mode for Type3.
+// Build the replace text. If it's string constant, add <Mode> directly in the
+// end of the string. Else, add <Mode>.
+std::string buildFixMsgForStringFlag(const Expr *Arg, const SourceManager &SM,
+ const LangOptions &LangOpts, char Mode) {
+ if (Arg->getBeginLoc().isMacroID())
+ return (Lexer::getSourceText(
+ CharSourceRange::getTokenRange(Arg->getSourceRange()), SM,
+ LangOpts) +
+ " \"" + Twine(Mode) + "\"")
+ .str();
+
+ StringRef SR = cast<StringLiteral>(Arg->IgnoreParenCasts())->getString();
+ return ("\"" + SR + Twine(Mode) + "\"").str();
+}
+} // namespace
+
+const char *CloexecCheck::FuncDeclBindingStr = "funcDecl";
+
+const char *CloexecCheck::FuncBindingStr ="func";
+
+void CloexecCheck::registerMatchersImpl(
+ MatchFinder *Finder, internal::Matcher<FunctionDecl> Function) {
+ // We assume all the checked APIs are C functions.
+ Finder->addMatcher(
+ callExpr(
+ callee(functionDecl(isExternC(), Function).bind(FuncDeclBindingStr)))
+ .bind(FuncBindingStr),
+ this);
+}
+
+void CloexecCheck::insertMacroFlag(const MatchFinder::MatchResult &Result,
+ StringRef MacroFlag, int ArgPos) {
+ const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>(FuncBindingStr);
+ const auto *FlagArg = MatchedCall->getArg(ArgPos);
+ const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>(FuncDeclBindingStr);
+ SourceManager &SM = *Result.SourceManager;
+
+ if (utils::exprHasBitFlagWithSpelling(FlagArg->IgnoreParenCasts(), SM,
+ Result.Context->getLangOpts(),
+ MacroFlag))
+ return;
+
+ SourceLocation EndLoc =
+ Lexer::getLocForEndOfToken(SM.getFileLoc(FlagArg->getEndLoc()), 0, SM,
+ Result.Context->getLangOpts());
+
+ diag(EndLoc, "%0 should use %1 where possible")
+ << FD << MacroFlag
+ << FixItHint::CreateInsertion(EndLoc, (Twine(" | ") + MacroFlag).str());
+}
+
+void CloexecCheck::replaceFunc(const MatchFinder::MatchResult &Result,
+ StringRef WarningMsg, StringRef FixMsg) {
+ const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>(FuncBindingStr);
+ diag(MatchedCall->getBeginLoc(), WarningMsg)
+ << FixItHint::CreateReplacement(MatchedCall->getSourceRange(), FixMsg);
+}
+
+void CloexecCheck::insertStringFlag(
+ const ast_matchers::MatchFinder::MatchResult &Result, const char Mode,
+ const int ArgPos) {
+ const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>(FuncBindingStr);
+ const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>(FuncDeclBindingStr);
+ const auto *ModeArg = MatchedCall->getArg(ArgPos);
+
+ // Check if the <Mode> may be in the mode string.
+ const auto *ModeStr = dyn_cast<StringLiteral>(ModeArg->IgnoreParenCasts());
+ if (!ModeStr || ModeStr->getString().contains(Mode))
+ return;
+
+ std::string ReplacementText = buildFixMsgForStringFlag(
+ ModeArg, *Result.SourceManager, Result.Context->getLangOpts(), Mode);
+
+ diag(ModeArg->getBeginLoc(), "use %0 mode '%1' to set O_CLOEXEC")
+ << FD << std::string(1, Mode)
+ << FixItHint::CreateReplacement(ModeArg->getSourceRange(),
+ ReplacementText);
+}
+
+StringRef CloexecCheck::getSpellingArg(const MatchFinder::MatchResult &Result,
+ int N) const {
+ const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>(FuncBindingStr);
+ const SourceManager &SM = *Result.SourceManager;
+ return Lexer::getSourceText(
+ CharSourceRange::getTokenRange(MatchedCall->getArg(N)->getSourceRange()),
+ SM, Result.Context->getLangOpts());
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCheck.h
new file mode 100644
index 0000000000..336ed56f5b
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCheck.h
@@ -0,0 +1,104 @@
+//===--- CloexecCheck.h - clang-tidy-----------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the declaration of the CloexecCheck class, which is the
+/// base class for all of the close-on-exec checks in Android module.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// The base class for all close-on-exec checks in Android module.
+/// To be specific, there are some functions that need the close-on-exec flag to
+/// prevent the file descriptor leakage on fork+exec and this class provides
+/// utilities to identify and fix these C functions.
+class CloexecCheck : public ClangTidyCheck {
+public:
+ CloexecCheck(StringRef Name, ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context) {}
+
+protected:
+ void
+ registerMatchersImpl(ast_matchers::MatchFinder *Finder,
+ ast_matchers::internal::Matcher<FunctionDecl> Function);
+
+ /// Currently, we have three types of fixes.
+ ///
+ /// Type1 is to insert the necessary macro flag in the flag argument. For
+ /// example, 'O_CLOEXEC' is required in function 'open()', so
+ /// \code
+ /// open(file, O_RDONLY);
+ /// \endcode
+ /// should be
+ /// \code
+ /// open(file, O_RDONLY | O_CLOEXE);
+ /// \endcode
+ ///
+ /// \param [out] Result MatchResult from AST matcher.
+ /// \param MacroFlag The macro name of the flag.
+ /// \param ArgPos The 0-based position of the flag argument.
+ void insertMacroFlag(const ast_matchers::MatchFinder::MatchResult &Result,
+ StringRef MacroFlag, int ArgPos);
+
+ /// Type2 is to replace the API to another function that has required the
+ /// ability. For example:
+ /// \code
+ /// creat(path, mode);
+ /// \endcode
+ /// should be
+ /// \code
+ /// open(path, O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, mode)
+ /// \endcode
+ ///
+ /// \param [out] Result MatchResult from AST matcher.
+ /// \param WarningMsg The warning message.
+ /// \param FixMsg The fix message.
+ void replaceFunc(const ast_matchers::MatchFinder::MatchResult &Result,
+ StringRef WarningMsg, StringRef FixMsg);
+
+ /// Type3 is also to add a flag to the corresponding argument, but this time,
+ /// the flag is some string and each char represents a mode rather than a
+ /// macro. For example, 'fopen' needs char 'e' in its mode argument string, so
+ /// \code
+ /// fopen(in_file, "r");
+ /// \endcode
+ /// should be
+ /// \code
+ /// fopen(in_file, "re");
+ /// \endcode
+ ///
+ /// \param [out] Result MatchResult from AST matcher.
+ /// \param Mode The required mode char.
+ /// \param ArgPos The 0-based position of the flag argument.
+ void insertStringFlag(const ast_matchers::MatchFinder::MatchResult &Result,
+ const char Mode, const int ArgPos);
+
+ /// Helper function to get the spelling of a particular argument.
+ StringRef getSpellingArg(const ast_matchers::MatchFinder::MatchResult &Result,
+ int N) const;
+
+ /// Binding name of the FuncDecl of a function call.
+ static const char *FuncDeclBindingStr;
+
+ /// Binding name of the function call expression.
+ static const char *FuncBindingStr;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCreatCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCreatCheck.cpp
new file mode 100644
index 0000000000..f096884d86
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCreatCheck.cpp
@@ -0,0 +1,42 @@
+//===--- CloexecCreatCheck.cpp - clang-tidy--------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecCreatCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecCreatCheck::registerMatchers(MatchFinder *Finder) {
+ auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter())));
+ auto MODETType = hasType(namedDecl(hasName("mode_t")));
+ registerMatchersImpl(Finder,
+ functionDecl(isExternC(), returns(isInteger()),
+ hasName("creat"),
+ hasParameter(0, CharPointerType),
+ hasParameter(1, MODETType)));
+}
+
+void CloexecCreatCheck::check(const MatchFinder::MatchResult &Result) {
+ const std::string &ReplacementText =
+ (Twine("open (") + getSpellingArg(Result, 0) +
+ ", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, " +
+ getSpellingArg(Result, 1) + ")")
+ .str();
+ replaceFunc(Result,
+ "prefer open() to creat() because open() allows O_CLOEXEC",
+ ReplacementText);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCreatCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCreatCheck.h
new file mode 100644
index 0000000000..cb60e25861
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecCreatCheck.h
@@ -0,0 +1,34 @@
+//===--- CloexecCreatCheck.h - clang-tidy------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_CREAT_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_CREAT_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// creat() is better to be replaced by open().
+/// Find the usage of creat() and redirect user to use open().
+
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-creat.html
+class CloexecCreatCheck : public CloexecCheck {
+public:
+ CloexecCreatCheck(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_CREAT_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecDupCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecDupCheck.cpp
new file mode 100644
index 0000000000..1f068d49f7
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecDupCheck.cpp
@@ -0,0 +1,37 @@
+//===--- CloexecDupCheck.cpp - clang-tidy----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecDupCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecDupCheck::registerMatchers(MatchFinder *Finder) {
+ registerMatchersImpl(Finder,
+ functionDecl(returns(isInteger()), hasName("dup"),
+ hasParameter(0, hasType(isInteger()))));
+}
+
+void CloexecDupCheck::check(const MatchFinder::MatchResult &Result) {
+ std::string ReplacementText =
+ (Twine("fcntl(") + getSpellingArg(Result, 0) + ", F_DUPFD_CLOEXEC)")
+ .str();
+
+ replaceFunc(Result,
+ "prefer fcntl() to dup() because fcntl() allows F_DUPFD_CLOEXEC",
+ ReplacementText);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecDupCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecDupCheck.h
new file mode 100644
index 0000000000..e87c0abbbb
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecDupCheck.h
@@ -0,0 +1,35 @@
+//===--- CloexecDupCheck.h - clang-tidy-------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_DUP_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_DUP_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// dup() is better to be replaced by fcntl(), which has close-on-exec flag.
+/// Find the usage of dup() and redirect user to use fcntl().
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-dup.html
+class CloexecDupCheck : public CloexecCheck {
+public:
+ CloexecDupCheck(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_DUP_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreate1Check.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreate1Check.cpp
new file mode 100644
index 0000000000..8fb175eef6
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreate1Check.cpp
@@ -0,0 +1,32 @@
+//===--- CloexecEpollCreate1Check.cpp - clang-tidy-------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecEpollCreate1Check.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecEpollCreate1Check::registerMatchers(MatchFinder *Finder) {
+ registerMatchersImpl(
+ Finder, functionDecl(returns(isInteger()), hasName("epoll_create1"),
+ hasParameter(0, hasType(isInteger()))));
+}
+
+void CloexecEpollCreate1Check::check(const MatchFinder::MatchResult &Result) {
+ insertMacroFlag(Result, /*MacroFlag=*/"EPOLL_CLOEXEC", /*ArgPos=*/0);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreate1Check.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreate1Check.h
new file mode 100644
index 0000000000..cac2581b9c
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreate1Check.h
@@ -0,0 +1,34 @@
+//===--- CloexecEpollCreate1Check.h - clang-tidy-----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// Finds code that uses epoll_create1() without using the EPOLL_CLOEXEC flag.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-epoll-create1.html
+class CloexecEpollCreate1Check : public CloexecCheck {
+public:
+ CloexecEpollCreate1Check(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreateCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreateCheck.cpp
new file mode 100644
index 0000000000..f1d7edfd12
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreateCheck.cpp
@@ -0,0 +1,35 @@
+//===--- CloexecEpollCreateCheck.cpp - clang-tidy--------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecEpollCreateCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecEpollCreateCheck::registerMatchers(MatchFinder *Finder) {
+ registerMatchersImpl(
+ Finder, functionDecl(returns(isInteger()), hasName("epoll_create"),
+ hasParameter(0, hasType(isInteger()))));
+}
+
+void CloexecEpollCreateCheck::check(const MatchFinder::MatchResult &Result) {
+ replaceFunc(Result,
+ "prefer epoll_create() to epoll_create1() "
+ "because epoll_create1() allows "
+ "EPOLL_CLOEXEC",
+ "epoll_create1(EPOLL_CLOEXEC)");
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreateCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreateCheck.h
new file mode 100644
index 0000000000..8db80c8429
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecEpollCreateCheck.h
@@ -0,0 +1,34 @@
+//===--- CloexecEpollCreateCheck.h - clang-tidy------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// epoll_create() is better to be replaced by epoll_create1().
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-epoll-create.html
+class CloexecEpollCreateCheck : public CloexecCheck {
+public:
+ CloexecEpollCreateCheck(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecFopenCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecFopenCheck.cpp
new file mode 100644
index 0000000000..dc9908b6a4
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecFopenCheck.cpp
@@ -0,0 +1,36 @@
+//===--- CloexecFopenCheck.cpp - clang-tidy--------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecFopenCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecFopenCheck::registerMatchers(MatchFinder *Finder) {
+ auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter())));
+ registerMatchersImpl(Finder,
+ functionDecl(isExternC(), returns(asString("FILE *")),
+ hasName("fopen"),
+ hasParameter(0, CharPointerType),
+ hasParameter(1, CharPointerType)));
+}
+
+void CloexecFopenCheck::check(const MatchFinder::MatchResult &Result) {
+ insertStringFlag(Result, /*Mode=*/'e', /*ArgPos=*/1);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecFopenCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecFopenCheck.h
new file mode 100644
index 0000000000..0b617ffdc3
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecFopenCheck.h
@@ -0,0 +1,37 @@
+//===--- CloexecFopenCheck.h - clang-tidy------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// fopen() is suggested to include "e" in their mode string; like "re" would be
+/// better than "r".
+///
+/// This check only works when corresponding argument is StringLiteral. No
+/// constant propagation.
+///
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-fopen.html
+class CloexecFopenCheck : public CloexecCheck {
+public:
+ CloexecFopenCheck(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInit1Check.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInit1Check.cpp
new file mode 100644
index 0000000000..f0a0b982b3
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInit1Check.cpp
@@ -0,0 +1,32 @@
+//===--- CloexecInotifyInit1Check.cpp - clang-tidy-------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecInotifyInit1Check.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecInotifyInit1Check::registerMatchers(MatchFinder *Finder) {
+ registerMatchersImpl(
+ Finder, functionDecl(returns(isInteger()), hasName("inotify_init1"),
+ hasParameter(0, hasType(isInteger()))));
+}
+
+void CloexecInotifyInit1Check::check(const MatchFinder::MatchResult &Result) {
+ insertMacroFlag(Result, /*MacroFlag=*/"IN_CLOEXEC", /*ArgPos=*/0);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInit1Check.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInit1Check.h
new file mode 100644
index 0000000000..d4a392d3fc
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInit1Check.h
@@ -0,0 +1,34 @@
+//===--- CloexecInotifyInit1Check.h - clang-tidy-----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT1_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT1_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// Finds code that uses inotify_init1() without using the IN_CLOEXEC flag.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-inotify-init1.html
+class CloexecInotifyInit1Check : public CloexecCheck {
+public:
+ CloexecInotifyInit1Check(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT1_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInitCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInitCheck.cpp
new file mode 100644
index 0000000000..e11cbb8b19
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInitCheck.cpp
@@ -0,0 +1,33 @@
+//===--- CloexecInotifyInitCheck.cpp - clang-tidy--------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecInotifyInitCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecInotifyInitCheck::registerMatchers(MatchFinder *Finder) {
+ registerMatchersImpl(
+ Finder, functionDecl(returns(isInteger()), hasName("inotify_init")));
+}
+
+void CloexecInotifyInitCheck::check(const MatchFinder::MatchResult &Result) {
+ replaceFunc(Result, /*WarningMsg=*/
+ "prefer inotify_init() to inotify_init1() "
+ "because inotify_init1() allows IN_CLOEXEC",
+ /*FixMsg=*/"inotify_init1(IN_CLOEXEC)");
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInitCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInitCheck.h
new file mode 100644
index 0000000000..3b6e05749e
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecInotifyInitCheck.h
@@ -0,0 +1,34 @@
+//===--- CloexecInotifyInitCheck.h - clang-tidy------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// inotify_init() is better to be replaced by inotify_init1().
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-inotify-init.html
+class CloexecInotifyInitCheck : public CloexecCheck {
+public:
+ CloexecInotifyInitCheck(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecMemfdCreateCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecMemfdCreateCheck.cpp
new file mode 100644
index 0000000000..6fa606b88a
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecMemfdCreateCheck.cpp
@@ -0,0 +1,31 @@
+//===--- CloexecMemfdCreateCheck.cpp - clang-tidy--------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecMemfdCreateCheck.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecMemfdCreateCheck::registerMatchers(MatchFinder *Finder) {
+ auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter())));
+ registerMatchersImpl(
+ Finder, functionDecl(returns(isInteger()), hasName("memfd_create"),
+ hasParameter(0, CharPointerType),
+ hasParameter(1, hasType(isInteger()))));
+}
+
+void CloexecMemfdCreateCheck::check(const MatchFinder::MatchResult &Result) {
+ insertMacroFlag(Result, "MFD_CLOEXEC", /*ArgPos=*/1);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecMemfdCreateCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecMemfdCreateCheck.h
new file mode 100644
index 0000000000..f429ee5f24
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecMemfdCreateCheck.h
@@ -0,0 +1,34 @@
+//===--- CloexecMemfdCreateCheck.h - clang-tidy-----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_MEMFD_CREATE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_MEMFD_CREATE_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// Finds code that uses memfd_create() without using the MFD_CLOEXEC flag.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-memfd-create.html
+class CloexecMemfdCreateCheck : public CloexecCheck {
+public:
+ CloexecMemfdCreateCheck(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_MEMFD_CREATE_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecOpenCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecOpenCheck.cpp
new file mode 100644
index 0000000000..d0617a336c
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecOpenCheck.cpp
@@ -0,0 +1,43 @@
+//===--- CloexecOpenCheck.cpp - clang-tidy---------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecOpenCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecOpenCheck::registerMatchers(MatchFinder *Finder) {
+ auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter())));
+ registerMatchersImpl(Finder,
+ functionDecl(isExternC(), returns(isInteger()),
+ hasAnyName("open", "open64"),
+ hasParameter(0, CharPointerType),
+ hasParameter(1, hasType(isInteger()))));
+ registerMatchersImpl(Finder,
+ functionDecl(isExternC(), returns(isInteger()),
+ hasName("openat"),
+ hasParameter(0, hasType(isInteger())),
+ hasParameter(1, CharPointerType),
+ hasParameter(2, hasType(isInteger()))));
+}
+
+void CloexecOpenCheck::check(const MatchFinder::MatchResult &Result) {
+ const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>(FuncDeclBindingStr);
+ assert(FD->param_size() > 1);
+ int ArgPos = (FD->param_size() > 2) ? 2 : 1;
+ insertMacroFlag(Result, /*MacroFlag=*/"O_CLOEXEC", ArgPos);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecOpenCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecOpenCheck.h
new file mode 100644
index 0000000000..eb3319c769
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecOpenCheck.h
@@ -0,0 +1,39 @@
+//===--- CloexecOpenCheck.h - clang-tidy-----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// Finds code that opens file without using the O_CLOEXEC flag.
+///
+/// open(), openat(), and open64() had better to include O_CLOEXEC in their
+/// flags argument. Only consider simple cases that the corresponding argument
+/// is constant or binary operation OR among constants like 'O_CLOEXEC' or
+/// 'O_CLOEXEC | O_RDONLY'. No constant propagation is performed.
+///
+/// Only the symbolic 'O_CLOEXEC' macro definition is checked, not the concrete
+/// value.
+class CloexecOpenCheck : public CloexecCheck {
+public:
+ CloexecOpenCheck(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipe2Check.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipe2Check.cpp
new file mode 100644
index 0000000000..7e3107da3b
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipe2Check.cpp
@@ -0,0 +1,33 @@
+//===--- CloexecPipe2Check.cpp - clang-tidy--------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecPipe2Check.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecPipe2Check::registerMatchers(MatchFinder *Finder) {
+ registerMatchersImpl(Finder,
+ functionDecl(returns(isInteger()), hasName("pipe2"),
+ hasParameter(0, hasType(pointsTo(isInteger()))),
+ hasParameter(1, hasType(isInteger()))));
+}
+
+void CloexecPipe2Check::check(const MatchFinder::MatchResult &Result) {
+ insertMacroFlag(Result, /*MacroFlag=*/"O_CLOEXEC", /*ArgPos=*/1);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipe2Check.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipe2Check.h
new file mode 100644
index 0000000000..b58846675c
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipe2Check.h
@@ -0,0 +1,34 @@
+//===--- CloexecPipe2Check.h - clang-tidy------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE2_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE2_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// Finds code that uses pipe2() without using the O_CLOEXEC flag.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-pipe2.html
+class CloexecPipe2Check : public CloexecCheck {
+public:
+ CloexecPipe2Check(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE2_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipeCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipeCheck.cpp
new file mode 100644
index 0000000000..94b9450bd5
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipeCheck.cpp
@@ -0,0 +1,37 @@
+//===--- CloexecPipeCheck.cpp - clang-tidy---------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecPipeCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecPipeCheck::registerMatchers(MatchFinder *Finder) {
+ registerMatchersImpl(Finder,
+ functionDecl(returns(isInteger()), hasName("pipe"),
+ hasParameter(0, hasType(pointsTo(isInteger())))));
+}
+
+void CloexecPipeCheck::check(const MatchFinder::MatchResult &Result) {
+ std::string ReplacementText =
+ (Twine("pipe2(") + getSpellingArg(Result, 0) + ", O_CLOEXEC)").str();
+
+ replaceFunc(
+ Result,
+ "prefer pipe2() with O_CLOEXEC to avoid leaking file descriptors to child processes",
+ ReplacementText);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipeCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipeCheck.h
new file mode 100644
index 0000000000..c89fe79677
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecPipeCheck.h
@@ -0,0 +1,34 @@
+//===--- CloexecPipeCheck.h - clang-tidy-------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// Suggests to replace calls to pipe() with calls to pipe2().
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-pipe.html
+class CloexecPipeCheck : public CloexecCheck {
+public:
+ CloexecPipeCheck(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecSocketCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecSocketCheck.cpp
new file mode 100644
index 0000000000..dd0f62443a
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecSocketCheck.cpp
@@ -0,0 +1,34 @@
+//===--- CloexecSocketCheck.cpp - clang-tidy-------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CloexecSocketCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecSocketCheck::registerMatchers(MatchFinder *Finder) {
+ registerMatchersImpl(Finder,
+ functionDecl(isExternC(), returns(isInteger()),
+ hasName("socket"),
+ hasParameter(0, hasType(isInteger())),
+ hasParameter(1, hasType(isInteger())),
+ hasParameter(2, hasType(isInteger()))));
+}
+
+void CloexecSocketCheck::check(const MatchFinder::MatchResult &Result) {
+ insertMacroFlag(Result, /*MacroFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/1);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecSocketCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecSocketCheck.h
new file mode 100644
index 0000000000..acbfceab3a
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/CloexecSocketCheck.h
@@ -0,0 +1,34 @@
+//===--- CloexecSocketCheck.h - clang-tidy-----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// Finds code that uses socket() without using the SOCK_CLOEXEC flag.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-socket.html
+class CloexecSocketCheck : public CloexecCheck {
+public:
+ CloexecSocketCheck(StringRef Name, ClangTidyContext *Context)
+ : CloexecCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp
new file mode 100644
index 0000000000..c7b9896c64
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp
@@ -0,0 +1,95 @@
+//===--- ComparisonInTempFailureRetryCheck.cpp - clang-tidy----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "../utils/Matchers.h"
+#include "ComparisonInTempFailureRetryCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+ComparisonInTempFailureRetryCheck::ComparisonInTempFailureRetryCheck(
+ StringRef Name, ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context),
+ RawRetryList(Options.get("RetryMacros", "TEMP_FAILURE_RETRY")) {
+ StringRef(RawRetryList).split(RetryMacros, ",", -1, false);
+}
+
+void ComparisonInTempFailureRetryCheck::storeOptions(
+ ClangTidyOptions::OptionMap &Opts) {
+ Options.store(Opts, "RetryMacros", RawRetryList);
+}
+
+void ComparisonInTempFailureRetryCheck::registerMatchers(MatchFinder *Finder) {
+ // Both glibc's and Bionic's TEMP_FAILURE_RETRY macros structurally look like:
+ //
+ // #define TEMP_FAILURE_RETRY(x) ({ \
+ // typeof(x) y; \
+ // do y = (x); \
+ // while (y == -1 && errno == EINTR); \
+ // y; \
+ // })
+ //
+ // (glibc uses `long int` instead of `typeof(x)` for the type of y).
+ //
+ // It's unclear how to walk up the AST from inside the expansion of `x`, and
+ // we need to not complain about things like TEMP_FAILURE_RETRY(foo(x == 1)),
+ // so we just match the assignment of `y = (x)` and inspect `x` from there.
+ Finder->addMatcher(
+ binaryOperator(hasOperatorName("="),
+ hasRHS(ignoringParenCasts(
+ binaryOperator(isComparisonOperator()).bind("inner"))))
+ .bind("outer"),
+ this);
+}
+
+void ComparisonInTempFailureRetryCheck::check(
+ const MatchFinder::MatchResult &Result) {
+ StringRef RetryMacroName;
+ const auto &Node = *Result.Nodes.getNodeAs<BinaryOperator>("outer");
+ if (!Node.getBeginLoc().isMacroID())
+ return;
+
+ const SourceManager &SM = *Result.SourceManager;
+ if (!SM.isMacroArgExpansion(Node.getRHS()->IgnoreParenCasts()->getBeginLoc()))
+ return;
+
+ const LangOptions &Opts = Result.Context->getLangOpts();
+ SourceLocation LocStart = Node.getBeginLoc();
+ while (LocStart.isMacroID()) {
+ SourceLocation Invocation = SM.getImmediateMacroCallerLoc(LocStart);
+ Token Tok;
+ if (!Lexer::getRawToken(SM.getSpellingLoc(Invocation), Tok, SM, Opts,
+ /*IgnoreWhiteSpace=*/true)) {
+ if (Tok.getKind() == tok::raw_identifier &&
+ llvm::is_contained(RetryMacros, Tok.getRawIdentifier())) {
+ RetryMacroName = Tok.getRawIdentifier();
+ break;
+ }
+ }
+
+ LocStart = Invocation;
+ }
+ if (RetryMacroName.empty())
+ return;
+
+ const auto &Inner = *Result.Nodes.getNodeAs<BinaryOperator>("inner");
+ diag(Inner.getOperatorLoc(), "top-level comparison in %0") << RetryMacroName;
+
+ // FIXME: FixIts would be nice, but potentially nontrivial when nested macros
+ // happen, e.g. `TEMP_FAILURE_RETRY(IS_ZERO(foo()))`
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.h
new file mode 100644
index 0000000000..7b000ab2f5
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.h
@@ -0,0 +1,42 @@
+//===--- ComparisonInTempFailureRetryCheck.h - clang-tidy--------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_COMPARISONINTEMPFAILURERETRYCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_COMPARISONINTEMPFAILURERETRYCHECK_H
+
+#include "../ClangTidyCheck.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include <string>
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// Attempts to catch calls to TEMP_FAILURE_RETRY with a top-level comparison
+/// operation, like `TEMP_FAILURE_RETRY(read(...) != N)`. In these cases, the
+/// comparison should go outside of the TEMP_FAILURE_RETRY.
+///
+/// TEMP_FAILURE_RETRY is a macro provided by both glibc and Bionic.
+class ComparisonInTempFailureRetryCheck : public ClangTidyCheck {
+public:
+ ComparisonInTempFailureRetryCheck(StringRef Name, ClangTidyContext *Context);
+ void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+ const std::string RawRetryList;
+ SmallVector<StringRef, 5> RetryMacros;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_COMPARISONINTEMPFAILURERETRYCHECK_H
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/android/ya.make b/contrib/libs/clang14/tools/extra/clang-tidy/android/ya.make
new file mode 100644
index 0000000000..9add57ff67
--- /dev/null
+++ b/contrib/libs/clang14/tools/extra/clang-tidy/android/ya.make
@@ -0,0 +1,51 @@
+# Generated by devtools/yamaker.
+
+LIBRARY()
+
+LICENSE(Apache-2.0 WITH LLVM-exception)
+
+LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
+
+PEERDIR(
+ contrib/libs/clang14
+ contrib/libs/clang14/include
+ contrib/libs/clang14/lib
+ contrib/libs/clang14/lib/AST
+ contrib/libs/clang14/lib/ASTMatchers
+ contrib/libs/clang14/lib/Basic
+ contrib/libs/clang14/lib/Lex
+ contrib/libs/clang14/tools/extra/clang-tidy/utils
+ contrib/libs/llvm14
+ contrib/libs/llvm14/lib/Frontend/OpenMP
+ contrib/libs/llvm14/lib/Support
+)
+
+ADDINCL(
+ contrib/libs/clang14/tools/extra/clang-tidy/android
+)
+
+NO_COMPILER_WARNINGS()
+
+NO_UTIL()
+
+SRCS(
+ AndroidTidyModule.cpp
+ CloexecAccept4Check.cpp
+ CloexecAcceptCheck.cpp
+ CloexecCheck.cpp
+ CloexecCreatCheck.cpp
+ CloexecDupCheck.cpp
+ CloexecEpollCreate1Check.cpp
+ CloexecEpollCreateCheck.cpp
+ CloexecFopenCheck.cpp
+ CloexecInotifyInit1Check.cpp
+ CloexecInotifyInitCheck.cpp
+ CloexecMemfdCreateCheck.cpp
+ CloexecOpenCheck.cpp
+ CloexecPipe2Check.cpp
+ CloexecPipeCheck.cpp
+ CloexecSocketCheck.cpp
+ ComparisonInTempFailureRetryCheck.cpp
+)
+
+END()