Skip to content

Commit

Permalink
LLVM and SPIRV-LLVM-Translator pulldown (WW01)
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-sycl committed Dec 29, 2021
2 parents 8dae986 + e07fa00 commit 7b7e044
Show file tree
Hide file tree
Showing 1,487 changed files with 127,591 additions and 111,654 deletions.
21 changes: 11 additions & 10 deletions clang-tools-extra/clang-include-fixer/SymbolIndexManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

#include "SymbolIndexManager.h"
#include "find-all-symbols/SymbolInfo.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Path.h"

Expand Down Expand Up @@ -47,7 +48,7 @@ static double similarityScore(llvm::StringRef FileName,

static void rank(std::vector<SymbolAndSignals> &Symbols,
llvm::StringRef FileName) {
llvm::DenseMap<llvm::StringRef, double> Score;
llvm::StringMap<double> Score;
for (const auto &Symbol : Symbols) {
// Calculate a score from the similarity of the header the symbol is in
// with the current file and the popularity of the symbol.
Expand All @@ -58,14 +59,14 @@ static void rank(std::vector<SymbolAndSignals> &Symbols,
}
// Sort by the gathered scores. Use file name as a tie breaker so we can
// deduplicate.
std::sort(Symbols.begin(), Symbols.end(),
[&](const SymbolAndSignals &A, const SymbolAndSignals &B) {
auto AS = Score[A.Symbol.getFilePath()];
auto BS = Score[B.Symbol.getFilePath()];
if (AS != BS)
return AS > BS;
return A.Symbol.getFilePath() < B.Symbol.getFilePath();
});
llvm::sort(Symbols.begin(), Symbols.end(),
[&](const SymbolAndSignals &A, const SymbolAndSignals &B) {
auto AS = Score[A.Symbol.getFilePath()];
auto BS = Score[B.Symbol.getFilePath()];
if (AS != BS)
return AS > BS;
return A.Symbol.getFilePath() < B.Symbol.getFilePath();
});
}

std::vector<find_all_symbols::SymbolInfo>
Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ DiagnosticBuilder ClangTidyContext::diag(const ClangTidyError &Error) {
SM.getFileManager().getFile(Error.Message.FilePath);
FileID ID = SM.getOrCreateFileID(*File, SrcMgr::C_User);
SourceLocation FileStartLoc = SM.getLocForStartOfFile(ID);
SourceLocation Loc = FileStartLoc.getLocWithOffset(Error.Message.FileOffset);
SourceLocation Loc = FileStartLoc.getLocWithOffset(
static_cast<SourceLocation::IntTy>(Error.Message.FileOffset));
return diag(Error.DiagnosticName, Loc, Error.Message.Message,
static_cast<DiagnosticIDs::Level>(Error.DiagLevel));
}
Expand Down
6 changes: 2 additions & 4 deletions clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,12 @@ getFixIt(const tooling::Diagnostic &Diagnostic, bool AnyFix);

/// A diagnostic consumer that turns each \c Diagnostic into a
/// \c SourceManager-independent \c ClangTidyError.
///
/// \param EnableNolintBlocks Enables diagnostic-disabling inside blocks of
/// code, delimited by NOLINTBEGIN and NOLINTEND.
//
// FIXME: If we move away from unit-tests, this can be moved to a private
// implementation file.
class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {
public:
/// \param EnableNolintBlocks Enables diagnostic-disabling inside blocks of
/// code, delimited by NOLINTBEGIN and NOLINTEND.
ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx,
DiagnosticsEngine *ExternalDiagEngine = nullptr,
bool RemoveIncompatibleErrors = true,
Expand Down
35 changes: 30 additions & 5 deletions clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void StringFindStartswithCheck::registerMatchers(MatchFinder *Finder) {

auto StringFind = cxxMemberCallExpr(
// .find()-call on a string...
callee(cxxMethodDecl(hasName("find"))),
callee(cxxMethodDecl(hasName("find")).bind("findfun")),
on(hasType(StringType)),
// ... with some search expression ...
hasArgument(0, expr().bind("needle")),
Expand All @@ -55,6 +55,25 @@ void StringFindStartswithCheck::registerMatchers(MatchFinder *Finder) {
ignoringParenImpCasts(StringFind.bind("findexpr"))))
.bind("expr"),
this);

auto StringRFind = cxxMemberCallExpr(
// .rfind()-call on a string...
callee(cxxMethodDecl(hasName("rfind")).bind("findfun")),
on(hasType(StringType)),
// ... with some search expression ...
hasArgument(0, expr().bind("needle")),
// ... and "0" as second argument.
hasArgument(1, ZeroLiteral));

Finder->addMatcher(
// Match [=!]= with either a zero or npos on one side and a string.rfind
// on the other.
binaryOperator(
hasAnyOperatorName("==", "!="),
hasOperands(ignoringParenImpCasts(ZeroLiteral),
ignoringParenImpCasts(StringRFind.bind("findexpr"))))
.bind("expr"),
this);
}

void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) {
Expand All @@ -69,6 +88,11 @@ void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) {
const Expr *Haystack = Result.Nodes.getNodeAs<CXXMemberCallExpr>("findexpr")
->getImplicitObjectArgument();
assert(Haystack != nullptr);
const CXXMethodDecl *FindFun =
Result.Nodes.getNodeAs<CXXMethodDecl>("findfun");
assert(FindFun != nullptr);

bool Rev = FindFun->getName().contains("rfind");

if (ComparisonExpr->getBeginLoc().isMacroID())
return;
Expand All @@ -86,10 +110,11 @@ void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) {
bool Neg = ComparisonExpr->getOpcode() == BO_NE;

// Create the warning message and a FixIt hint replacing the original expr.
auto Diagnostic = diag(ComparisonExpr->getBeginLoc(),
"use %select{absl::StartsWith|!absl::StartsWith}0 "
"instead of find() %select{==|!=}0 0")
<< Neg;
auto Diagnostic =
diag(ComparisonExpr->getBeginLoc(),
"use %select{absl::StartsWith|!absl::StartsWith}0 "
"instead of %select{find()|rfind()}1 %select{==|!=}0 0")
<< Neg << Rev;

Diagnostic << FixItHint::CreateReplacement(
ComparisonExpr->getSourceRange(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ void UpgradeGoogletestCaseCheck::registerMatchers(MatchFinder *Finder) {
usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(TestCaseTypeAlias)))
.bind("using"),
this);
Finder->addMatcher(
typeLoc(loc(usingType(hasUnderlyingType(
typedefType(hasDeclaration(TestCaseTypeAlias))))),
unless(hasAncestor(decl(isImplicit()))), LocationFilter)
.bind("typeloc"),
this);
}

static llvm::StringRef getNewMethodName(llvm::StringRef CurrentName) {
Expand Down
16 changes: 13 additions & 3 deletions clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl,
return DeclMatcher.matches(*TD, Finder, Builder);
return false;
}

} // namespace

