aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
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 /library/cpp
parent726057070f9c5a91fc10fde0d5024913d10f1ab9 (diff)
downloadydb-6ffe9e53658409f212834330e13564e4952558f6.tar.gz
YQ Connector: support managed ClickHouse
Со стороны dqrun можно обратиться к инстансу коннектора, который работает на streaming стенде, и извлечь данные из облачного CH.
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/clang_tidy/arcadia_checks/taxi_coroutine_unsafe_check.cpp89
-rw-r--r--library/cpp/clang_tidy/arcadia_checks/taxi_coroutine_unsafe_check.h33
-rw-r--r--library/cpp/clang_tidy/arcadia_checks/taxi_dangling_config_ref_check.cpp48
-rw-r--r--library/cpp/clang_tidy/arcadia_checks/taxi_dangling_config_ref_check.h32
-rw-r--r--library/cpp/clang_tidy/arcadia_checks/tidy_module.cpp31
-rw-r--r--library/cpp/clang_tidy/arcadia_checks/usage_restriction_checks.cpp24
-rw-r--r--library/cpp/clang_tidy/arcadia_checks/usage_restriction_checks.h18
-rw-r--r--library/cpp/clang_tidy/arcadia_checks/ya.make19
8 files changed, 294 insertions, 0 deletions
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
new file mode 100644
index 0000000000..b47c702bab
--- /dev/null
+++ b/library/cpp/clang_tidy/arcadia_checks/taxi_coroutine_unsafe_check.cpp
@@ -0,0 +1,89 @@
+//===--- 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
new file mode 100644
index 0000000000..4139f7c500
--- /dev/null
+++ b/library/cpp/clang_tidy/arcadia_checks/taxi_coroutine_unsafe_check.h
@@ -0,0 +1,33 @@
+//===--- 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
new file mode 100644
index 0000000000..9ac88094d2
--- /dev/null
+++ b/library/cpp/clang_tidy/arcadia_checks/taxi_dangling_config_ref_check.cpp
@@ -0,0 +1,48 @@
+//===--- 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
new file mode 100644
index 0000000000..e675bea9c9
--- /dev/null
+++ b/library/cpp/clang_tidy/arcadia_checks/taxi_dangling_config_ref_check.h
@@ -0,0 +1,32 @@
+//===--- 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
new file mode 100644
index 0000000000..348211949e
--- /dev/null
+++ b/library/cpp/clang_tidy/arcadia_checks/tidy_module.cpp
@@ -0,0 +1,31 @@
+#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 "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");
+ }
+ };
+
+ // 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
new file mode 100644
index 0000000000..bc825fa18f
--- /dev/null
+++ b/library/cpp/clang_tidy/arcadia_checks/usage_restriction_checks.cpp
@@ -0,0 +1,24 @@
+#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(allOf(hasName("name"), parameterCountIs(0))))),
+ this);
+ Finder->addMatcher(cxxMemberCallExpr(on(expr(hasType(namedDecl(hasName("::std::type_index")))).bind("expr")),
+ callee(cxxMethodDecl(allOf(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
new file mode 100644
index 0000000000..d63d3658e9
--- /dev/null
+++ b/library/cpp/clang_tidy/arcadia_checks/usage_restriction_checks.h
@@ -0,0 +1,18 @@
+#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
new file mode 100644
index 0000000000..5a38ea6c39
--- /dev/null
+++ b/library/cpp/clang_tidy/arcadia_checks/ya.make
@@ -0,0 +1,19 @@
+LIBRARY()
+
+PEERDIR(
+ contrib/libs/clang16/lib/AST
+ contrib/libs/clang16/lib/ASTMatchers
+)
+
+NO_COMPILER_WARNINGS()
+
+NO_UTIL()
+
+SRCS(
+ taxi_coroutine_unsafe_check.cpp
+ taxi_dangling_config_ref_check.cpp
+ GLOBAL tidy_module.cpp
+ usage_restriction_checks.cpp
+)
+
+END()