diff options
author | vitalyisaev <vitalyisaev@yandex-team.com> | 2023-06-29 10:00:50 +0300 |
---|---|---|
committer | vitalyisaev <vitalyisaev@yandex-team.com> | 2023-06-29 10:00:50 +0300 |
commit | 6ffe9e53658409f212834330e13564e4952558f6 (patch) | |
tree | 85b1e00183517648b228aafa7c8fb07f5276f419 /contrib/libs/clang14/tools/extra/clang-tidy/portability | |
parent | 726057070f9c5a91fc10fde0d5024913d10f1ab9 (diff) | |
download | ydb-6ffe9e53658409f212834330e13564e4952558f6.tar.gz |
YQ Connector: support managed ClickHouse
Со стороны dqrun можно обратиться к инстансу коннектора, который работает на streaming стенде, и извлечь данные из облачного CH.
Diffstat (limited to 'contrib/libs/clang14/tools/extra/clang-tidy/portability')
6 files changed, 438 insertions, 0 deletions
diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/portability/PortabilityTidyModule.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/portability/PortabilityTidyModule.cpp new file mode 100644 index 0000000000..c87a119aa8 --- /dev/null +++ b/contrib/libs/clang14/tools/extra/clang-tidy/portability/PortabilityTidyModule.cpp @@ -0,0 +1,40 @@ +//===--- PortabilityTidyModule.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 "RestrictSystemIncludesCheck.h" +#include "SIMDIntrinsicsCheck.h" + +namespace clang { +namespace tidy { +namespace portability { + +class PortabilityModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck<RestrictSystemIncludesCheck>( + "portability-restrict-system-includes"); + CheckFactories.registerCheck<SIMDIntrinsicsCheck>( + "portability-simd-intrinsics"); + } +}; + +// Register the PortabilityModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add<PortabilityModule> + X("portability-module", "Adds portability-related checks."); + +} // namespace portability + +// This anchor is used to force the linker to link in the generated object file +// and thus register the PortabilityModule. +volatile int PortabilityModuleAnchorSource = 0; + +} // namespace tidy +} // namespace clang diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp new file mode 100644 index 0000000000..f6163989a4 --- /dev/null +++ b/contrib/libs/clang14/tools/extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp @@ -0,0 +1,80 @@ +//===--- RestrictSystemIncludesCheck.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 "RestrictSystemIncludesCheck.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Lex/HeaderSearch.h" +#include "clang/Lex/PPCallbacks.h" +#include "clang/Lex/Preprocessor.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Path.h" +#include <cstring> + +namespace clang { +namespace tidy { +namespace portability { + +void RestrictedIncludesPPCallbacks::InclusionDirective( + SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, + SrcMgr::CharacteristicKind FileType) { + if (!Check.contains(FileName) && SrcMgr::isSystem(FileType)) { + SmallString<256> FullPath; + llvm::sys::path::append(FullPath, SearchPath); + llvm::sys::path::append(FullPath, RelativePath); + // Bucket the allowed include directives by the id of the file they were + // declared in. + IncludeDirectives[SM.getFileID(HashLoc)].emplace_back( + HashLoc, FilenameRange, FileName, FullPath.str(), + SM.isInMainFile(HashLoc)); + } +} + +void RestrictedIncludesPPCallbacks::EndOfMainFile() { + for (const auto &Bucket : IncludeDirectives) { + const FileIncludes &FileDirectives = Bucket.second; + + // Emit fixits for all restricted includes. + for (const auto &Include : FileDirectives) { + // Fetch the length of the include statement from the start to just after + // the newline, for finding the end (including the newline). + unsigned ToLen = std::strcspn(SM.getCharacterData(Include.Loc), "\n") + 1; + CharSourceRange ToRange = CharSourceRange::getCharRange( + Include.Loc, Include.Loc.getLocWithOffset(ToLen)); + + if (!Include.IsInMainFile) { + auto D = Check.diag( + Include.Loc, + "system include %0 not allowed, transitively included from %1"); + D << Include.IncludeFile << SM.getFilename(Include.Loc); + D << FixItHint::CreateRemoval(ToRange); + continue; + } + auto D = Check.diag(Include.Loc, "system include %0 not allowed"); + D << Include.IncludeFile; + D << FixItHint::CreateRemoval(ToRange); + } + } +} + +void RestrictSystemIncludesCheck::registerPPCallbacks( + const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) { + PP->addPPCallbacks( + std::make_unique<RestrictedIncludesPPCallbacks>(*this, SM)); +} + +void RestrictSystemIncludesCheck::storeOptions( + ClangTidyOptions::OptionMap &Opts) { + Options.store(Opts, "Includes", AllowedIncludes); +} + +} // namespace portability +} // namespace tidy +} // namespace clang diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/portability/RestrictSystemIncludesCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/portability/RestrictSystemIncludesCheck.h new file mode 100644 index 0000000000..80eddf7bce --- /dev/null +++ b/contrib/libs/clang14/tools/extra/clang-tidy/portability/RestrictSystemIncludesCheck.h @@ -0,0 +1,85 @@ +//===--- RestrictSystemIncludesCheck.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_PORTABILITY_RESTRICTINCLUDESSCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H + +#include "../ClangTidyCheck.h" +#include "../GlobList.h" +#include "clang/Lex/PPCallbacks.h" + +namespace clang { +namespace tidy { +namespace portability { + +/// Checks for allowed includes and suggests removal of any others. If no +/// includes are specified, the check will exit without issuing any warnings. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/portability-restrict-system-includes.html +class RestrictSystemIncludesCheck : public ClangTidyCheck { +public: + RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context, + std::string DefaultAllowedIncludes = "*") + : ClangTidyCheck(Name, Context), + AllowedIncludes(Options.get("Includes", DefaultAllowedIncludes)), + AllowedIncludesGlobList(AllowedIncludes) {} + + void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, + Preprocessor *ModuleExpanderPP) override; + void storeOptions(ClangTidyOptions::OptionMap &Opts) override; + bool contains(StringRef FileName) { + return AllowedIncludesGlobList.contains(FileName); + } + +private: + std::string AllowedIncludes; + GlobList AllowedIncludesGlobList; +}; + +class RestrictedIncludesPPCallbacks : public PPCallbacks { +public: + explicit RestrictedIncludesPPCallbacks(RestrictSystemIncludesCheck &Check, + const SourceManager &SM) + : Check(Check), SM(SM) {} + + void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, + StringRef FileName, bool IsAngled, + CharSourceRange FilenameRange, const FileEntry *File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, + SrcMgr::CharacteristicKind FileType) override; + void EndOfMainFile() override; + +private: + struct IncludeDirective { + IncludeDirective() = default; + IncludeDirective(SourceLocation Loc, CharSourceRange Range, + StringRef Filename, StringRef FullPath, bool IsInMainFile) + : Loc(Loc), Range(Range), IncludeFile(Filename), IncludePath(FullPath), + IsInMainFile(IsInMainFile) {} + + SourceLocation Loc; // '#' location in the include directive + CharSourceRange Range; // SourceRange for the file name + std::string IncludeFile; // Filename as a string + std::string IncludePath; // Full file path as a string + bool IsInMainFile; // Whether or not the include is in the main file + }; + + using FileIncludes = llvm::SmallVector<IncludeDirective, 8>; + llvm::SmallDenseMap<FileID, FileIncludes> IncludeDirectives; + + RestrictSystemIncludesCheck &Check; + const SourceManager &SM; +}; + +} // namespace portability +} // namespace tidy +} // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp b/contrib/libs/clang14/tools/extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp new file mode 100644 index 0000000000..8ea00a0b8e --- /dev/null +++ b/contrib/libs/clang14/tools/extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp @@ -0,0 +1,151 @@ +//===--- SIMDIntrinsicsCheck.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 "SIMDIntrinsicsCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Basic/TargetInfo.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/Triple.h" +#include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/Regex.h" + +using namespace clang::ast_matchers; + +namespace clang { +namespace tidy { +namespace portability { + +namespace { + +// If the callee has parameter of VectorType or pointer to VectorType, +// or the return type is VectorType, we consider it a vector function +// and a candidate for checking. +AST_MATCHER(FunctionDecl, isVectorFunction) { + bool IsVector = Node.getReturnType()->isVectorType(); + for (const ParmVarDecl *Parm : Node.parameters()) { + QualType Type = Parm->getType(); + if (Type->isPointerType()) + Type = Type->getPointeeType(); + if (Type->isVectorType()) + IsVector = true; + } + return IsVector; +} + +} // namespace + +static StringRef trySuggestPpc(StringRef Name) { + if (!Name.consume_front("vec_")) + return {}; + + return llvm::StringSwitch<StringRef>(Name) + // [simd.alg] + .Case("max", "$std::max") + .Case("min", "$std::min") + // [simd.binary] + .Case("add", "operator+ on $simd objects") + .Case("sub", "operator- on $simd objects") + .Case("mul", "operator* on $simd objects") + .Default({}); +} + +static StringRef trySuggestX86(StringRef Name) { + if (!(Name.consume_front("_mm_") || Name.consume_front("_mm256_") || + Name.consume_front("_mm512_"))) + return {}; + + // [simd.alg] + if (Name.startswith("max_")) + return "$simd::max"; + if (Name.startswith("min_")) + return "$simd::min"; + + // [simd.binary] + if (Name.startswith("add_")) + return "operator+ on $simd objects"; + if (Name.startswith("sub_")) + return "operator- on $simd objects"; + if (Name.startswith("mul_")) + return "operator* on $simd objects"; + + return {}; +} + +SIMDIntrinsicsCheck::SIMDIntrinsicsCheck(StringRef Name, + ClangTidyContext *Context) + : ClangTidyCheck(Name, Context), Std(Options.get("Std", "")), + Suggest(Options.get("Suggest", false)) {} + +void SIMDIntrinsicsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { + Options.store(Opts, "Std", Std); + Options.store(Opts, "Suggest", Suggest); +} + +void SIMDIntrinsicsCheck::registerMatchers(MatchFinder *Finder) { + // If Std is not specified, infer it from the language options. + // libcxx implementation backports it to C++11 std::experimental::simd. + if (Std.empty()) + Std = getLangOpts().CPlusPlus20 ? "std" : "std::experimental"; + + Finder->addMatcher(callExpr(callee(functionDecl( + matchesName("^::(_mm_|_mm256_|_mm512_|vec_)"), + isVectorFunction())), + unless(isExpansionInSystemHeader())) + .bind("call"), + this); +} + +void SIMDIntrinsicsCheck::check(const MatchFinder::MatchResult &Result) { + const auto *Call = Result.Nodes.getNodeAs<CallExpr>("call"); + assert(Call != nullptr); + const FunctionDecl *Callee = Call->getDirectCallee(); + if (!Callee) + return; + + StringRef Old = Callee->getName(); + StringRef New; + llvm::Triple::ArchType Arch = + Result.Context->getTargetInfo().getTriple().getArch(); + + // We warn or suggest if this SIMD intrinsic function has a std::simd + // replacement. + switch (Arch) { + default: + break; + case llvm::Triple::ppc: + case llvm::Triple::ppc64: + case llvm::Triple::ppc64le: + New = trySuggestPpc(Old); + break; + case llvm::Triple::x86: + case llvm::Triple::x86_64: + New = trySuggestX86(Old); + break; + } + + // We have found a std::simd replacement. + if (!New.empty()) { + // If Suggest is true, give a P0214 alternative, otherwise point it out it + // is non-portable. + if (Suggest) { + static const llvm::Regex StdRegex("\\$std"), SimdRegex("\\$simd"); + diag(Call->getExprLoc(), "'%0' can be replaced by %1") + << Old + << SimdRegex.sub(SmallString<32>({Std, "::simd"}), + StdRegex.sub(Std, New)); + } else { + diag("'%0' is a non-portable %1 intrinsic function") + << Old << llvm::Triple::getArchTypeName(Arch); + } + } +} + +} // namespace portability +} // namespace tidy +} // namespace clang diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/portability/SIMDIntrinsicsCheck.h b/contrib/libs/clang14/tools/extra/clang-tidy/portability/SIMDIntrinsicsCheck.h new file mode 100644 index 0000000000..17ed4bb3c1 --- /dev/null +++ b/contrib/libs/clang14/tools/extra/clang-tidy/portability/SIMDIntrinsicsCheck.h @@ -0,0 +1,44 @@ +//===--- SIMDIntrinsicsCheck.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_SIMD_INTRINSICS_CHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H + +#include "../ClangTidyCheck.h" + +#include "llvm/ADT/SmallString.h" + +namespace clang { +namespace tidy { +namespace portability { + +/// Find SIMD intrinsics calls and suggest std::experimental::simd alternatives. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/portability-simd-intrinsics.html +class SIMDIntrinsicsCheck : public ClangTidyCheck { +public: + SIMDIntrinsicsCheck(StringRef Name, ClangTidyContext *Context); + + bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { + return LangOpts.CPlusPlus11; + } + void storeOptions(ClangTidyOptions::OptionMap &Opts) override; + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; + + private: + llvm::SmallString<32> Std; + const bool Suggest; +}; + +} // namespace portability +} // namespace tidy +} // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H diff --git a/contrib/libs/clang14/tools/extra/clang-tidy/portability/ya.make b/contrib/libs/clang14/tools/extra/clang-tidy/portability/ya.make new file mode 100644 index 0000000000..de32f2f2cc --- /dev/null +++ b/contrib/libs/clang14/tools/extra/clang-tidy/portability/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/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/lib/Tooling + 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/portability +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + +SRCS( + PortabilityTidyModule.cpp + RestrictSystemIncludesCheck.cpp + SIMDIntrinsicsCheck.cpp +) + +END() |