Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,23 @@
set(LLVM_LINK_COMPONENTS support)
add_clang_library(clangTidyHICPPModule
ExceptionBaseclassCheck.cpp
NoAssemblerCheck.cpp
HICPPTidyModule.cpp
SignedBitwiseCheck.cpp
LINK_LIBS
clangAST
clangASTMatchers
clangBasic
clangLex
clangTidy
clangTidyBugproneModule
clangTidyCppCoreGuidelinesModule
clangTidyGoogleModule
clangTidyMiscModule
clangTidyModernizeModule
clangTidyPerformanceModule
clangTidyReadabilityModule
clangTidyUtils
)

View File

@@ -0,0 +1,50 @@
//===--- ExceptionBaseclassCheck.cpp - clang-tidy--------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "ExceptionBaseclassCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
namespace hicpp {
void ExceptionBaseclassCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(
cxxThrowExpr(allOf(has(expr(unless(hasType(qualType(hasCanonicalType(
hasDeclaration(cxxRecordDecl(isSameOrDerivedFrom(
hasName("std::exception")))))))))),
has(expr(unless(cxxUnresolvedConstructExpr()))),
eachOf(has(expr(hasType(namedDecl().bind("decl")))),
anything())))
.bind("bad_throw"),
this);
}
void ExceptionBaseclassCheck::check(const MatchFinder::MatchResult &Result) {
const auto *BadThrow = Result.Nodes.getNodeAs<CXXThrowExpr>("bad_throw");
diag(BadThrow->getSubExpr()->getLocStart(), "throwing an exception whose "
"type %0 is not derived from "
"'std::exception'")
<< BadThrow->getSubExpr()->getType() << BadThrow->getSourceRange();
const auto *TypeDecl = Result.Nodes.getNodeAs<NamedDecl>("decl");
if (TypeDecl != nullptr)
diag(TypeDecl->getLocStart(), "type defined here", DiagnosticIDs::Note);
}
} // namespace hicpp
} // namespace tidy
} // namespace clang

View File

