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/zircon | |
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/zircon')
4 files changed, 165 insertions, 0 deletions
diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp b/contrib/libs/clang16/tools/extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp new file mode 100644 index 0000000000..240bb4ee29 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp @@ -0,0 +1,55 @@ +//===--- TemporaryObjectsCheck.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 "TemporaryObjectsCheck.h" +#include "../utils/OptionsUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" +#include <string> + +using namespace clang::ast_matchers; + +namespace clang::tidy::zircon { + +AST_MATCHER_P(CXXRecordDecl, matchesAnyName, ArrayRef<StringRef>, Names) { + std::string QualifiedName = Node.getQualifiedNameAsString(); + return llvm::is_contained(Names, QualifiedName); +} + +void TemporaryObjectsCheck::registerMatchers(MatchFinder *Finder) { + // Matcher for default constructors. + Finder->addMatcher( + cxxTemporaryObjectExpr(hasDeclaration(cxxConstructorDecl(hasParent( + cxxRecordDecl(matchesAnyName(Names)))))) + .bind("temps"), + this); + + // Matcher for user-defined constructors. + Finder->addMatcher( + traverse(TK_AsIs, + cxxConstructExpr(hasParent(cxxFunctionalCastExpr()), + hasDeclaration(cxxConstructorDecl(hasParent( + cxxRecordDecl(matchesAnyName(Names)))))) + .bind("temps")), + this); +} + +void TemporaryObjectsCheck::check(const MatchFinder::MatchResult &Result) { + if (const auto *D = Result.Nodes.getNodeAs<CXXConstructExpr>("temps")) + diag(D->getLocation(), + "creating a temporary object of type %q0 is prohibited") + << D->getConstructor()->getParent(); +} + +void TemporaryObjectsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { + Options.store(Opts, "Names", utils::options::serializeStringList(Names)); +} + +} // namespace clang::tidy::zircon diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/zircon/TemporaryObjectsCheck.h b/contrib/libs/clang16/tools/extra/clang-tidy/zircon/TemporaryObjectsCheck.h new file mode 100644 index 0000000000..e1f1f06ab3 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/zircon/TemporaryObjectsCheck.h @@ -0,0 +1,37 @@ +//===--- TemporaryObjectsCheck.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_ZIRCON_TEMPORARYOBJECTSCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ZIRCON_TEMPORARYOBJECTSCHECK_H + +#include "../ClangTidyCheck.h" +#include "../utils/OptionsUtils.h" + +namespace clang::tidy::zircon { + +/// Construction of specific temporary objects in the Zircon kernel is +/// discouraged. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/zircon/temporary-objects.html +class TemporaryObjectsCheck : public ClangTidyCheck { +public: + TemporaryObjectsCheck(StringRef Name, ClangTidyContext *Context) + : ClangTidyCheck(Name, Context), + Names(utils::options::parseStringList(Options.get("Names", ""))) {} + void storeOptions(ClangTidyOptions::OptionMap &Opts) override; + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; + +private: + std::vector<StringRef> Names; +}; + +} // namespace clang::tidy::zircon + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ZIRCON_TEMPORARYOBJECTSCHECK_H diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/zircon/ZirconTidyModule.cpp b/contrib/libs/clang16/tools/extra/clang-tidy/zircon/ZirconTidyModule.cpp new file mode 100644 index 0000000000..000680455d --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/zircon/ZirconTidyModule.cpp @@ -0,0 +1,37 @@ +//===--- ZirconTidyModule.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 "TemporaryObjectsCheck.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy { +namespace zircon { + +/// This module is for Zircon-specific checks. +class ZirconModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck<TemporaryObjectsCheck>( + "zircon-temporary-objects"); + } +}; + +// Register the ZirconTidyModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add<ZirconModule> + X("zircon-module", "Adds Zircon kernel checks."); +} // namespace zircon + +// This anchor is used to force the linker to link in the generated object file +// and thus register the ZirconModule. +volatile int ZirconModuleAnchorSource = 0; + +} // namespace clang::tidy diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/zircon/ya.make b/contrib/libs/clang16/tools/extra/clang-tidy/zircon/ya.make new file mode 100644 index 0000000000..59761a825a --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/zircon/ya.make @@ -0,0 +1,36 @@ +# 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/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/zircon +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + +SRCS( + TemporaryObjectsCheck.cpp + ZirconTidyModule.cpp +) + +END() |