Skip to content

Commit

Permalink
Manually merged master:1d104f75498 into amd-gfx:c625fb9f60f
Browse files Browse the repository at this point in the history
Local branch amd-gfx c625fb9 Fix unintended line end changes introduced in manual merge.
Remote branch master 1d104f7 Build fix: Turn off _GLIBCXX_DEBUG based on a compile check --no-edit 1d104f7

Change-Id: I6de3e5a7574326613c95321739fc1300a0da01e5
  • Loading branch information
piotrAMD committed Mar 3, 2020
2 parents c625fb9 + 1d104f7 commit dc1257e
Show file tree
Hide file tree
Showing 816 changed files with 20,119 additions and 6,979 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
3 changes: 3 additions & 0 deletions clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class ClangTidyDiagnosticRenderer : public DiagnosticRenderer {
}
assert(Error.Message.Message.empty() && "Overwriting a diagnostic message");
Error.Message = TidyMessage;
for (const CharSourceRange &SourceRange : Ranges) {
Error.Ranges.emplace_back(Loc.getManager(), SourceRange);
}
}

void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
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
41 changes: 23 additions & 18 deletions clang-tools-extra/clangd/Hover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,32 +532,37 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
}
auto TokensTouchingCursor =
syntax::spelledTokensTouching(*CurLoc, AST.getTokens());
// Early exit if there were no tokens around the cursor.
if (TokensTouchingCursor.empty())
return llvm::None;

// In general we prefer the touching token that works over the one that
// doesn't, see SelectionTree::create(). The following locations are used only
// for triggering on macros and auto/decltype, so simply choosing the lone
// identifier-or-keyword token is equivalent.
// To be used as a backup for highlighting the selected token.
SourceLocation IdentLoc;
SourceLocation AutoLoc;
llvm::Optional<HoverInfo> HI;
// Macros and deducedtype only works on identifiers and auto/decltype keywords
// respectively. Therefore they are only trggered on whichever works for them,
// similar to SelectionTree::create().
for (const auto &Tok : TokensTouchingCursor) {
if (Tok.kind() == tok::identifier)
if (Tok.kind() == tok::identifier) {
IdentLoc = Tok.location();
if (Tok.kind() == tok::kw_auto || Tok.kind() == tok::kw_decltype)
AutoLoc = Tok.location();
if (auto M = locateMacroAt(Tok, AST.getPreprocessor())) {
HI = getHoverContents(*M, AST);
HI->SymRange = getTokenRange(AST.getSourceManager(), AST.getLangOpts(),
Tok.location());
break;
}
} else if (Tok.kind() == tok::kw_auto || Tok.kind() == tok::kw_decltype) {
if (auto Deduced = getDeducedType(AST.getASTContext(), Tok.location())) {
HI = getHoverContents(*Deduced, AST.getASTContext(), Index);
HI->SymRange = getTokenRange(AST.getSourceManager(), AST.getLangOpts(),
Tok.location());
break;
}
}
}

llvm::Optional<HoverInfo> HI;
if (auto Deduced = getDeducedType(AST.getASTContext(), AutoLoc)) {
HI = getHoverContents(*Deduced, AST.getASTContext(), Index);
HI->SymRange =
getTokenRange(AST.getSourceManager(), AST.getLangOpts(), AutoLoc);
} else if (auto M = locateMacroAt(IdentLoc, AST.getPreprocessor())) {
HI = getHoverContents(*M, AST);
HI->SymRange =
getTokenRange(AST.getSourceManager(), AST.getLangOpts(), IdentLoc);
} else {
// If it wasn't auto/decltype or macro, look for decls and expressions.
if (!HI) {
auto Offset = SM.getFileOffset(*CurLoc);
// Editors send the position on the left of the hovered character.
// So our selection tree should be biased right. (Tested with VSCode).
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 dc1257e

Please sign in to comment.