@@ -0,0 +1,35 @@
//===--- ExceptionBaseclassCheck.h - clang-tidy------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_EXCEPTION_BASECLASS_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_EXCEPTION_BASECLASS_H
#include "../ClangTidy.h"
namespace clang {
namespace tidy {
namespace hicpp {
/// Check for thrown exceptions and enforce they are all derived from std::exception.
///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/hicpp-exception-baseclass.html
class ExceptionBaseclassCheck : public ClangTidyCheck {
public:
ExceptionBaseclassCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
} // namespace hicpp
} // namespace tidy
} // namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_EXCEPTION_BASECLASS_H

View File

@@ -0,0 +1,114 @@
//===------- HICPPTidyModule.cpp - clang-tidy -----------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
#include "../bugprone/UseAfterMoveCheck.h"
#include "../cppcoreguidelines/NoMallocCheck.h"
#include "../cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h"
#include "../cppcoreguidelines/ProTypeMemberInitCheck.h"
#include "../cppcoreguidelines/ProTypeVarargCheck.h"
#include "../cppcoreguidelines/SpecialMemberFunctionsCheck.h"
#include "../google/DefaultArgumentsCheck.h"
#include "../google/ExplicitConstructorCheck.h"
#include "../misc/NewDeleteOverloadsCheck.h"
#include "../misc/StaticAssertCheck.h"
#include "../misc/UndelegatedConstructor.h"
#include "../modernize/DeprecatedHeadersCheck.h"
#include "../modernize/UseAutoCheck.h"
#include "../modernize/UseEmplaceCheck.h"
#include "../modernize/UseEqualsDefaultCheck.h"
#include "../modernize/UseEqualsDeleteCheck.h"
#include "../modernize/UseNoexceptCheck.h"
#include "../modernize/UseNullptrCheck.h"
#include "../modernize/UseOverrideCheck.h"
#include "../performance/MoveConstArgCheck.h"
#include "../performance/NoexceptMoveConstructorCheck.h"
#include "../readability/BracesAroundStatementsCheck.h"
#include "../readability/FunctionSizeCheck.h"
#include "../readability/IdentifierNamingCheck.h"
#include "ExceptionBaseclassCheck.h"
#include "NoAssemblerCheck.h"
#include "SignedBitwiseCheck.h"
namespace clang {
namespace tidy {
namespace hicpp {
class HICPPModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<readability::BracesAroundStatementsCheck>(
"hicpp-braces-around-statements");
CheckFactories.registerCheck<modernize::DeprecatedHeadersCheck>(
"hicpp-deprecated-headers");
CheckFactories.registerCheck<ExceptionBaseclassCheck>(
"hicpp-exception-baseclass");
CheckFactories.registerCheck<SignedBitwiseCheck>(
"hicpp-signed-bitwise");
CheckFactories.registerCheck<google::ExplicitConstructorCheck>(
"hicpp-explicit-conversions");
CheckFactories.registerCheck<readability::FunctionSizeCheck>(
"hicpp-function-size");
CheckFactories.registerCheck<readability::IdentifierNamingCheck>(
"hicpp-named-parameter");
CheckFactories.registerCheck<bugprone::UseAfterMoveCheck>(
"hicpp-invalid-access-moved");
CheckFactories.registerCheck<cppcoreguidelines::ProTypeMemberInitCheck>(
"hicpp-member-init");
CheckFactories.registerCheck<performance::MoveConstArgCheck>(
"hicpp-move-const-arg");
CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>(
"hicpp-new-delete-operators");
CheckFactories.registerCheck<performance::NoexceptMoveConstructorCheck>(
"hicpp-noexcept-move");
CheckFactories
.registerCheck<cppcoreguidelines::ProBoundsArrayToPointerDecayCheck>(
"hicpp-no-array-decay");
CheckFactories.registerCheck<NoAssemblerCheck>("hicpp-no-assembler");
CheckFactories.registerCheck<cppcoreguidelines::NoMallocCheck>(
"hicpp-no-malloc");
CheckFactories
.registerCheck<cppcoreguidelines::SpecialMemberFunctionsCheck>(
"hicpp-special-member-functions");
CheckFactories.registerCheck<misc::StaticAssertCheck>(
"hicpp-static-assert");
CheckFactories.registerCheck<modernize::UseAutoCheck>("hicpp-use-auto");
CheckFactories.registerCheck<misc::UndelegatedConstructorCheck>(
"hicpp-undelegated-constructor");
CheckFactories.registerCheck<modernize::UseEmplaceCheck>(
"hicpp-use-emplace");
CheckFactories.registerCheck<modernize::UseEqualsDefaultCheck>(
"hicpp-use-equals-default");
CheckFactories.registerCheck<modernize::UseEqualsDeleteCheck>(
"hicpp-use-equals-delete");
CheckFactories.registerCheck<modernize::UseNoexceptCheck>(
"hicpp-use-noexcept");
CheckFactories.registerCheck<modernize::UseNullptrCheck>(
"hicpp-use-nullptr");
CheckFactories.registerCheck<modernize::UseOverrideCheck>(
"hicpp-use-override");
CheckFactories.registerCheck<cppcoreguidelines::ProTypeVarargCheck>(
"hicpp-vararg");
}
};
// Register the HICPPModule using this statically initialized variable.
static ClangTidyModuleRegistry::Add<HICPPModule>
X("hicpp-module", "Adds High-Integrity C++ checks.");
} // namespace hicpp
// This anchor is used to force the linker to link in the generated object file
// and thus register the HICPPModule.
volatile int HICPPModuleAnchorSource = 0;
} // namespace tidy
} // namespace clang

View File

@@ -0,0 +1,12 @@
------------------------------------------------------------------------------
clang-tidy High-Integrity C++ Files
------------------------------------------------------------------------------
All clang-tidy files are licensed under the LLVM license with the following
additions:
Any file referencing a High-Integrity C++ Coding guideline:
HIC++ Coding Standard as created by PRQA.
Please see http://www.codingstandard.com/section/conditions-of-use/ for more
information.

View File

@@ -0,0 +1,51 @@
//===--- NoAssemblerCheck.cpp - clang-tidy---------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "NoAssemblerCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
namespace clang {
namespace ast_matchers {
AST_MATCHER(VarDecl, isAsm) { return Node.hasAttr<clang::AsmLabelAttr>(); }
const internal::VariadicDynCastAllOfMatcher<Decl, FileScopeAsmDecl>
fileScopeAsmDecl;
}
}
namespace clang {
namespace tidy {
namespace hicpp {
void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(asmStmt().bind("asm-stmt"), this);
Finder->addMatcher(fileScopeAsmDecl().bind("asm-file-scope"), this);
Finder->addMatcher(varDecl(isAsm()).bind("asm-var"), this);
}
void NoAssemblerCheck::check(const MatchFinder::MatchResult &Result) {
SourceLocation ASMLocation;
if (const auto *ASM = Result.Nodes.getNodeAs<AsmStmt>("asm-stmt"))
ASMLocation = ASM->getAsmLoc();
else if (const auto *ASM =
Result.Nodes.getNodeAs<FileScopeAsmDecl>("asm-file-scope"))
ASMLocation = ASM->getAsmLoc();
else if (const auto *ASM = Result.Nodes.getNodeAs<VarDecl>("asm-var"))
ASMLocation = ASM->getLocation();
else
llvm_unreachable("Unhandled case in matcher.");
diag(ASMLocation, "do not use inline assembler in safety-critical code");
}
} // namespace hicpp
} // namespace tidy
} // namespace clang

