diff options
author | Alexander Smirnov <alex@ydb.tech> | 2024-11-23 21:12:15 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-11-23 21:12:15 +0000 |
commit | 94a340fff420b50bea5bb806a5892d03b91036f1 (patch) | |
tree | 7e069e905f29f9ae99d7e2a28baf864b8123648f /library/cpp | |
parent | 398fb410adba8fede893681a5e67a809f02d0750 (diff) | |
parent | 8b9f13e29dea8f76f11579aae5344ac571d5e604 (diff) | |
download | ydb-94a340fff420b50bea5bb806a5892d03b91036f1.tar.gz |
Merge branch 'rightlib' into mergelibs-241123-2111
Diffstat (limited to 'library/cpp')
13 files changed, 12 insertions, 411 deletions
diff --git a/library/cpp/clang_tidy/arcadia_checks/ascii_compare_ignore_case_check.cpp b/library/cpp/clang_tidy/arcadia_checks/ascii_compare_ignore_case_check.cpp deleted file mode 100644 index c24f40bf0d9..00000000000 --- a/library/cpp/clang_tidy/arcadia_checks/ascii_compare_ignore_case_check.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "ascii_compare_ignore_case_check.h" - -#include <contrib/libs/clang16/include/clang/AST/ASTContext.h> -#include <contrib/libs/clang16/include/clang/ASTMatchers/ASTMatchFinder.h> -#include <contrib/libs/clang16/include/clang/Basic/Diagnostic.h> - - -using namespace clang::ast_matchers; - -namespace clang::tidy::arcadia { - - // This check is based on readability-string-compare. - - static const StringRef DiagMessage = - "do not use 'AsciiCompareIgnoreCase' to test case-insensitive equality " - "of strings; use 'AsciiEqualsIgnoreCase' instead"; - - void AsciiCompareIgnoreCaseCheck::registerMatchers(MatchFinder* finder) { - const auto compareMatcher = callExpr( - callee(functionDecl( - hasName("AsciiCompareIgnoreCase"), - parameterCountIs(2) - )) - ); - - // Case 1: AsciiCompareIgnoreCase(...) is casted (maybe implicitly) to boolean. - finder->addMatcher( - traverse( - TK_AsIs, - // Explicit casts also contain an implicit cast inside - implicitCastExpr(hasImplicitDestinationType(booleanType()), has(compareMatcher)) - .bind("match1")), - this); - - // Case 2: AsciiCompareIgnoreCase == 0 (!= 0) - finder->addMatcher( - binaryOperator( - hasAnyOperatorName("==", "!="), - hasOperands( - compareMatcher.bind("compare"), - integerLiteral(equals(0)).bind("zero"))) - .bind("match2"), - this); - } - - void AsciiCompareIgnoreCaseCheck::check(const MatchFinder::MatchResult& result) { - if (const auto* matched = result.Nodes.getNodeAs<Stmt>("match1")) { - diag(matched->getBeginLoc(), DiagMessage); - } else if (const auto* matched = result.Nodes.getNodeAs<Stmt>("match2")) { - const auto* op = cast<BinaryOperator>(matched); - const auto* compareCall = result.Nodes.getNodeAs<CallExpr>("compare"); - const auto* zero = result.Nodes.getNodeAs<Stmt>("zero"); - - const ASTContext &ctx = *result.Context; - auto diagBuilder = diag(matched->getBeginLoc(), DiagMessage); - if (op->getOpcode() == BinaryOperatorKind::BO_NE) { - diagBuilder << FixItHint::CreateInsertion(compareCall->getCallee()->getBeginLoc(), "!"); - } - diagBuilder << FixItHint::CreateReplacement(compareCall->getCallee()->getSourceRange(), "AsciiEqualsIgnoreCase"); - diagBuilder << FixItHint::CreateRemoval(op->getOperatorLoc()); - diagBuilder << FixItHint::CreateRemoval(zero->getSourceRange()); - } - } - -} // namespace clang::tidy::arcadia diff --git a/library/cpp/clang_tidy/arcadia_checks/ascii_compare_ignore_case_check.h b/library/cpp/clang_tidy/arcadia_checks/ascii_compare_ignore_case_check.h deleted file mode 100644 index e6da741aa63..00000000000 --- a/library/cpp/clang_tidy/arcadia_checks/ascii_compare_ignore_case_check.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include <contrib/libs/clang16/tools/extra/clang-tidy/ClangTidyCheck.h> - -namespace clang::tidy::arcadia { - /// Finds uses of AsciiCompareIgnoreCase that can be replaced with AsciiEqualsIgnoreCase. - class AsciiCompareIgnoreCaseCheck : public ClangTidyCheck { - public: - AsciiCompareIgnoreCaseCheck(StringRef name, ClangTidyContext* context) - : ClangTidyCheck(name, context) - {} - - bool isLanguageVersionSupported(const LangOptions& langOpts) const override { - return langOpts.CPlusPlus; - } - - void registerMatchers(ast_matchers::MatchFinder* finder) override; - void check(const ast_matchers::MatchFinder::MatchResult& result) override; - }; - -} // namespace clang::tidy::arcadia diff --git a/library/cpp/clang_tidy/arcadia_checks/taxi_coroutine_unsafe_check.cpp b/library/cpp/clang_tidy/arcadia_checks/taxi_coroutine_unsafe_check.cpp deleted file mode 100644 index b47c702bab9..00000000000 --- a/library/cpp/clang_tidy/arcadia_checks/taxi_coroutine_unsafe_check.cpp +++ /dev/null @@ -1,89 +0,0 @@ -//===--- taxi_coroutine_unsafe_check.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 "taxi_coroutine_unsafe_check.h" -#include <contrib/libs/clang16/include/clang/AST/ASTContext.h> -#include <contrib/libs/clang16/include/clang/ASTMatchers/ASTMatchFinder.h> - -using namespace clang::ast_matchers; -using namespace clang::ast_matchers::internal; - -namespace clang { -namespace tidy { -namespace misc { - -namespace { -const auto kFuncall = "funcall"; -const auto kCtr = "ctr"; -const auto kFieldDecl = "field_decl"; -} // namespace - -TaxiCoroutineUnsafeCheck::TaxiCoroutineUnsafeCheck(StringRef Name, - ClangTidyContext *Context) - : ClangTidyCheck(Name, Context) {} - -void TaxiCoroutineUnsafeCheck::registerMatchers(MatchFinder *Finder) { - const auto UnsafeTypes = anyOf( // - matchesName("^::std::thread"), // - matchesName("^::std::future"), // - matchesName("^::std::condition_variable"), // - matchesName("^::std::condition_variable_any"), // - matchesName("^::std::shared_mutex"), // - matchesName("^::std::mutex"), // - matchesName("^::boost::thread"), // - matchesName("^::boost::future"), // - matchesName("^::boost::condition_variable"), // - matchesName("^::boost::condition_variable_any"), // - matchesName("^::boost::shared_mutex"), // - matchesName("^::boost::mutex") // - ); - Finder->addMatcher( - cxxConstructExpr(hasDeclaration(namedDecl(UnsafeTypes))).bind(kCtr), - this); - - const auto UnsafeFuncs = anyOf( // - matchesName("^::thrd_create$"), // - matchesName("^::mtx_init$"), // - matchesName("^::cnd_init$"), // - matchesName("^::pthread_"), // - matchesName("^::system$"), // - matchesName("^::fork$"), // - matchesName("^::sleep$"), // - matchesName("^::usleep$") // - ); - - Finder->addMatcher(callExpr(callee(functionDecl(UnsafeFuncs))).bind(kFuncall), - this); - - Finder->addMatcher( - fieldDecl(hasType(namedDecl(UnsafeTypes))).bind(kFieldDecl), this); -} - -void TaxiCoroutineUnsafeCheck::check(const MatchFinder::MatchResult &Result) { - const auto *Call = Result.Nodes.getNodeAs<CallExpr>(kFuncall); - if (Call) { - diag(Call->getBeginLoc(), "function is not coroutine safe") - << SourceRange(Call->getBeginLoc(), Call->getEndLoc()); - } - - const auto *Decl = Result.Nodes.getNodeAs<CXXConstructExpr>(kCtr); - if (Decl) { - diag(Decl->getBeginLoc(), "type is not coroutine safe") - << SourceRange(Decl->getBeginLoc(), Decl->getEndLoc()); - } - - const auto *FDecl = Result.Nodes.getNodeAs<FieldDecl>(kFieldDecl); - if (FDecl) { - diag(FDecl->getBeginLoc(), "type is not coroutine safe") - << SourceRange(FDecl->getBeginLoc(), FDecl->getEndLoc()); - } -} - -} // namespace misc -} // namespace tidy -} // namespace clang diff --git a/library/cpp/clang_tidy/arcadia_checks/taxi_coroutine_unsafe_check.h b/library/cpp/clang_tidy/arcadia_checks/taxi_coroutine_unsafe_check.h deleted file mode 100644 index 4139f7c5005..00000000000 --- a/library/cpp/clang_tidy/arcadia_checks/taxi_coroutine_unsafe_check.h +++ /dev/null @@ -1,33 +0,0 @@ -//===--- taxi_coroutine_unsafe_check.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_MISC_TAXICOROUTINEUNSAFECHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_TAXICOROUTINEUNSAFECHECK_H - -#include <contrib/libs/clang16/tools/extra/clang-tidy/ClangTidyCheck.h> - -namespace clang { -namespace tidy { -namespace misc { - -/// Coroutines related checks on blocking or inefficient calls not related to -/// the filesystem. -class TaxiCoroutineUnsafeCheck : public ClangTidyCheck { -public: - TaxiCoroutineUnsafeCheck(StringRef Name, ClangTidyContext *Context); - - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; -}; - -} // namespace misc -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_TAXICOROUTINEUNSAFECHECK_H diff --git a/library/cpp/clang_tidy/arcadia_checks/taxi_dangling_config_ref_check.cpp b/library/cpp/clang_tidy/arcadia_checks/taxi_dangling_config_ref_check.cpp deleted file mode 100644 index 9ac88094d24..00000000000 --- a/library/cpp/clang_tidy/arcadia_checks/taxi_dangling_config_ref_check.cpp +++ /dev/null @@ -1,48 +0,0 @@ -//===--- taxi_dangling_config_ref_check.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 "taxi_dangling_config_ref_check.h" -#include <contrib/libs/clang16/include/clang/AST/ASTContext.h> -#include <contrib/libs/clang16/include/clang/ASTMatchers/ASTMatchFinder.h> - -using namespace clang::ast_matchers; - -namespace clang { -namespace tidy { -namespace misc { - -namespace { -const auto kConfig = "config"; -} - -void TaxiDanglingConfigRefCheck::registerMatchers(MatchFinder *Finder) { - Finder->addMatcher( - varDecl( - hasType(references(cxxRecordDecl())), - has(exprWithCleanups(has(cxxMemberCallExpr(has(memberExpr( - member(hasName("Get")), - has(cxxOperatorCallExpr( - has(implicitCastExpr(has(materializeTemporaryExpr( - has(cxxBindTemporaryExpr(has(cxxMemberCallExpr(has( - memberExpr(member(hasName("Get"))))))))))))))))))))) - .bind("config"), - this); -} - -void TaxiDanglingConfigRefCheck::check(const MatchFinder::MatchResult &Result) { - const auto *MatchedDecl = Result.Nodes.getNodeAs<VarDecl>("config"); - if (MatchedDecl) { - diag(MatchedDecl->getBeginLoc(), - "don't init reference with member of temporary") - << SourceRange(MatchedDecl->getBeginLoc(), MatchedDecl->getEndLoc()); - } -} - -} // namespace misc -} // namespace tidy -} // namespace clang diff --git a/library/cpp/clang_tidy/arcadia_checks/taxi_dangling_config_ref_check.h b/library/cpp/clang_tidy/arcadia_checks/taxi_dangling_config_ref_check.h deleted file mode 100644 index e675bea9c92..00000000000 --- a/library/cpp/clang_tidy/arcadia_checks/taxi_dangling_config_ref_check.h +++ /dev/null @@ -1,32 +0,0 @@ -//===--- taxi_dangling_config_ref_check.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_MISC_TAXIDANGLINGCONFIGREFCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_TAXIDANGLINGCONFIGREFCHECK_H - -#include <contrib/libs/clang16/tools/extra/clang-tidy/ClangTidyCheck.h> - -namespace clang { -namespace tidy { -namespace misc { - -class TaxiDanglingConfigRefCheck : public ClangTidyCheck { -public: - TaxiDanglingConfigRefCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context) {} - - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; -}; - -} // namespace misc -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_TAXIDANGLINGCONFIGREFCHECK_H diff --git a/library/cpp/clang_tidy/arcadia_checks/tidy_module.cpp b/library/cpp/clang_tidy/arcadia_checks/tidy_module.cpp deleted file mode 100644 index add729d5fb1..00000000000 --- a/library/cpp/clang_tidy/arcadia_checks/tidy_module.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include <contrib/libs/clang16/tools/extra/clang-tidy/ClangTidy.h> -#include <contrib/libs/clang16/tools/extra/clang-tidy/ClangTidyModule.h> -#include <contrib/libs/clang16/tools/extra/clang-tidy/ClangTidyModuleRegistry.h> - -#include "taxi_coroutine_unsafe_check.h" -#include "taxi_dangling_config_ref_check.h" - -#include "ascii_compare_ignore_case_check.h" -#include "usage_restriction_checks.h" - -using namespace clang::ast_matchers; - -namespace clang::tidy::arcadia { - class ArcadiaModule: public ClangTidyModule { - public: - void addCheckFactories(ClangTidyCheckFactories& CheckFactories) override { - CheckFactories.registerCheck<misc::TaxiCoroutineUnsafeCheck>( - "arcadia-taxi-coroutine-unsafe"); - CheckFactories.registerCheck<misc::TaxiDanglingConfigRefCheck>( - "arcadia-taxi-dangling-config-ref"); - - // https://st.yandex-team.ru/IGNIETFERRO-1863 - CheckFactories.registerCheck<TypeidNameRestrictionCheck>( - "arcadia-typeid-name-restriction"); - CheckFactories.registerCheck<AsciiCompareIgnoreCaseCheck>("arcadia-ascii-compare-ignorecase"); - } - }; - - // Register the ArcadiaTidyModule using this statically initialized variable. - static ClangTidyModuleRegistry::Add<ArcadiaModule> - X("arcadia-module", "Adds Arcadia specific lint checks."); - -} diff --git a/library/cpp/clang_tidy/arcadia_checks/usage_restriction_checks.cpp b/library/cpp/clang_tidy/arcadia_checks/usage_restriction_checks.cpp deleted file mode 100644 index b4530088076..00000000000 --- a/library/cpp/clang_tidy/arcadia_checks/usage_restriction_checks.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "usage_restriction_checks.h" -#include <contrib/libs/clang16/include/clang/AST/ASTContext.h> -#include <contrib/libs/clang16/include/clang/ASTMatchers/ASTMatchFinder.h> - -using namespace clang::ast_matchers; - -namespace clang::tidy::arcadia { - void TypeidNameRestrictionCheck::registerMatchers(MatchFinder* Finder) { - Finder->addMatcher(cxxMemberCallExpr(on(expr(hasType(namedDecl(hasName("::std::type_info")))).bind("expr")), - callee(cxxMethodDecl(hasName("name"), parameterCountIs(0)))), - this); - Finder->addMatcher(cxxMemberCallExpr(on(expr(hasType(namedDecl(hasName("::std::type_index")))).bind("expr")), - callee(cxxMethodDecl(hasName("name"), parameterCountIs(0)))), - this); - } - - void TypeidNameRestrictionCheck::check(const MatchFinder::MatchResult& Result) { - const auto node = Result.Nodes.getNodeAs<Expr>("expr"); - - diag(node->getBeginLoc(), "Both std::type_info::name() and std::type_index::name() return mangled typename. " - "Consider using TypeName() functions from <util/system/type_name.h> instead"); - } - -} diff --git a/library/cpp/clang_tidy/arcadia_checks/usage_restriction_checks.h b/library/cpp/clang_tidy/arcadia_checks/usage_restriction_checks.h deleted file mode 100644 index d63d3658e9b..00000000000 --- a/library/cpp/clang_tidy/arcadia_checks/usage_restriction_checks.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include <contrib/libs/clang16/tools/extra/clang-tidy/ClangTidyCheck.h> - -namespace clang::tidy::arcadia { - /// Finds usage of `typeid(smth).name` - /// For more info see https://st.yandex-team.ru/IGNIETFERRO-1522 - class TypeidNameRestrictionCheck: public ClangTidyCheck { - public: - TypeidNameRestrictionCheck(StringRef Name, ClangTidyContext* Context) - : ClangTidyCheck(Name, Context) - { - } - void registerMatchers(ast_matchers::MatchFinder* Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult& Result) override; - }; - -} diff --git a/library/cpp/clang_tidy/arcadia_checks/ya.make b/library/cpp/clang_tidy/arcadia_checks/ya.make deleted file mode 100644 index 63224e3e50e..00000000000 --- a/library/cpp/clang_tidy/arcadia_checks/ya.make +++ /dev/null @@ -1,20 +0,0 @@ -LIBRARY() - -PEERDIR( - contrib/libs/clang16/lib/AST - contrib/libs/clang16/lib/ASTMatchers -) - -NO_COMPILER_WARNINGS() - -NO_UTIL() - -SRCS( - ascii_compare_ignore_case_check.cpp - taxi_coroutine_unsafe_check.cpp - taxi_dangling_config_ref_check.cpp - GLOBAL tidy_module.cpp - usage_restriction_checks.cpp -) - -END() diff --git a/library/cpp/iterator/enumerate.h b/library/cpp/iterator/enumerate.h index 6ebc12a0e7d..4b6a43dad78 100644 --- a/library/cpp/iterator/enumerate.h +++ b/library/cpp/iterator/enumerate.h @@ -8,11 +8,11 @@ namespace NPrivate { - template <typename TContainer> + template <typename TContainer, typename TSize> struct TEnumerator { private: using TStorage = TAutoEmbedOrPtrPolicy<TContainer>; - using TValue = std::tuple<const std::size_t, decltype(*std::begin(std::declval<TContainer&>()))>; + using TValue = std::tuple<const TSize, decltype(*std::begin(std::declval<TContainer&>()))>; using TIteratorState = decltype(std::begin(std::declval<TContainer&>())); using TSentinelState = decltype(std::end(std::declval<TContainer&>())); @@ -55,7 +55,7 @@ namespace NPrivate { return Iterator_ == other.Iterator_; } - std::size_t Index_; + TSize Index_; TIteratorState Iterator_; }; @@ -72,7 +72,7 @@ namespace NPrivate { TSentinel end() const { if constexpr (TrivialSentinel) { - return TIterator{std::numeric_limits<std::size_t>::max(), std::end(*Storage_.Ptr())}; + return TIterator{std::numeric_limits<TSize>::max(), std::end(*Storage_.Ptr())}; } else { return TSentinel{std::end(*Storage_.Ptr())}; } @@ -86,5 +86,12 @@ namespace NPrivate { //! Usage: for (auto [i, x] : Enumerate(container)) {...} template <typename TContainerOrRef> auto Enumerate(TContainerOrRef&& container) { - return NPrivate::TEnumerator<TContainerOrRef>{std::forward<TContainerOrRef>(container)}; + return NPrivate::TEnumerator<TContainerOrRef, std::size_t>{std::forward<TContainerOrRef>(container)}; +} + +//! Usage: for (auto [i, x] : SEnumerate(container)) {...} +// The index is signed for codebases that prefer signed numerics (such as YTsaurus). +template <typename TContainerOrRef> +auto SEnumerate(TContainerOrRef&& container) { + return NPrivate::TEnumerator<TContainerOrRef, std::ptrdiff_t>{std::forward<TContainerOrRef>(container)}; } diff --git a/library/cpp/tcmalloc/fix.cpp b/library/cpp/tcmalloc/fix.cpp deleted file mode 100644 index 3229ac74402..00000000000 --- a/library/cpp/tcmalloc/fix.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include <absl/debugging/stacktrace.h> - -namespace { - static struct TInitUnwinder { - TInitUnwinder() { - absl::SetStackUnwinder(DummyUnwinder); - } - - static int DummyUnwinder(void**, int*, int, int, const void*, int*) { - return 0; - } - } init; -} diff --git a/library/cpp/tcmalloc/ya.make b/library/cpp/tcmalloc/ya.make deleted file mode 100644 index 3e66c28aa72..00000000000 --- a/library/cpp/tcmalloc/ya.make +++ /dev/null @@ -1,10 +0,0 @@ -LIBRARY() - -IF (OS_LINUX) - PEERDIR( - contrib/restricted/abseil-cpp/absl/debugging - ) - SRCS(GLOBAL fix.cpp) -ENDIF() - -END() |