Skip to content

Commit

Permalink
Merge from 'master' to 'sycl-web' (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
bader committed Mar 8, 2020
2 parents d7eba00 + 7a42bab commit b93fda8
Show file tree
Hide file tree
Showing 796 changed files with 23,184 additions and 10,832 deletions.
2 changes: 2 additions & 0 deletions clang-tools-extra/clang-tidy/ClangTidy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ ClangTidyASTConsumerFactory::CreateASTConsumer(
}

for (auto &Check : Checks) {
if (!Check->isLanguageVersionSupported(Context.getLangOpts()))
continue;
Check->registerMatchers(&*Finder);
Check->registerPPCallbacks(*SM, PP, ModuleExpanderPP);
}
Expand Down
16 changes: 16 additions & 0 deletions clang-tools-extra/clang-tidy/ClangTidyCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,24 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// constructor using the Options.get() methods below.
ClangTidyCheck(StringRef CheckName, ClangTidyContext *Context);

/// Override this to disable registering matchers and PP callbacks if an
/// invalid language version is being used.
///
/// For example if a check is examining overloaded functions then this should
/// be overridden to return false when the CPlusPlus flag is not set in
/// \p LangOpts.
virtual bool isLanguageVersionSupported(const LangOptions &LangOpts) const {
return true;
}

/// Override this to register ``PPCallbacks`` in the preprocessor.
///
/// This should be used for clang-tidy checks that analyze preprocessor-
/// dependent properties, e.g. include directives and macro definitions.
///
/// This will only be executed if the function isLanguageVersionSupported
/// returns true.
///
/// There are two Preprocessors to choose from that differ in how they handle
/// modular #includes:
/// - PP is the real Preprocessor. It doesn't walk into modular #includes and
Expand All @@ -80,6 +93,9 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// "this" will be used as callback, but you can also specify other callback
/// classes. Thereby, different matchers can trigger different callbacks.
///
/// This will only be executed if the function isLanguageVersionSupported
/// returns true.
///
/// If you need to merge information between the different matchers, you can
/// store these as members of the derived class. However, note that all
/// matches occur in the order of the AST traversal.
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void NoRecursionCheck::check(const MatchFinder::MatchResult &Result) {
for (llvm::scc_iterator<CallGraph *> SCCI = llvm::scc_begin(&CG),
SCCE = llvm::scc_end(&CG);
SCCI != SCCE; ++SCCI) {
if (!SCCI.hasLoop()) // We only care about cycles, not standalone nodes.
if (!SCCI.hasCycle()) // We only care about cycles, not standalone nodes.
continue;
handleSCC(*SCCI);
}
Expand Down
5 changes: 0 additions & 5 deletions clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,12 @@ bool MakeSmartPtrCheck::isLanguageVersionSupported(
void MakeSmartPtrCheck::registerPPCallbacks(const SourceManager &SM,
Preprocessor *PP,
Preprocessor *ModuleExpanderPP) {
if (isLanguageVersionSupported(getLangOpts())) {
Inserter = std::make_unique<utils::IncludeInserter>(SM, getLangOpts(),
IncludeStyle);
PP->addPPCallbacks(Inserter->CreatePPCallbacks());
}
}

void MakeSmartPtrCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
if (!isLanguageVersionSupported(getLangOpts()))
return;

// Calling make_smart_ptr from within a member function of a type with a
// private or protected constructor would be ill-formed.
auto CanCallCtor = unless(has(ignoringImpCasts(
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MakeSmartPtrCheck : public ClangTidyCheck {
virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const = 0;

/// Returns whether the C++ version is compatible with current check.
virtual bool isLanguageVersionSupported(const LangOptions &LangOpts) const;
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;

static const char PointerType[];

Expand Down
27 changes: 15 additions & 12 deletions clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ AST_MATCHER(CXXRecordDecl, isMoveConstructible) {
}
} // namespace

static TypeMatcher constRefType() {
return lValueReferenceType(pointee(isConstQualified()));
static TypeMatcher notTemplateSpecConstRefType() {
return lValueReferenceType(
pointee(unless(templateSpecializationType()), isConstQualified()));
}

static TypeMatcher nonConstValueType() {
Expand Down Expand Up @@ -145,16 +146,18 @@ void PassByValueCheck::registerMatchers(MatchFinder *Finder) {
// ParenListExpr is generated instead of a CXXConstructExpr,
// filtering out templates automatically for us.
withInitializer(cxxConstructExpr(
has(ignoringParenImpCasts(declRefExpr(to(
parmVarDecl(
hasType(qualType(
// Match only const-ref or a non-const value
// parameters. Rvalues and const-values
// shouldn't be modified.
ValuesOnly ? nonConstValueType()
: anyOf(constRefType(),
nonConstValueType()))))
.bind("Param"))))),
has(ignoringParenImpCasts(declRefExpr(
to(parmVarDecl(
hasType(qualType(
// Match only const-ref or a non-const
// value parameters. Rvalues,
// TemplateSpecializationValues and
// const-values shouldn't be modified.
ValuesOnly
? nonConstValueType()
: anyOf(notTemplateSpecConstRefType(),
nonConstValueType()))))
.bind("Param"))))),
hasDeclaration(cxxConstructorDecl(
isCopyConstructor(), unless(isDeleted()),
hasDeclContext(
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "LexerUtils.h"
#include "clang/Basic/SourceManager.h"

namespace clang {
namespace tidy {
Expand Down
8 changes: 0 additions & 8 deletions clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,6 @@ void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
WorkScheduler.runWithAST("Rename", File, std::move(Action));
}

void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
bool WantFormat, Callback<FileEdits> CB) {
RenameOptions Opts;
Opts.WantFormat = WantFormat;
Opts.AllowCrossFile = false;
rename(File, Pos, NewName, Opts, std::move(CB));
}

// May generate several candidate selections, due to SelectionTree ambiguity.
// vector of pointers because GCC doesn't like non-copyable Selection.
static llvm::Expected<std::vector<std::unique_ptr<Tweak::Selection>>>
Expand Down
3 changes: 0 additions & 3 deletions clang-tools-extra/clangd/ClangdServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ class ClangdServer {
/// highlighting them in prepare stage).
void rename(PathRef File, Position Pos, llvm::StringRef NewName,
const RenameOptions &Opts, Callback<FileEdits> CB);
// FIXME: remove this compatibility method in favor above.
void rename(PathRef File, Position Pos, llvm::StringRef NewName,
bool WantFormat, Callback<FileEdits> CB);

struct TweakRef {
std::string ID; /// ID to pass for applyTweak.
Expand Down
2 changes: 2 additions & 0 deletions clang-tools-extra/clangd/ParsedAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ ParsedAST::build(std::unique_ptr<clang::CompilerInvocation> CI,
});
Preprocessor *PP = &Clang->getPreprocessor();
for (const auto &Check : CTChecks) {
if (!Check->isLanguageVersionSupported(CTContext->getLangOpts()))
continue;
// FIXME: the PP callbacks skip the entire preamble.
// Checks that want to see #includes in the main file do not see them.
Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
Expand Down
32 changes: 1 addition & 31 deletions clang-tools-extra/clangd/SemanticHighlighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Base64.h"
#include "llvm/Support/Casting.h"
#include <algorithm>

Expand Down Expand Up @@ -283,37 +284,6 @@ class CollectExtraHighlightings
HighlightingsBuilder &H;
};

// Encode binary data into base64.
// This was copied from compiler-rt/lib/fuzzer/FuzzerUtil.cpp.
// FIXME: Factor this out into llvm/Support?
std::string encodeBase64(const llvm::SmallVectorImpl<char> &Bytes) {
static const char Table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
std::string Res;
size_t I;
for (I = 0; I + 2 < Bytes.size(); I += 3) {
uint32_t X = (Bytes[I] << 16) + (Bytes[I + 1] << 8) + Bytes[I + 2];
Res += Table[(X >> 18) & 63];
Res += Table[(X >> 12) & 63];
Res += Table[(X >> 6) & 63];
Res += Table[X & 63];
}
if (I + 1 == Bytes.size()) {
uint32_t X = (Bytes[I] << 16);
Res += Table[(X >> 18) & 63];
Res += Table[(X >> 12) & 63];
Res += "==";
} else if (I + 2 == Bytes.size()) {
uint32_t X = (Bytes[I] << 16) + (Bytes[I + 1] << 8);
Res += Table[(X >> 18) & 63];
Res += Table[(X >> 12) & 63];
Res += Table[(X >> 6) & 63];
Res += "=";
}
return Res;
}

void write32be(uint32_t I, llvm::raw_ostream &OS) {
std::array<char, 4> Buf;
llvm::support::endian::write32be(Buf.data(), I);
Expand Down
Loading

0 comments on commit b93fda8

Please sign in to comment.