View File

@@ -0,0 +1,35 @@
//===--- NoAssemblerCheck.h - clang-tidy-------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_NO_ASSEMBLER_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_NO_ASSEMBLER_H
#include "../ClangTidy.h"
namespace clang {
namespace tidy {
namespace hicpp {
/// Find assembler statements. No fix is offered.
///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/hicpp-no-assembler.html
class NoAssemblerCheck : public ClangTidyCheck {
public:
NoAssemblerCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
} // namespace hicpp
} // namespace tidy
} // namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_NO_ASSEMBLER_H

View File

@@ -0,0 +1,96 @@
//===--- SignedBitwiseCheck.cpp - clang-tidy-------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "SignedBitwiseCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
using namespace clang::ast_matchers::internal;
namespace clang {
namespace tidy {
namespace hicpp {
void SignedBitwiseCheck::registerMatchers(MatchFinder *Finder) {
const auto SignedIntegerOperand =
expr(ignoringImpCasts(hasType(isSignedInteger()))).bind("signed-operand");
// The standard [bitmask.types] allows some integral types to be implemented
// as signed types. Exclude these types from diagnosing for bitwise or(|) and
// bitwise and(&). Shifting and complementing such values is still not
// allowed.
const auto BitmaskType = namedDecl(anyOf(
hasName("::std::locale::category"), hasName("::std::ctype_base::mask"),
hasName("::std::ios_base::fmtflags"), hasName("::std::ios_base::iostate"),
hasName("::std::ios_base::openmode")));
const auto IsStdBitmask = ignoringImpCasts(declRefExpr(hasType(BitmaskType)));
// Match binary bitwise operations on signed integer arguments.
Finder->addMatcher(
binaryOperator(
allOf(anyOf(hasOperatorName("^"), hasOperatorName("|"),
hasOperatorName("&")),
unless(allOf(hasLHS(IsStdBitmask), hasRHS(IsStdBitmask))),
hasEitherOperand(SignedIntegerOperand),
hasLHS(hasType(isInteger())), hasRHS(hasType(isInteger()))))
.bind("binary-no-sign-interference"),
this);
// Shifting and complement is not allowed for any signed integer type because
// the sign bit may corrupt the result.
Finder->addMatcher(
binaryOperator(allOf(anyOf(hasOperatorName("<<"), hasOperatorName(">>")),
hasEitherOperand(SignedIntegerOperand),
hasLHS(hasType(isInteger())),
hasRHS(hasType(isInteger()))))
.bind("binary-sign-interference"),
this);
// Match unary operations on signed integer types.
Finder->addMatcher(unaryOperator(allOf(hasOperatorName("~"),
hasUnaryOperand(SignedIntegerOperand)))
.bind("unary-signed"),
this);
}
void SignedBitwiseCheck::check(const MatchFinder::MatchResult &Result) {
const ast_matchers::BoundNodes &N = Result.Nodes;
const auto *SignedOperand = N.getNodeAs<Expr>("signed-operand");
assert(SignedOperand &&
"No signed operand found in problematic bitwise operations");
bool IsUnary = false;
SourceLocation Location;
if (const auto *UnaryOp = N.getNodeAs<UnaryOperator>("unary-signed")) {
IsUnary = true;
Location = UnaryOp->getLocStart();
} else {
if (const auto *BinaryOp =
N.getNodeAs<BinaryOperator>("binary-no-sign-interference"))
Location = BinaryOp->getLocStart();
else if (const auto *BinaryOp =
N.getNodeAs<BinaryOperator>("binary-sign-interference"))
Location = BinaryOp->getLocStart();
else
llvm_unreachable("unexpected matcher result");
}
diag(Location,
"use of a signed integer operand with a %select{binary|unary}0 bitwise "
"operator")
<< IsUnary << SignedOperand->getSourceRange();
}
} // namespace hicpp
} // namespace tidy
} // namespace clang

View File

@@ -0,0 +1,36 @@
//===--- SignedBitwiseCheck.h - clang-tidy-----------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_SIGNED_BITWISE_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_SIGNED_BITWISE_H
#include "../ClangTidy.h"
namespace clang {
namespace tidy {
namespace hicpp {
/// This check implements the rule 5.6.1 of the HICPP Standard, which disallows
/// bitwise operations on signed integer types.
///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/hicpp-signed-bitwise.html
class SignedBitwiseCheck : public ClangTidyCheck {
public:
SignedBitwiseCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
} // namespace hicpp
} // namespace tidy
} // namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_SIGNED_BITWISE_H