// A function that helps to tell whether a TargetDecl in a UsingDecl will be
Expand All @@ -60,13 +61,10 @@ static bool shouldCheckDecl(const Decl *TargetDecl) {
void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(usingDecl(isExpansionInMainFile()).bind("using"), this);
auto DeclMatcher = hasDeclaration(namedDecl().bind("used"));
Finder->addMatcher(loc(enumType(DeclMatcher)), this);
Finder->addMatcher(loc(recordType(DeclMatcher)), this);
Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
Finder->addMatcher(loc(deducedTemplateSpecializationType(
refsToTemplatedDecl(namedDecl().bind("used")))),
this);
Finder->addMatcher(declRefExpr().bind("used"), this);
Finder->addMatcher(callExpr(callee(unresolvedLookupExpr().bind("used"))),
this);
Finder->addMatcher(
Expand All @@ -76,6 +74,12 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(loc(templateSpecializationType(forEachTemplateArgument(
templateArgument().bind("used")))),
this);
// Cases where we can identify the UsingShadowDecl directly, rather than
// just its target.
// FIXME: cover more cases in this way, as the AST supports it.
auto ThroughShadowMatcher = throughUsingDecl(namedDecl().bind("usedShadow"));
Finder->addMatcher(declRefExpr(ThroughShadowMatcher), this);
Finder->addMatcher(loc(usingType(ThroughShadowMatcher)), this);
}

void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
Expand Down Expand Up @@ -137,6 +141,12 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
return;
}

