diff options
author | thegeorg <thegeorg@yandex-team.com> | 2024-03-13 13:58:24 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2024-03-13 14:11:53 +0300 |
commit | 11a895b7e15d1c5a1f52706396b82e3f9db953cb (patch) | |
tree | fabc6d883b0f946151f61ae7865cee9f529a1fdd /contrib/libs/clang16/tools/extra/clang-tidy/darwin | |
parent | 9685917341315774aad5733b1793b1e533a88bbb (diff) | |
download | ydb-11a895b7e15d1c5a1f52706396b82e3f9db953cb.tar.gz |
Export clang-format16 via ydblib project
6e6be3a95868fde888d801b7590af4044049563f
Diffstat (limited to 'contrib/libs/clang16/tools/extra/clang-tidy/darwin')
6 files changed, 228 insertions, 0 deletions
diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/darwin/AvoidSpinlockCheck.cpp b/contrib/libs/clang16/tools/extra/clang-tidy/darwin/AvoidSpinlockCheck.cpp new file mode 100644 index 0000000000..8864fdb786 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/darwin/AvoidSpinlockCheck.cpp @@ -0,0 +1,32 @@ +//===--- AvoidSpinlockCheck.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 "AvoidSpinlockCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::darwin { + +void AvoidSpinlockCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher( + callExpr(callee((functionDecl(hasAnyName( + "OSSpinlockLock", "OSSpinlockUnlock", "OSSpinlockTry"))))) + .bind("spinlock"), + this); +} + +void AvoidSpinlockCheck::check(const MatchFinder::MatchResult &Result) { + const auto *MatchedExpr = Result.Nodes.getNodeAs<CallExpr>("spinlock"); + diag(MatchedExpr->getBeginLoc(), + "use os_unfair_lock_lock() or dispatch queue APIs instead of the " + "deprecated OSSpinLock"); +} + +} // namespace clang::tidy::darwin diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/darwin/AvoidSpinlockCheck.h b/contrib/libs/clang16/tools/extra/clang-tidy/darwin/AvoidSpinlockCheck.h new file mode 100644 index 0000000000..727878b258 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/darwin/AvoidSpinlockCheck.h @@ -0,0 +1,31 @@ +//===--- AvoidSpinlockCheck.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_DARWIN_AVOIDSPINLOCKCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_DARWIN_AVOIDSPINLOCKCHECK_H + +#include "../ClangTidyCheck.h" + +namespace clang::tidy::darwin { + +/// Finds usages of OSSpinlock, which is deprecated due to potential livelock +/// problems. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/darwin/avoid-spinlock.html +class AvoidSpinlockCheck : public ClangTidyCheck { + public: + AvoidSpinlockCheck(StringRef Name, ClangTidyContext *Context) + : ClangTidyCheck(Name, Context) {} + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; +}; + +} // namespace clang::tidy::darwin + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_DARWIN_AVOIDSPINLOCKCHECK_H diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/darwin/DarwinTidyModule.cpp b/contrib/libs/clang16/tools/extra/clang-tidy/darwin/DarwinTidyModule.cpp new file mode 100644 index 0000000000..3475deada4 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/darwin/DarwinTidyModule.cpp @@ -0,0 +1,38 @@ +//===--- MiscTidyModule.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 "AvoidSpinlockCheck.h" +#include "DispatchOnceNonstaticCheck.h" + +namespace clang::tidy { +namespace darwin { + +class DarwinModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck<AvoidSpinlockCheck>( + "darwin-avoid-spinlock"); + CheckFactories.registerCheck<DispatchOnceNonstaticCheck>( + "darwin-dispatch-once-nonstatic"); + } +}; + +} // namespace darwin + +// Register the DarwinTidyModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add<darwin::DarwinModule> + X("darwin-module", "Adds Darwin-specific lint checks."); + +// This anchor is used to force the linker to link in the generated object file +// and thus register the DarwinModule. +volatile int DarwinModuleAnchorSource = 0; + +} // namespace clang::tidy diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/darwin/DispatchOnceNonstaticCheck.cpp b/contrib/libs/clang16/tools/extra/clang-tidy/darwin/DispatchOnceNonstaticCheck.cpp new file mode 100644 index 0000000000..75d38a9724 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/darwin/DispatchOnceNonstaticCheck.cpp @@ -0,0 +1,58 @@ +//===--- DispatchOnceNonstaticCheck.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 "DispatchOnceNonstaticCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Basic/Diagnostic.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::darwin { + +void DispatchOnceNonstaticCheck::registerMatchers(MatchFinder *Finder) { + // Find variables without static or global storage. VarDecls do not include + // struct/class members, which are FieldDecls. + Finder->addMatcher( + varDecl(hasLocalStorage(), hasType(asString("dispatch_once_t"))) + .bind("non-static-var"), + this); + + // Members of structs or classes might be okay, if the use is at static or + // global scope. These will be ignored for now. But ObjC ivars can be + // flagged immediately, since they cannot be static. + Finder->addMatcher( + objcIvarDecl(hasType(asString("dispatch_once_t"))).bind("ivar"), this); +} + +void DispatchOnceNonstaticCheck::check(const MatchFinder::MatchResult &Result) { + if (const auto *VD = Result.Nodes.getNodeAs<VarDecl>("non-static-var")) { + if (const auto *PD = dyn_cast<ParmVarDecl>(VD)) { + // Catch function/method parameters, as any dispatch_once_t should be + // passed by pointer instead. + diag(PD->getTypeSpecStartLoc(), + "dispatch_once_t variables must have static or global storage " + "duration; function parameters should be pointer references"); + } else { + diag(VD->getTypeSpecStartLoc(), "dispatch_once_t variables must have " + "static or global storage duration") + << FixItHint::CreateInsertion(VD->getTypeSpecStartLoc(), "static "); + } + } + + if (const auto *D = Result.Nodes.getNodeAs<ObjCIvarDecl>("ivar")) { + diag(D->getTypeSpecStartLoc(), + "dispatch_once_t variables must have static or global storage " + "duration and cannot be Objective-C instance variables"); + } +} + +} // namespace clang::tidy::darwin diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/darwin/DispatchOnceNonstaticCheck.h b/contrib/libs/clang16/tools/extra/clang-tidy/darwin/DispatchOnceNonstaticCheck.h new file mode 100644 index 0000000000..ddf6dfa22c --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/darwin/DispatchOnceNonstaticCheck.h @@ -0,0 +1,31 @@ +//===--- DispatchOnceNonstaticCheck.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_DARWIN_DISPATCHONCENONSTATICCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_DARWIN_DISPATCHONCENONSTATICCHECK_H + +#include "../ClangTidyCheck.h" + +namespace clang::tidy::darwin { + +/// Finds variables of type dispatch_once_t that do not have static or global +/// storage duration, as required by the libdispatch documentation. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/darwin/dispatch-once-nonstatic.html +class DispatchOnceNonstaticCheck : public ClangTidyCheck { +public: + DispatchOnceNonstaticCheck(StringRef Name, ClangTidyContext *Context) + : ClangTidyCheck(Name, Context) {} + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; +}; + +} // namespace clang::tidy::darwin + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_DARWIN_DISPATCHONCENONSTATICCHECK_H diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/darwin/ya.make b/contrib/libs/clang16/tools/extra/clang-tidy/darwin/ya.make new file mode 100644 index 0000000000..1aa16bab8f --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/darwin/ya.make @@ -0,0 +1,38 @@ +# Generated by devtools/yamaker. + +LIBRARY() + +LICENSE(Apache-2.0 WITH LLVM-exception) + +LICENSE_TEXTS(.yandex_meta/licenses.list.txt) + +PEERDIR( + contrib/libs/clang16 + contrib/libs/clang16/include + contrib/libs/clang16/lib + contrib/libs/clang16/lib/AST + contrib/libs/clang16/lib/ASTMatchers + contrib/libs/clang16/lib/Analysis + contrib/libs/clang16/lib/Basic + contrib/libs/clang16/lib/Lex + contrib/libs/clang16/tools/extra/clang-tidy/utils + contrib/libs/llvm16 + contrib/libs/llvm16/lib/Frontend/OpenMP + contrib/libs/llvm16/lib/Support +) + +ADDINCL( + contrib/libs/clang16/tools/extra/clang-tidy/darwin +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + +SRCS( + AvoidSpinlockCheck.cpp + DarwinTidyModule.cpp + DispatchOnceNonstaticCheck.cpp +) + +END() |