Skip to content

Commit

Permalink
LLVM and SPIRV-LLVM-Translator pulldown (WW49) #2836
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirlaz authored Dec 1, 2020
2 parents 07d0812 + 4fdbfae commit 20cb0da
Show file tree
Hide file tree
Showing 2,136 changed files with 48,825 additions and 49,583 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/main-branch-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: main branch sync

on:
push:
branches:
- 'master'

jobs:
branch_sync:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Update branch
env:
LLVMBOT_TOKEN: ${{ secrets.LLVMBOT_MAIN_SYNC }}
run: |
git push https://$LLVMBOT_TOKEN@github.com/${{ github.repository }} HEAD:temp-test-main
2 changes: 0 additions & 2 deletions clang-tools-extra/clang-query/QueryParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ QueryRef QueryParser::parseSetTraversalKind(
unsigned Value =
LexOrCompleteWord<unsigned>(this, ValStr)
.Case("AsIs", ast_type_traits::TK_AsIs)
.Case("IgnoreImplicitCastsAndParentheses",
ast_type_traits::TK_IgnoreImplicitCastsAndParentheses)
.Case("IgnoreUnlessSpelledInSource",
ast_type_traits::TK_IgnoreUnlessSpelledInSource)
.Default(~0u);
Expand Down
11 changes: 5 additions & 6 deletions clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,11 @@ void UnusedRaiiCheck::check(const MatchFinder::MatchResult &Result) {
// written type.
auto Matches =
match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
const auto *TL = selectFirst<TypeLoc>("t", Matches);
assert(TL);
D << FixItHint::CreateInsertion(
Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
getLangOpts()),
Replacement);
if (const auto *TL = selectFirst<TypeLoc>("t", Matches))
D << FixItHint::CreateInsertion(
Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
getLangOpts()),
Replacement);
}

} // namespace bugprone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ bool isCapsOnly(StringRef Name) {
class MacroUsageCallbacks : public PPCallbacks {
public:
MacroUsageCallbacks(MacroUsageCheck *Check, const SourceManager &SM,
StringRef RegExp, bool CapsOnly, bool IgnoreCommandLine)
: Check(Check), SM(SM), RegExp(RegExp), CheckCapsOnly(CapsOnly),
StringRef RegExpStr, bool CapsOnly, bool IgnoreCommandLine)
: Check(Check), SM(SM), RegExp(RegExpStr), CheckCapsOnly(CapsOnly),
IgnoreCommandLineMacros(IgnoreCommandLine) {}
void MacroDefined(const Token &MacroNameTok,
const MacroDirective *MD) override {
Expand All @@ -47,7 +47,7 @@ class MacroUsageCallbacks : public PPCallbacks {
return;

StringRef MacroName = MacroNameTok.getIdentifierInfo()->getName();
if (!CheckCapsOnly && !llvm::Regex(RegExp).match(MacroName))
if (!CheckCapsOnly && !RegExp.match(MacroName))
Check->warnMacro(MD, MacroName);

if (CheckCapsOnly && !isCapsOnly(MacroName))
Expand All @@ -57,7 +57,7 @@ class MacroUsageCallbacks : public PPCallbacks {
private:
MacroUsageCheck *Check;
const SourceManager &SM;
StringRef RegExp;
const llvm::Regex RegExp;
bool CheckCapsOnly;
bool IgnoreCommandLineMacros;
};
Expand Down
45 changes: 34 additions & 11 deletions clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,32 @@ static StringRef const StyleNames[] = {
#undef NAMING_KEYS
// clang-format on

IdentifierNamingCheck::NamingStyle::NamingStyle(
llvm::Optional<IdentifierNamingCheck::CaseType> Case,
const std::string &Prefix, const std::string &Suffix,
const std::string &IgnoredRegexpStr)
: Case(Case), Prefix(Prefix), Suffix(Suffix),
IgnoredRegexpStr(IgnoredRegexpStr) {
if (!IgnoredRegexpStr.empty()) {
IgnoredRegexp =
llvm::Regex(llvm::SmallString<128>({"^", IgnoredRegexpStr, "$"}));
if (!IgnoredRegexp.isValid())
llvm::errs() << "Invalid IgnoredRegexp regular expression: "
<< IgnoredRegexpStr;
}
}

static IdentifierNamingCheck::FileStyle
getFileStyleFromOptions(const ClangTidyCheck::OptionsView &Options) {
SmallVector<llvm::Optional<IdentifierNamingCheck::NamingStyle>, 0> Styles(
SK_Count);
SmallVector<llvm::Optional<IdentifierNamingCheck::NamingStyle>, 0> Styles;
Styles.resize(SK_Count);
SmallString<64> StyleString;
for (unsigned I = 0; I < SK_Count; ++I) {
StyleString = StyleNames[I];
size_t StyleSize = StyleString.size();
StyleString.append("IgnoredRegexp");
std::string IgnoredRegexpStr = Options.get(StyleString, "");
StyleString.resize(StyleSize);
StyleString.append("Prefix");
std::string Prefix(Options.get(StyleString, ""));
// Fast replacement of [Pre]fix -> [Suf]fix.
Expand All @@ -141,9 +159,10 @@ getFileStyleFromOptions(const ClangTidyCheck::OptionsView &Options) {
auto CaseOptional =
Options.getOptional<IdentifierNamingCheck::CaseType>(StyleString);

if (CaseOptional || !Prefix.empty() || !Postfix.empty())
if (CaseOptional || !Prefix.empty() || !Postfix.empty() ||
!IgnoredRegexpStr.empty())
Styles[I].emplace(std::move(CaseOptional), std::move(Prefix),
std::move(Postfix));
std::move(Postfix), std::move(IgnoredRegexpStr));
}
bool IgnoreMainLike = Options.get("IgnoreMainLikeFunctions", false);
return {std::move(Styles), IgnoreMainLike};
Expand Down Expand Up @@ -175,6 +194,9 @@ void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
continue;
StyleString = StyleNames[I];
size_t StyleSize = StyleString.size();
StyleString.append("IgnoredRegexp");
Options.store(Opts, StyleString, Styles[I]->IgnoredRegexpStr);
StyleString.resize(StyleSize);
StyleString.append("Prefix");
Options.store(Opts, StyleString, Styles[I]->Prefix);
// Fast replacement of [Pre]fix -> [Suf]fix.
Expand All @@ -194,7 +216,7 @@ void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}

static bool matchesStyle(StringRef Name,
IdentifierNamingCheck::NamingStyle Style) {
const IdentifierNamingCheck::NamingStyle &Style) {
static llvm::Regex Matchers[] = {
llvm::Regex("^.*$"),
llvm::Regex("^[a-z][a-z0-9_]*$"),
Expand Down Expand Up @@ -589,12 +611,10 @@ static StyleKind findStyleKind(

// If this method has the same name as any base method, this is likely
// necessary even if it's not an override. e.g. CRTP.
auto FindHidden = [&](const CXXBaseSpecifier *S, clang::CXXBasePath &P) {
return CXXRecordDecl::FindOrdinaryMember(S, P, Decl->getDeclName());
};
CXXBasePaths UnusedPaths;
if (Decl->getParent()->lookupInBases(FindHidden, UnusedPaths))
return SK_Invalid;
for (const CXXBaseSpecifier &Base : Decl->getParent()->bases())
if (const auto *RD = Base.getType()->getAsCXXRecordDecl())
if (RD->hasMemberName(Decl->getDeclName()))
return SK_Invalid;

if (Decl->isConstexpr() && NamingStyles[SK_ConstexprMethod])
return SK_ConstexprMethod;
Expand Down Expand Up @@ -681,6 +701,9 @@ static llvm::Optional<RenamerClangTidyCheck::FailureInfo> getFailureInfo(
return None;

const IdentifierNamingCheck::NamingStyle &Style = *NamingStyles[SK];
if (Style.IgnoredRegexp.isValid() && Style.IgnoredRegexp.match(Name))
return None;

if (matchesStyle(Name, Style))
return None;

Expand Down
10 changes: 8 additions & 2 deletions clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ class IdentifierNamingCheck final : public RenamerClangTidyCheck {
NamingStyle() = default;

NamingStyle(llvm::Optional<CaseType> Case, const std::string &Prefix,
const std::string &Suffix)
: Case(Case), Prefix(Prefix), Suffix(Suffix) {}
const std::string &Suffix, const std::string &IgnoredRegexpStr);
NamingStyle(const NamingStyle &O) = delete;
NamingStyle &operator=(NamingStyle &&O) = default;
NamingStyle(NamingStyle &&O) = default;

llvm::Optional<CaseType> Case;
std::string Prefix;
std::string Suffix;
// Store both compiled and non-compiled forms so original value can be
// serialized
llvm::Regex IgnoredRegexp;
std::string IgnoredRegexpStr;
};

struct FileStyle {
Expand Down
7 changes: 5 additions & 2 deletions clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ASTUtils.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
Expand Down Expand Up @@ -463,6 +464,8 @@ void RenamerClangTidyCheck::check(const MatchFinder::MatchResult &Result) {
Failure.FixStatus = ShouldFixStatus::ConflictsWithKeyword;
else if (Ident->hasMacroDefinition())
Failure.FixStatus = ShouldFixStatus::ConflictsWithMacroDefinition;
} else if (!isValidIdentifier(Info.Fixup)) {
Failure.FixStatus = ShouldFixStatus::FixInvalidIdentifier;
}

Failure.Info = std::move(Info);
Expand Down Expand Up @@ -503,7 +506,8 @@ void RenamerClangTidyCheck::expandMacro(const Token &MacroNameTok,
static std::string
getDiagnosticSuffix(const RenamerClangTidyCheck::ShouldFixStatus FixStatus,
const std::string &Fixup) {
if (Fixup.empty())
if (Fixup.empty() ||
FixStatus == RenamerClangTidyCheck::ShouldFixStatus::FixInvalidIdentifier)
return "; cannot be fixed automatically";
if (FixStatus == RenamerClangTidyCheck::ShouldFixStatus::ShouldFix)
return {};
Expand All @@ -517,7 +521,6 @@ getDiagnosticSuffix(const RenamerClangTidyCheck::ShouldFixStatus FixStatus,
RenamerClangTidyCheck::ShouldFixStatus::ConflictsWithMacroDefinition)
return "; cannot be fixed because '" + Fixup +
"' would conflict with a macro definition";

llvm_unreachable("invalid ShouldFixStatus");
}

Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class RenamerClangTidyCheck : public ClangTidyCheck {
/// automatically.
ConflictsWithMacroDefinition,

/// The fixup results in an identifier that is not a valid c/c++ identifier.
FixInvalidIdentifier,

/// Values pass this threshold will be ignored completely
/// i.e no message, no fixup.
IgnoreFailureThreshold,
Expand Down
14 changes: 8 additions & 6 deletions clang-tools-extra/clangd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ add_clang_library(clangDaemon
SemanticSelection.cpp
SourceCode.cpp
QueryDriverDatabase.cpp
TidyProvider.cpp
TUScheduler.cpp
URI.cpp
XRefs.cpp
Expand All @@ -97,6 +98,7 @@ add_clang_library(clangDaemon
index/IndexAction.cpp
index/MemIndex.cpp
index/Merge.cpp
index/ProjectAware.cpp
index/Ref.cpp
index/Relation.cpp
index/Serialization.cpp
Expand Down Expand Up @@ -139,7 +141,6 @@ clang_target_link_libraries(clangDaemon
clangTooling
clangToolingCore
clangToolingInclusions
clangToolingRefactoring
clangToolingSyntax
)

Expand Down Expand Up @@ -168,17 +169,18 @@ if ( CLANGD_BUILD_XPC )
add_subdirectory(xpc)
endif ()

if (CLANGD_ENABLE_REMOTE)
include(FindGRPC)
endif()

if(CLANG_INCLUDE_TESTS)
add_subdirectory(test)
add_subdirectory(unittests)
add_subdirectory(test)
add_subdirectory(unittests)
endif()

# FIXME(kirillbobyrev): Document this in the LLVM docs once remote index is stable.
option(CLANGD_ENABLE_REMOTE "Use gRPC library to enable remote index support for Clangd" OFF)
set(GRPC_INSTALL_PATH "" CACHE PATH "Path to gRPC library manual installation.")

if (CLANGD_ENABLE_REMOTE)
include(FindGRPC)
endif()
add_subdirectory(index/remote)
add_subdirectory(index/dex/dexp)
42 changes: 42 additions & 0 deletions clang-tools-extra/clangd/ClangdLSPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
}},
{"declarationProvider", true},
{"definitionProvider", true},
{"implementationProvider", true},
{"documentHighlightProvider", true},
{"documentLinkProvider",
llvm::json::Object{
Expand All @@ -624,6 +625,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
}},
{"typeHierarchyProvider", true},
{"memoryUsageProvider", true}, // clangd extension.
{"callHierarchyProvider", true},
}}}};
if (Opts.Encoding)
Result["offsetEncoding"] = *Opts.Encoding;
Expand Down Expand Up @@ -1223,6 +1225,26 @@ void ClangdLSPServer::onResolveTypeHierarchy(
std::move(Reply));
}

void ClangdLSPServer::onPrepareCallHierarchy(
const CallHierarchyPrepareParams &Params,
Callback<std::vector<CallHierarchyItem>> Reply) {
Server->prepareCallHierarchy(Params.textDocument.uri.file(), Params.position,
std::move(Reply));
}

void ClangdLSPServer::onCallHierarchyIncomingCalls(
const CallHierarchyIncomingCallsParams &Params,
Callback<std::vector<CallHierarchyIncomingCall>> Reply) {
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::applyConfiguration(
const ConfigurationSettings &Settings) {
// Per-file update to the compilation database.
Expand Down Expand Up @@ -1291,6 +1313,22 @@ void ClangdLSPServer::onReference(const ReferenceParams &Params,
});
}

void ClangdLSPServer::onGoToImplementation(
const TextDocumentPositionParams &Params,
Callback<std::vector<Location>> Reply) {
Server->findImplementations(
Params.textDocument.uri.file(), Params.position,
[Reply = std::move(Reply)](
llvm::Expected<std::vector<LocatedSymbol>> Overrides) mutable {
if (!Overrides)
return Reply(Overrides.takeError());
std::vector<Location> Impls;
for (const LocatedSymbol &Sym : *Overrides)
Impls.push_back(Sym.PreferredDeclaration);
return Reply(std::move(Impls));
});
}

void ClangdLSPServer::onSymbolInfo(const TextDocumentPositionParams &Params,
Callback<std::vector<SymbolDetails>> Reply) {
Server->symbolInfo(Params.textDocument.uri.file(), Params.position,
Expand Down Expand Up @@ -1431,6 +1469,7 @@ ClangdLSPServer::ClangdLSPServer(class Transport &Transp,
MsgHandler->bind("textDocument/signatureHelp", &ClangdLSPServer::onSignatureHelp);
MsgHandler->bind("textDocument/definition", &ClangdLSPServer::onGoToDefinition);
MsgHandler->bind("textDocument/declaration", &ClangdLSPServer::onGoToDeclaration);
MsgHandler->bind("textDocument/implementation", &ClangdLSPServer::onGoToImplementation);
MsgHandler->bind("textDocument/references", &ClangdLSPServer::onReference);
MsgHandler->bind("textDocument/switchSourceHeader", &ClangdLSPServer::onSwitchSourceHeader);
MsgHandler->bind("textDocument/prepareRename", &ClangdLSPServer::onPrepareRename);
Expand All @@ -1450,6 +1489,9 @@ ClangdLSPServer::ClangdLSPServer(class Transport &Transp,
MsgHandler->bind("textDocument/symbolInfo", &ClangdLSPServer::onSymbolInfo);
MsgHandler->bind("textDocument/typeHierarchy", &ClangdLSPServer::onTypeHierarchy);
MsgHandler->bind("typeHierarchy/resolve", &ClangdLSPServer::onResolveTypeHierarchy);
MsgHandler->bind("textDocument/prepareCallHierarchy", &ClangdLSPServer::onPrepareCallHierarchy);
MsgHandler->bind("callHierarchy/incomingCalls", &ClangdLSPServer::onCallHierarchyIncomingCalls);
MsgHandler->bind("callHierarchy/outgoingCalls", &ClangdLSPServer::onCallHierarchyOutgoingCalls);
MsgHandler->bind("textDocument/selectionRange", &ClangdLSPServer::onSelectionRange);
MsgHandler->bind("textDocument/documentLink", &ClangdLSPServer::onDocumentLink);
MsgHandler->bind("textDocument/semanticTokens/full", &ClangdLSPServer::onSemanticTokens);
Expand Down
10 changes: 10 additions & 0 deletions clang-tools-extra/clangd/ClangdLSPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
Callback<std::vector<Location>>);
void onGoToDefinition(const TextDocumentPositionParams &,
Callback<std::vector<Location>>);
void onGoToImplementation(const TextDocumentPositionParams &,
Callback<std::vector<Location>>);
void onReference(const ReferenceParams &, Callback<std::vector<Location>>);
void onSwitchSourceHeader(const TextDocumentIdentifier &,
Callback<llvm::Optional<URIForFile>>);
Expand All @@ -133,6 +135,14 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
Callback<llvm::Optional<TypeHierarchyItem>>);
void onResolveTypeHierarchy(const ResolveTypeHierarchyItemParams &,
Callback<llvm::Optional<TypeHierarchyItem>>);
void onPrepareCallHierarchy(const CallHierarchyPrepareParams &,
Callback<std::vector<CallHierarchyItem>>);
void onCallHierarchyIncomingCalls(
const CallHierarchyIncomingCallsParams &,
Callback<std::vector<CallHierarchyIncomingCall>>);
void onCallHierarchyOutgoingCalls(
const CallHierarchyOutgoingCallsParams &,
Callback<std::vector<CallHierarchyOutgoingCall>>);
void onChangeConfiguration(const DidChangeConfigurationParams &);
void onSymbolInfo(const TextDocumentPositionParams &,
Callback<std::vector<SymbolDetails>>);
Expand Down
Loading

0 comments on commit 20cb0da

Please sign in to comment.