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/fuchsia | |
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/fuchsia')
16 files changed, 709 insertions, 0 deletions
diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp new file mode 100644 index 0000000000..96cd30e0ba --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp @@ -0,0 +1,31 @@ +//===--- DefaultArgumentsCallsCheck.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 "DefaultArgumentsCallsCheck.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::fuchsia { + +void DefaultArgumentsCallsCheck::registerMatchers(MatchFinder *Finder) { + // Calling a function which uses default arguments is disallowed. + Finder->addMatcher(cxxDefaultArgExpr().bind("stmt"), this); +} + +void DefaultArgumentsCallsCheck::check(const MatchFinder::MatchResult &Result) { + const auto *S = Result.Nodes.getNodeAs<CXXDefaultArgExpr>("stmt"); + if (!S) + return; + + diag(S->getUsedLocation(), + "calling a function that uses a default argument is disallowed"); + diag(S->getParam()->getBeginLoc(), "default parameter was declared here", + DiagnosticIDs::Note); +} + +} // namespace clang::tidy::fuchsia diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h new file mode 100644 index 0000000000..49d7820d04 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h @@ -0,0 +1,30 @@ +//===--- DefaultArgumentsCallsCheck.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_FUCHSIA_DEFAULT_ARGUMENTS_CALLS_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_CALLS_H + +#include "../ClangTidyCheck.h" + +namespace clang::tidy::fuchsia { + +/// Default arguments are not allowed in called functions. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia/default-arguments-calls.html +class DefaultArgumentsCallsCheck : public ClangTidyCheck { +public: + DefaultArgumentsCallsCheck(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::fuchsia + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_CALLS_H diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp new file mode 100644 index 0000000000..05a663bf3d --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp @@ -0,0 +1,51 @@ +//===--- DefaultArgumentsDeclarationsCheck.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 "DefaultArgumentsDeclarationsCheck.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::fuchsia { + +void DefaultArgumentsDeclarationsCheck::registerMatchers(MatchFinder *Finder) { + // Declaring default parameters is disallowed. + Finder->addMatcher(parmVarDecl(hasDefaultArgument()).bind("decl"), this); +} + +void DefaultArgumentsDeclarationsCheck::check( + const MatchFinder::MatchResult &Result) { + const auto *D = Result.Nodes.getNodeAs<ParmVarDecl>("decl"); + if (!D) + return; + + SourceRange DefaultArgRange = D->getDefaultArgRange(); + + if (DefaultArgRange.getEnd() != D->getEndLoc()) + return; + + if (DefaultArgRange.getBegin().isMacroID()) { + diag(D->getBeginLoc(), + "declaring a parameter with a default argument is disallowed"); + return; + } + + SourceLocation StartLocation = + D->getName().empty() ? D->getBeginLoc() : D->getLocation(); + + SourceRange RemovalRange( + Lexer::getLocForEndOfToken(StartLocation, 0, *Result.SourceManager, + Result.Context->getLangOpts()), + DefaultArgRange.getEnd()); + + diag(D->getBeginLoc(), + "declaring a parameter with a default argument is disallowed") + << D << FixItHint::CreateRemoval(RemovalRange); +} + +} // namespace clang::tidy::fuchsia diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h new file mode 100644 index 0000000000..d03d0b7a10 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h @@ -0,0 +1,30 @@ +//===--- DefaultArgumentsDeclarationsCheck.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_FUCHSIA_DEFAULT_ARGUMENTS_DECLARATIONS_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_DECLARATIONS_H + +#include "../ClangTidyCheck.h" + +namespace clang::tidy::fuchsia { + +/// Default parameters are not allowed in declared functions. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia/default-arguments-declarations.html +class DefaultArgumentsDeclarationsCheck : public ClangTidyCheck { +public: + DefaultArgumentsDeclarationsCheck(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::fuchsia + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_DECLARATIONS_H diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp new file mode 100644 index 0000000000..45a79b75e0 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp @@ -0,0 +1,57 @@ +//===--- FuchsiaTidyModule.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 "../google/UnnamedNamespaceInHeaderCheck.h" +#include "DefaultArgumentsCallsCheck.h" +#include "DefaultArgumentsDeclarationsCheck.h" +#include "MultipleInheritanceCheck.h" +#include "OverloadedOperatorCheck.h" +#include "StaticallyConstructedObjectsCheck.h" +#include "TrailingReturnCheck.h" +#include "VirtualInheritanceCheck.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy { +namespace fuchsia { + +/// This module is for Fuchsia-specific checks. +class FuchsiaModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck<DefaultArgumentsCallsCheck>( + "fuchsia-default-arguments-calls"); + CheckFactories.registerCheck<DefaultArgumentsDeclarationsCheck>( + "fuchsia-default-arguments-declarations"); + CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>( + "fuchsia-header-anon-namespaces"); + CheckFactories.registerCheck<MultipleInheritanceCheck>( + "fuchsia-multiple-inheritance"); + CheckFactories.registerCheck<OverloadedOperatorCheck>( + "fuchsia-overloaded-operator"); + CheckFactories.registerCheck<StaticallyConstructedObjectsCheck>( + "fuchsia-statically-constructed-objects"); + CheckFactories.registerCheck<TrailingReturnCheck>( + "fuchsia-trailing-return"); + CheckFactories.registerCheck<VirtualInheritanceCheck>( + "fuchsia-virtual-inheritance"); + } +}; +// Register the FuchsiaTidyModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add<FuchsiaModule> + X("fuchsia-module", "Adds Fuchsia platform checks."); +} // namespace fuchsia + +// This anchor is used to force the linker to link in the generated object file +// and thus register the FuchsiaModule. +volatile int FuchsiaModuleAnchorSource = 0; + +} // namespace clang::tidy diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp new file mode 100644 index 0000000000..060f3aebcd --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp @@ -0,0 +1,123 @@ +//===--- MultipleInheritanceCheck.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 "MultipleInheritanceCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang; +using namespace clang::ast_matchers; + +namespace clang::tidy::fuchsia { + +namespace { +AST_MATCHER(CXXRecordDecl, hasBases) { + if (Node.hasDefinition()) + return Node.getNumBases() > 0; + return false; +} +} // namespace + +// Adds a node (by name) to the interface map, if it was not present in the map +// previously. +void MultipleInheritanceCheck::addNodeToInterfaceMap(const CXXRecordDecl *Node, + bool IsInterface) { + assert(Node->getIdentifier()); + StringRef Name = Node->getIdentifier()->getName(); + InterfaceMap.insert(std::make_pair(Name, IsInterface)); +} + +// Returns "true" if the boolean "isInterface" has been set to the +// interface status of the current Node. Return "false" if the +// interface status for the current node is not yet known. +bool MultipleInheritanceCheck::getInterfaceStatus(const CXXRecordDecl *Node, + bool &IsInterface) const { + assert(Node->getIdentifier()); + StringRef Name = Node->getIdentifier()->getName(); + llvm::StringMapConstIterator<bool> Pair = InterfaceMap.find(Name); + if (Pair == InterfaceMap.end()) + return false; + IsInterface = Pair->second; + return true; +} + +bool MultipleInheritanceCheck::isCurrentClassInterface( + const CXXRecordDecl *Node) const { + // Interfaces should have no fields. + if (!Node->field_empty()) return false; + + // Interfaces should have exclusively pure methods. + return llvm::none_of(Node->methods(), [](const CXXMethodDecl *M) { + return M->isUserProvided() && !M->isPure() && !M->isStatic(); + }); +} + +bool MultipleInheritanceCheck::isInterface(const CXXRecordDecl *Node) { + if (!Node->getIdentifier()) + return false; + + // Short circuit the lookup if we have analyzed this record before. + bool PreviousIsInterfaceResult; + if (getInterfaceStatus(Node, PreviousIsInterfaceResult)) + return PreviousIsInterfaceResult; + + // To be an interface, all base classes must be interfaces as well. + for (const auto &I : Node->bases()) { + if (I.isVirtual()) continue; + const auto *Ty = I.getType()->getAs<RecordType>(); + if (!Ty) continue; + const RecordDecl *D = Ty->getDecl()->getDefinition(); + if (!D) continue; + const auto *Base = cast<CXXRecordDecl>(D); + if (!isInterface(Base)) { + addNodeToInterfaceMap(Node, false); + return false; + } + } + + bool CurrentClassIsInterface = isCurrentClassInterface(Node); + addNodeToInterfaceMap(Node, CurrentClassIsInterface); + return CurrentClassIsInterface; +} + +void MultipleInheritanceCheck::registerMatchers(MatchFinder *Finder) { + // Match declarations which have bases. + Finder->addMatcher( + cxxRecordDecl(allOf(hasBases(), isDefinition())).bind("decl"), this); +} + +void MultipleInheritanceCheck::check(const MatchFinder::MatchResult &Result) { + if (const auto *D = Result.Nodes.getNodeAs<CXXRecordDecl>("decl")) { + // Check against map to see if if the class inherits from multiple + // concrete classes + unsigned NumConcrete = 0; + for (const auto &I : D->bases()) { + if (I.isVirtual()) continue; + const auto *Ty = I.getType()->getAs<RecordType>(); + if (!Ty) continue; + const auto *Base = cast<CXXRecordDecl>(Ty->getDecl()->getDefinition()); + if (!isInterface(Base)) NumConcrete++; + } + + // Check virtual bases to see if there is more than one concrete + // non-virtual base. + for (const auto &V : D->vbases()) { + const auto *Ty = V.getType()->getAs<RecordType>(); + if (!Ty) continue; + const auto *Base = cast<CXXRecordDecl>(Ty->getDecl()->getDefinition()); + if (!isInterface(Base)) NumConcrete++; + } + + if (NumConcrete > 1) { + diag(D->getBeginLoc(), "inheriting multiple classes that aren't " + "pure virtual is discouraged"); + } + } +} + +} // namespace clang::tidy::fuchsia diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/MultipleInheritanceCheck.h b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/MultipleInheritanceCheck.h new file mode 100644 index 0000000000..be5942c952 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/MultipleInheritanceCheck.h @@ -0,0 +1,46 @@ +//===--- MultipleInheritanceCheck.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_FUCHSIA_MULTIPLE_INHERITANCE_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLE_INHERITANCE_H + +#include "../ClangTidyCheck.h" + +namespace clang::tidy::fuchsia { + +/// Multiple implementation inheritance is discouraged. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia/multiple-inheritance.html +class MultipleInheritanceCheck : public ClangTidyCheck { +public: + MultipleInheritanceCheck(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; + + void onEndOfTranslationUnit() override { InterfaceMap.clear(); } + +private: + void addNodeToInterfaceMap(const CXXRecordDecl *Node, bool IsInterface); + bool getInterfaceStatus(const CXXRecordDecl *Node, bool &IsInterface) const; + bool isCurrentClassInterface(const CXXRecordDecl *Node) const; + bool isInterface(const CXXRecordDecl *Node); + + // Contains the identity of each named CXXRecord as an interface. This is + // used to memoize lookup speeds and improve performance from O(N^2) to O(N), + // where N is the number of classes. + llvm::StringMap<bool> InterfaceMap; +}; + +} // namespace clang::tidy::fuchsia + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLE_INHERITANCE_H diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp new file mode 100644 index 0000000000..85864006e4 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp @@ -0,0 +1,42 @@ +//===--- OverloadedOperatorCheck.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 "OverloadedOperatorCheck.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::fuchsia { + +namespace { +AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) { + if (const auto *CXXMethodNode = dyn_cast<CXXMethodDecl>(&Node)) { + if (CXXMethodNode->isCopyAssignmentOperator() || + CXXMethodNode->isMoveAssignmentOperator()) + return false; + if (CXXMethodNode->getParent()->isLambda()) + return false; + } + return Node.isOverloadedOperator(); +} +} // namespace + +void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"), + this); +} + +void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) { + const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl"); + assert(D && "No FunctionDecl captured!"); + + SourceLocation Loc = D->getBeginLoc(); + if (Loc.isValid()) + diag(Loc, "overloading %0 is disallowed") << D; +} + +} // namespace clang::tidy::fuchsia diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/OverloadedOperatorCheck.h b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/OverloadedOperatorCheck.h new file mode 100644 index 0000000000..007f410a6e --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/OverloadedOperatorCheck.h @@ -0,0 +1,30 @@ +//===--- OverloadedOperatorCheck.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_FUCHSIA_OVERLOADED_OPERATOR_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H + +#include "../ClangTidyCheck.h" + +namespace clang::tidy::fuchsia { + +/// Overloading operators is disallowed by the Fuchsia coding standard. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia/overloaded-operator.html +class OverloadedOperatorCheck : public ClangTidyCheck { +public: + OverloadedOperatorCheck(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::fuchsia + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp new file mode 100644 index 0000000000..ac55d01208 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp @@ -0,0 +1,51 @@ +//===--- StaticallyConstructedObjectsCheck.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 "StaticallyConstructedObjectsCheck.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::fuchsia { + +namespace { +AST_MATCHER(Expr, isConstantInitializer) { + return Node.isConstantInitializer(Finder->getASTContext(), false); +} + +AST_MATCHER(VarDecl, isGlobalStatic) { + return Node.getStorageDuration() == SD_Static && !Node.isLocalVarDecl(); +} +} // namespace + +void StaticallyConstructedObjectsCheck::registerMatchers(MatchFinder *Finder) { + // Constructing global, non-trivial objects with static storage is + // disallowed, unless the object is statically initialized with a constexpr + // constructor or has no explicit constructor. + Finder->addMatcher( + traverse(TK_AsIs, + varDecl( + // Match global, statically stored objects... + isGlobalStatic(), + // ... that have C++ constructors... + hasDescendant(cxxConstructExpr(unless(allOf( + // ... unless it is constexpr ... + hasDeclaration(cxxConstructorDecl(isConstexpr())), + // ... and is statically initialized. + isConstantInitializer()))))) + .bind("decl")), + this); +} + +void StaticallyConstructedObjectsCheck::check( + const MatchFinder::MatchResult &Result) { + if (const auto *D = Result.Nodes.getNodeAs<VarDecl>("decl")) + diag(D->getBeginLoc(), "static objects are disallowed; if possible, use a " + "constexpr constructor instead"); +} + +} // namespace clang::tidy::fuchsia diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h new file mode 100644 index 0000000000..fc18273ad7 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h @@ -0,0 +1,35 @@ +//===--- StaticallyConstructedObjectsCheck.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_FUCHSIA_STATICALLY_CONSTRUCTED_OBJECTS_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_STATICALLY_CONSTRUCTED_OBJECTS_H + +#include "../ClangTidyCheck.h" + +namespace clang::tidy::fuchsia { + +/// Constructing global, non-trivial objects with static storage is +/// disallowed, unless the object is statically initialized with a constexpr +/// constructor or has no explicit constructor. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia/statically-constructed-objects.html +class StaticallyConstructedObjectsCheck : public ClangTidyCheck { +public: + StaticallyConstructedObjectsCheck(StringRef Name, ClangTidyContext *Context) + : ClangTidyCheck(Name, Context) {} + bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { + return LangOpts.CPlusPlus11; + } + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; +}; + +} // namespace clang::tidy::fuchsia + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_STATICALLY_CONSTRUCTED_OBJECTS_H diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp new file mode 100644 index 0000000000..06e2637634 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp @@ -0,0 +1,37 @@ +//===--- TrailingReturnCheck.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 "TrailingReturnCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchersInternal.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::fuchsia { + +void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) { + // Functions that have trailing returns are disallowed, except for those + // using decltype specifiers and lambda with otherwise unutterable + // return types. + Finder->addMatcher( + functionDecl(hasTrailingReturn(), + unless(anyOf(returns(decltypeType()), + hasParent(cxxRecordDecl(isLambda())), + cxxDeductionGuideDecl()))) + .bind("decl"), + this); +} + +void TrailingReturnCheck::check(const MatchFinder::MatchResult &Result) { + if (const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl")) + diag(D->getBeginLoc(), + "a trailing return type is disallowed for this function declaration"); +} + +} // namespace clang::tidy::fuchsia diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/TrailingReturnCheck.h b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/TrailingReturnCheck.h new file mode 100644 index 0000000000..2ba8e27d00 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/TrailingReturnCheck.h @@ -0,0 +1,35 @@ +//===--- TrailingReturnCheck.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_FUCHSIA_TRAILING_RETURN_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILING_RETURN_H + +#include "../ClangTidyCheck.h" + +namespace clang::tidy::fuchsia { + +/// Functions that have trailing returns are disallowed, except for those +/// using decltype specifiers and lambda with otherwise unutterable +/// return types. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia/trailing-return.html +class TrailingReturnCheck : public ClangTidyCheck { +public: + TrailingReturnCheck(StringRef Name, ClangTidyContext *Context) + : ClangTidyCheck(Name, Context) {} + bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { + return LangOpts.CPlusPlus11; + } + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; +}; + +} // namespace clang::tidy::fuchsia + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILING_RETURN_H diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp new file mode 100644 index 0000000000..9c367423fd --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp @@ -0,0 +1,38 @@ +//===--- VirtualInheritanceCheck.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 "VirtualInheritanceCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::fuchsia { + +namespace { +AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) { + if (!Node.hasDefinition()) return false; + if (!Node.getNumVBases()) return false; + for (const CXXBaseSpecifier &Base : Node.bases()) + if (Base.isVirtual()) return true; + return false; +} +} // namespace + +void VirtualInheritanceCheck::registerMatchers(MatchFinder *Finder) { + // Defining classes using direct virtual inheritance is disallowed. + Finder->addMatcher(cxxRecordDecl(hasDirectVirtualBaseClass()).bind("decl"), + this); +} + +void VirtualInheritanceCheck::check(const MatchFinder::MatchResult &Result) { + if (const auto *D = Result.Nodes.getNodeAs<CXXRecordDecl>("decl")) + diag(D->getBeginLoc(), "direct virtual inheritance is disallowed"); +} + +} // namespace clang::tidy::fuchsia diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/VirtualInheritanceCheck.h b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/VirtualInheritanceCheck.h new file mode 100644 index 0000000000..d109bd52a1 --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/VirtualInheritanceCheck.h @@ -0,0 +1,30 @@ +//===--- VirtualInheritanceCheck.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_FUCHSIA_VIRTUAL_INHERITANCE_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H + +#include "../ClangTidyCheck.h" + +namespace clang::tidy::fuchsia { + +/// Defining classes with virtual inheritance is disallowed. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia/virtual-inheritance.html +class VirtualInheritanceCheck : public ClangTidyCheck { + public: + VirtualInheritanceCheck(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::fuchsia + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H diff --git a/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/ya.make b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/ya.make new file mode 100644 index 0000000000..f3d4d16e0b --- /dev/null +++ b/contrib/libs/clang16/tools/extra/clang-tidy/fuchsia/ya.make @@ -0,0 +1,43 @@ +# 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/google + 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/fuchsia +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + +SRCS( + DefaultArgumentsCallsCheck.cpp + DefaultArgumentsDeclarationsCheck.cpp + FuchsiaTidyModule.cpp + MultipleInheritanceCheck.cpp + OverloadedOperatorCheck.cpp + StaticallyConstructedObjectsCheck.cpp + TrailingReturnCheck.cpp + VirtualInheritanceCheck.cpp +) + +END() |