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,16 @@
set(LLVM_LINK_COMPONENTS support)
add_clang_library(clangTidyFuchsiaModule
DefaultArgumentsCheck.cpp
FuchsiaTidyModule.cpp
OverloadedOperatorCheck.cpp
VirtualInheritanceCheck.cpp
LINK_LIBS
clangAST
clangASTMatchers
clangBasic
clangLex
clangTidy
clangTidyUtils
)

View File

@ -0,0 +1,64 @@
//===--- DefaultArgumentsCheck.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 "DefaultArgumentsCheck.h"
using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
namespace fuchsia {
void DefaultArgumentsCheck::registerMatchers(MatchFinder *Finder) {
// Calling a function which uses default arguments is disallowed.
Finder->addMatcher(cxxDefaultArgExpr().bind("stmt"), this);
// Declaring default parameters is disallowed.
Finder->addMatcher(parmVarDecl(hasDefaultArgument()).bind("decl"), this);
}
void DefaultArgumentsCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *S =
Result.Nodes.getNodeAs<CXXDefaultArgExpr>("stmt")) {
diag(S->getUsedLocation(),
"calling a function that uses a default argument is disallowed");
diag(S->getParam()->getLocStart(),
"default parameter was declared here",
DiagnosticIDs::Note);
} else if (const ParmVarDecl *D =
Result.Nodes.getNodeAs<ParmVarDecl>("decl")) {
SourceRange DefaultArgRange = D->getDefaultArgRange();
if (DefaultArgRange.getEnd() != D->getLocEnd()) {
return;
} else if (DefaultArgRange.getBegin().isMacroID()) {
diag(D->getLocStart(),
"declaring a parameter with a default argument is disallowed");
} else {
SourceLocation StartLocation = D->getName().empty() ?
D->getLocStart() : D->getLocation();
SourceRange RemovalRange(Lexer::getLocForEndOfToken(
StartLocation, 0,
*Result.SourceManager,
Result.Context->getLangOpts()
),
DefaultArgRange.getEnd()
);
diag(D->getLocStart(),
"declaring a parameter with a default argument is disallowed")
<< D
<< FixItHint::CreateRemoval(RemovalRange);
}
}
}
} // namespace fuchsia
} // namespace tidy
} // namespace clang

View File

@ -0,0 +1,35 @@
//===--- DefaultArgumentsCheck.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_FUCHSIA_DEFAULT_ARGUMENTS_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_H
#include "../ClangTidy.h"
namespace clang {
namespace tidy {
namespace fuchsia {
/// Default arguments are not allowed in declared or called functions.
///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-default-arguments.html
class DefaultArgumentsCheck : public ClangTidyCheck {
public:
DefaultArgumentsCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
} // namespace fuchsia
} // namespace tidy
} // namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_H

View File

@ -0,0 +1,45 @@
//===--- FuchsiaTidyModule.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 "DefaultArgumentsCheck.h"
#include "OverloadedOperatorCheck.h"
#include "VirtualInheritanceCheck.h"
using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
namespace fuchsia {
/// This module is for Fuchsia-specific checks.
class FuchsiaModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<DefaultArgumentsCheck>(
"fuchsia-default-arguments");
CheckFactories.registerCheck<OverloadedOperatorCheck>(
"fuchsia-overloaded-operator");
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 tidy
} // namespace clang

View File

@ -0,0 +1,43 @@
//===--- OverloadedOperatorCheck.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 "OverloadedOperatorCheck.h"
using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
namespace fuchsia {
AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) {
if (const auto *CXXMethodNode = dyn_cast<CXXMethodDecl>(&Node)) {
if (CXXMethodNode->isCopyAssignmentOperator() ||
CXXMethodNode->isMoveAssignmentOperator())
return false;
}
return Node.isOverloadedOperator();
}
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->getLocStart();
if (Loc.isValid())
diag(Loc, "cannot overload %0") << D;
}
} // namespace fuchsia
} // namespace tidy
} // namespace clang

View File

@ -0,0 +1,35 @@
//===--- OverloadedOperatorCheck.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_FUCHSIA_OVERLOADED_OPERATOR_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H
#include "../ClangTidy.h"
namespace clang {
namespace tidy {
namespace 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 fuchsia
} // namespace tidy
} // namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H

View File

@ -0,0 +1,41 @@
//===--- VirtualInheritanceCheck.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 "VirtualInheritanceCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
namespace fuchsia {
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;
}
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->getLocStart(), "direct virtual inheritance is disallowed");
}
} // namespace fuchsia
} // namespace tidy
} // namespace clang

View File

@ -0,0 +1,35 @@
//===--- VirtualInheritanceCheck.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_FUCHSIA_VIRTUAL_INHERITANCE_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H
#include "../ClangTidy.h"
namespace clang {
namespace tidy {
namespace 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 fuchsia
} // namespace tidy
} // namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H