if (const auto *UsedShadow =
Result.Nodes.getNodeAs<UsingShadowDecl>("usedShadow")) {
removeFromFoundDecls(UsedShadow->getTargetDecl());
return;
}

if (const auto *Used = Result.Nodes.getNodeAs<TemplateArgument>("used")) {
if (Used->getKind() == TemplateArgument::Template) {
if (const auto *TD = Used->getAsTemplate().getAsTemplateDecl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ struct UnqualNameVisitor : public RecursiveASTVisitor<UnqualNameVisitor> {
TL.getAs<TypedefTypeLoc>().getTypePtr()->getDecl()->getName()))
return false;
break;
case TypeLoc::Using:
if (visitUnqualName(TL.getAs<UsingTypeLoc>()
.getTypePtr()
->getFoundDecl()
->getName()))
return false;
break;
default:
break;
}
Expand Down
8 changes: 0 additions & 8 deletions clang-tools-extra/clangd/ClangdLSPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,13 +1208,6 @@ void ClangdLSPServer::onCallHierarchyIncomingCalls(
Server->incomingCalls(Params.item, std::move(Reply));
}

void ClangdLSPServer::onCallHierarchyOutgoingCalls(
const CallHierarchyOutgoingCallsParams &Params,
Callback<std::vector<CallHierarchyOutgoingCall>> Reply) {
// FIXME: To be implemented.
Reply(std::vector<CallHierarchyOutgoingCall>{});
}

void ClangdLSPServer::onInlayHints(const InlayHintsParams &Params,
Callback<std::vector<InlayHint>> Reply) {
Server->inlayHints(Params.textDocument.uri.file(), std::move(Reply));
Expand Down Expand Up @@ -1478,7 +1471,6 @@ void ClangdLSPServer::bindMethods(LSPBinder &Bind,
Bind.method("typeHierarchy/resolve", this, &ClangdLSPServer::onResolveTypeHierarchy);
Bind.method("textDocument/prepareCallHierarchy", this, &ClangdLSPServer::onPrepareCallHierarchy);
Bind.method("callHierarchy/incomingCalls", this, &ClangdLSPServer::onCallHierarchyIncomingCalls);
Bind.method("callHierarchy/outgoingCalls", this, &ClangdLSPServer::onCallHierarchyOutgoingCalls);
Bind.method("textDocument/selectionRange", this, &ClangdLSPServer::onSelectionRange);
Bind.method("textDocument/documentLink", this, &ClangdLSPServer::onDocumentLink);
Bind.method("textDocument/semanticTokens/full", this, &ClangdLSPServer::onSemanticTokens);
Expand Down
11 changes: 11 additions & 0 deletions clang-tools-extra/clangd/FindTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ struct TargetFinder {
Outer.add(ET->desugar(), Flags);
}

void VisitUsingType(const UsingType *ET) {
Outer.add(ET->getFoundDecl(), Flags);
}

void VisitInjectedClassNameType(const InjectedClassNameType *ICNT) {
Outer.add(ICNT->getDecl(), Flags);
}
Expand Down Expand Up @@ -855,6 +859,13 @@ refInTypeLoc(TypeLoc L, const HeuristicResolver *Resolver) {
}
}

void VisitUsingTypeLoc(UsingTypeLoc L) {
Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
L.getLocalSourceRange().getBegin(),
/*IsDecl=*/false,
{L.getFoundDecl()}});
}

void VisitTagTypeLoc(TagTypeLoc L) {
Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
L.getNameLoc(),
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/clangd/IncludeCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class ReferencedLocationCrawler
return true;
}

bool VisitUsingType(UsingType *UT) {
add(UT->getFoundDecl());
return true;
}

bool VisitTypedefType(TypedefType *TT) {
add(TT->getDecl());
return true;
Expand Down
Loading

0 comments on commit 7b7e044

Please sign in to comment.