Skip to content

Commit

Permalink
LLVM and LLVM-SPIRV-Translator pulldown
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirlaz authored Apr 30, 2020
2 parents abe533c + 6b757e5 commit 1a5165e
Show file tree
Hide file tree
Showing 2,907 changed files with 85,917 additions and 25,731 deletions.
21 changes: 8 additions & 13 deletions clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@ namespace abseil {
// `FactoryName`, return `None`.
static llvm::Optional<DurationScale>
getScaleForFactory(llvm::StringRef FactoryName) {
static const std::unordered_map<std::string, DurationScale> ScaleMap(
{{"Nanoseconds", DurationScale::Nanoseconds},
{"Microseconds", DurationScale::Microseconds},
{"Milliseconds", DurationScale::Milliseconds},
{"Seconds", DurationScale::Seconds},
{"Minutes", DurationScale::Minutes},
{"Hours", DurationScale::Hours}});

auto ScaleIter = ScaleMap.find(std::string(FactoryName));
if (ScaleIter == ScaleMap.end())
return llvm::None;

return ScaleIter->second;
return llvm::StringSwitch<llvm::Optional<DurationScale>>(FactoryName)
.Case("Nanoseconds", DurationScale::Nanoseconds)
.Case("Microseconds", DurationScale::Microseconds)
.Case("Milliseconds", DurationScale::Milliseconds)
.Case("Seconds", DurationScale::Seconds)
.Case("Minutes", DurationScale::Minutes)
.Case("Hours", DurationScale::Hours)
.Default(llvm::None);
}

// Given either an integer or float literal, return its value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
// Don't suggest fixes for bitfields because in-class initialization is not
// possible until C++2a.
if (F->getType()->isEnumeralType() ||
(!getLangOpts().CPlusPlus2a && F->isBitField()))
(!getLangOpts().CPlusPlus20 && F->isBitField()))
return;
if (!F->getParent()->isUnion() || UnionsSeen.insert(F->getParent()).second)
FieldsToFix.insert(F);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ static constexpr std::array<StringRef, 5> DeprecatedTypes = {
"::std::ios_base::seek_dir", "::std::ios_base::streamoff",
"::std::ios_base::streampos"};

static const llvm::StringMap<StringRef> ReplacementTypes = {
{"io_state", "iostate"},
{"open_mode", "openmode"},
{"seek_dir", "seekdir"}};
static llvm::Optional<const char *> getReplacementType(StringRef Type) {
return llvm::StringSwitch<llvm::Optional<const char *>>(Type)
.Case("io_state", "iostate")
.Case("open_mode", "openmode")
.Case("seek_dir", "seekdir")
.Default(llvm::None);
}

void DeprecatedIosBaseAliasesCheck::registerMatchers(MatchFinder *Finder) {
auto IoStateDecl = typedefDecl(hasAnyName(DeprecatedTypes)).bind("TypeDecl");
Expand All @@ -40,23 +43,23 @@ void DeprecatedIosBaseAliasesCheck::check(

const auto *Typedef = Result.Nodes.getNodeAs<TypedefDecl>("TypeDecl");
StringRef TypeName = Typedef->getName();
bool HasReplacement = ReplacementTypes.count(TypeName);
auto Replacement = getReplacementType(TypeName);

const auto *TL = Result.Nodes.getNodeAs<TypeLoc>("TypeLoc");
SourceLocation IoStateLoc = TL->getBeginLoc();

// Do not generate fixits for matches depending on template arguments and
// macro expansions.
bool Fix = HasReplacement && !TL->getType()->isDependentType();
bool Fix = Replacement && !TL->getType()->isDependentType();
if (IoStateLoc.isMacroID()) {
IoStateLoc = SM.getSpellingLoc(IoStateLoc);
Fix = false;
}

SourceLocation EndLoc = IoStateLoc.getLocWithOffset(TypeName.size() - 1);

if (HasReplacement) {
auto FixName = ReplacementTypes.lookup(TypeName);
if (Replacement) {
auto FixName = *Replacement;
auto Builder = diag(IoStateLoc, "'std::ios_base::%0' is deprecated; use "
"'std::ios_base::%1' instead")
<< TypeName << FixName;
Expand Down
17 changes: 8 additions & 9 deletions clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,11 @@ void LoopConvertCheck::doConversion(
const ValueDecl *MaybeContainer, const UsageResult &Usages,
const DeclStmt *AliasDecl, bool AliasUseRequired, bool AliasFromForInit,
const ForStmt *Loop, RangeDescriptor Descriptor) {
auto Diag = diag(Loop->getForLoc(), "use range-based for loop instead");

std::string VarName;
bool VarNameFromAlias = (Usages.size() == 1) && AliasDecl;
bool AliasVarIsRef = false;
bool CanCopy = true;

std::vector<FixItHint> FixIts;
if (VarNameFromAlias) {
const auto *AliasVar = cast<VarDecl>(AliasDecl->getSingleDecl());
VarName = AliasVar->getName().str();
Expand Down Expand Up @@ -563,8 +561,8 @@ void LoopConvertCheck::doConversion(
getAliasRange(Context->getSourceManager(), ReplaceRange);
}

Diag << FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(ReplaceRange), ReplacementText);
FixIts.push_back(FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(ReplaceRange), ReplacementText));
// No further replacements are made to the loop, since the iterator or index
// was used exactly once - in the initialization of AliasVar.
} else {
Expand Down Expand Up @@ -609,8 +607,8 @@ void LoopConvertCheck::doConversion(
Usage.Kind == Usage::UK_CaptureByCopy ? "&" + VarName : VarName;
}
TUInfo->getReplacedVars().insert(std::make_pair(Loop, IndexVar));
Diag << FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(Range), ReplaceText);
FixIts.push_back(FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(Range), ReplaceText));
}
}

Expand Down Expand Up @@ -648,8 +646,9 @@ void LoopConvertCheck::doConversion(
std::string Range = ("(" + TypeString + " " + VarName + " : " +
MaybeDereference + Descriptor.ContainerString + ")")
.str();
Diag << FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(ParenRange), Range);
FixIts.push_back(FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(ParenRange), Range));
diag(Loop->getForLoc(), "use range-based for loop instead") << FixIts;
TUInfo->getGeneratedDecls().insert(make_pair(Loop, VarName));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
isDefaultConstructor(), unless(isInstantiated()),
forEachConstructorInitializer(
cxxCtorInitializer(
forField(unless(anyOf(getLangOpts().CPlusPlus2a
forField(unless(anyOf(getLangOpts().CPlusPlus20
? unless(anything())
: isBitField(),
hasInClassInitializer(anything()),
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
printPolicy.SuppressScope = true;
printPolicy.ConstantArraySizeAsWritten = true;
printPolicy.UseVoidForZeroParams = false;
printPolicy.PrintInjectedClassNameWithArguments = false;

std::string Type = MatchedDecl->getUnderlyingType().getAsString(printPolicy);
std::string Name = MatchedDecl->getNameAsString();
Expand Down
26 changes: 10 additions & 16 deletions clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,15 @@ static StringRef TrySuggestPPC(StringRef Name) {
if (!Name.consume_front("vec_"))
return {};

static const llvm::StringMap<StringRef> Mapping{
// [simd.alg]
{"max", "$std::max"},
{"min", "$std::min"},

// [simd.binary]
{"add", "operator+ on $simd objects"},
{"sub", "operator- on $simd objects"},
{"mul", "operator* on $simd objects"},
};

auto It = Mapping.find(Name);
if (It != Mapping.end())
return It->second;
return {};
return llvm::StringSwitch<StringRef>(Name)
// [simd.alg]
.Case("max", "$std::max")
.Case("min", "$std::min")
// [simd.binary]
.Case("add", "operator+ on $simd objects")
.Case("sub", "operator- on $simd objects")
.Case("mul", "operator* on $simd objects")
.Default({});
}

static StringRef TrySuggestX86(StringRef Name) {
Expand Down Expand Up @@ -96,7 +90,7 @@ void SIMDIntrinsicsCheck::registerMatchers(MatchFinder *Finder) {
// If Std is not specified, infer it from the language options.
// libcxx implementation backports it to C++11 std::experimental::simd.
if (Std.empty())
Std = getLangOpts().CPlusPlus2a ? "std" : "std::experimental";
Std = getLangOpts().CPlusPlus20 ? "std" : "std::experimental";

Finder->addMatcher(callExpr(callee(functionDecl(
matchesName("^::(_mm_|_mm256_|_mm512_|vec_)"),
Expand Down
12 changes: 10 additions & 2 deletions clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ def make_absolute(f, directory):


def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
header_filter, extra_arg, extra_arg_before, quiet,
config):
header_filter, allow_enabling_alpha_checkers,
extra_arg, extra_arg_before, quiet, config):
"""Gets a command line for clang-tidy."""
start = [clang_tidy_binary]
if allow_enabling_alpha_checkers is not None:
start.append('-allow-enabling-analyzer-alpha-checkers')
if header_filter is not None:
start.append('-header-filter=' + header_filter)
if checks:
Expand Down Expand Up @@ -159,6 +161,7 @@ def run_tidy(args, tmpdir, build_path, queue, lock, failed_files):
name = queue.get()
invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks,
tmpdir, build_path, args.header_filter,
args.allow_enabling_alpha_checkers,
args.extra_arg, args.extra_arg_before,
args.quiet, args.config)

Expand All @@ -179,6 +182,9 @@ def main():
'in a compilation database. Requires '
'clang-tidy and clang-apply-replacements in '
'$PATH.')
parser.add_argument('-allow-enabling-alpha-checkers',
action='store_true', help='allow alpha checkers from '
'clang-analyzer.')
parser.add_argument('-clang-tidy-binary', metavar='PATH',
default='clang-tidy',
help='path to clang-tidy binary')
Expand Down Expand Up @@ -238,6 +244,8 @@ def main():

try:
invocation = [args.clang_tidy_binary, '-list-checks']
if args.allow_enabling_alpha_checkers:
invocation.append('-allow-enabling-analyzer-alpha-checkers')
invocation.append('-p=' + build_path)
if args.checks:
invocation.append('-checks=' + args.checks)
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
endif()
add_subdirectory(tool)
add_subdirectory(indexer)
add_subdirectory(index/dex/dexp)

if (LLVM_INCLUDE_BENCHMARKS)
add_subdirectory(benchmarks)
Expand All @@ -160,5 +159,6 @@ set(GRPC_INSTALL_PATH "" CACHE PATH "Path to gRPC library manual installation.")

if (CLANGD_ENABLE_REMOTE)
include(FindGRPC)
add_subdirectory(index/remote)
endif()
add_subdirectory(index/remote)
add_subdirectory(index/dex/dexp)
7 changes: 2 additions & 5 deletions clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,8 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos,
Pos, FS, Index));
};

// Unlike code completion, we wait for an up-to-date preamble here.
// Signature help is often triggered after code completion. If the code
// completion inserted a header to make the symbol available, then using
// the old preamble would yield useless results.
WorkScheduler.runWithPreamble("SignatureHelp", File, TUScheduler::Consistent,
// Unlike code completion, we wait for a preamble here.
WorkScheduler.runWithPreamble("SignatureHelp", File, TUScheduler::Stale,
std::move(Action));
}

Expand Down
18 changes: 13 additions & 5 deletions clang-tools-extra/clangd/CodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ struct SemaCompleteInput {
PathRef FileName;
const tooling::CompileCommand &Command;
const PreambleData &Preamble;
const PreamblePatch &Patch;
llvm::StringRef Contents;
size_t Offset;
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
Expand Down Expand Up @@ -1060,7 +1061,6 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
ParseInput.CompileCommand = Input.Command;
ParseInput.FS = VFS;
ParseInput.Contents = std::string(Input.Contents);
ParseInput.Opts = ParseOptions();

IgnoreDiagnostics IgnoreDiags;
auto CI = buildCompilerInvocation(ParseInput, IgnoreDiags);
Expand Down Expand Up @@ -1096,6 +1096,7 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
PreambleBounds PreambleRegion =
ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
bool CompletingInPreamble = PreambleRegion.Size > Input.Offset;
Input.Patch.apply(*CI);
// NOTE: we must call BeginSourceFile after prepareCompilerInstance. Otherwise
// the remapped buffers do not get freed.
auto Clang = prepareCompilerInstance(
Expand Down Expand Up @@ -1754,8 +1755,10 @@ codeComplete(PathRef FileName, const tooling::CompileCommand &Command,
SpecFuzzyFind, Opts);
return (!Preamble || Opts.RunParser == CodeCompleteOptions::NeverParse)
? std::move(Flow).runWithoutSema(Contents, *Offset, VFS)
: std::move(Flow).run(
{FileName, Command, *Preamble, Contents, *Offset, VFS});
: std::move(Flow).run({FileName, Command, *Preamble,
// We want to serve code completions with
// low latency, so don't bother patching.
PreamblePatch(), Contents, *Offset, VFS});
}

SignatureHelp signatureHelp(PathRef FileName,
Expand All @@ -1775,10 +1778,15 @@ SignatureHelp signatureHelp(PathRef FileName,
Options.IncludeMacros = false;
Options.IncludeCodePatterns = false;
Options.IncludeBriefComments = false;
IncludeStructure PreambleInclusions; // Unused for signatureHelp

ParseInputs PI;
PI.CompileCommand = Command;
PI.Contents = Contents.str();
PI.FS = std::move(VFS);
auto PP = PreamblePatch::create(FileName, PI, Preamble);
semaCodeComplete(
std::make_unique<SignatureHelpCollector>(Options, Index, Result), Options,
{FileName, Command, Preamble, Contents, *Offset, std::move(VFS)});
{FileName, Command, Preamble, PP, Contents, *Offset, std::move(PI.FS)});
return Result;
}

Expand Down
9 changes: 9 additions & 0 deletions clang-tools-extra/clangd/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ buildCompilerInvocation(const ParseInputs &Inputs,
CI->getFrontendOpts().DisableFree = false;
CI->getLangOpts()->CommentOpts.ParseAllComments = true;
CI->getLangOpts()->RetainCommentsFromSystemHeaders = true;

// Disable any dependency outputting, we don't want to generate files or write
// to stdout/stderr.
CI->getDependencyOutputOpts().ShowIncludesDest =
ShowIncludesDestination::None;
CI->getDependencyOutputOpts().OutputFile.clear();
CI->getDependencyOutputOpts().HeaderIncludeOutputFile.clear();
CI->getDependencyOutputOpts().DOTOutputFile.clear();
CI->getDependencyOutputOpts().ModuleDependencyOutputDir.clear();
return CI;
}

Expand Down
23 changes: 18 additions & 5 deletions clang-tools-extra/clangd/Diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,23 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
if (!InsideMainFile)
return false;

// Copy as we may modify the ranges.
auto FixIts = Info.getFixItHints().vec();
llvm::SmallVector<TextEdit, 1> Edits;
for (auto &FixIt : Info.getFixItHints()) {
// Follow clang's behavior, don't apply FixIt to the code in macros,
// we are less certain it is the right fix.
for (auto &FixIt : FixIts) {
// Allow fixits within a single macro-arg expansion to be applied.
// This can be incorrect if the argument is expanded multiple times in
// different contexts. Hopefully this is rare!
if (FixIt.RemoveRange.getBegin().isMacroID() &&
FixIt.RemoveRange.getEnd().isMacroID() &&
SM.getFileID(FixIt.RemoveRange.getBegin()) ==
SM.getFileID(FixIt.RemoveRange.getEnd())) {
FixIt.RemoveRange = CharSourceRange(
{SM.getTopMacroCallerLoc(FixIt.RemoveRange.getBegin()),
SM.getTopMacroCallerLoc(FixIt.RemoveRange.getEnd())},
FixIt.RemoveRange.isTokenRange());
}
// Otherwise, follow clang's behavior: no fixits in macros.
if (FixIt.RemoveRange.getBegin().isMacroID() ||
FixIt.RemoveRange.getEnd().isMacroID())
return false;
Expand All @@ -570,8 +583,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,

llvm::SmallString<64> Message;
// If requested and possible, create a message like "change 'foo' to 'bar'".
if (SyntheticMessage && Info.getNumFixItHints() == 1) {
const auto &FixIt = Info.getFixItHint(0);
if (SyntheticMessage && FixIts.size() == 1) {
const auto &FixIt = FixIts.front();
bool Invalid = false;
llvm::StringRef Remove =
Lexer::getSourceText(FixIt.RemoveRange, SM, *LangOpts, &Invalid);
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/Features.inc.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMOTE@
10 changes: 6 additions & 4 deletions clang-tools-extra/clangd/FindTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,15 +860,17 @@ class ExplicitReferenceCollector
// TemplateArgumentLoc is the only way to get locations for references to
// template template parameters.
bool TraverseTemplateArgumentLoc(TemplateArgumentLoc A) {
llvm::SmallVector<const NamedDecl *, 1> Targets;
switch (A.getArgument().getKind()) {
case TemplateArgument::Template:
case TemplateArgument::TemplateExpansion:
if (const auto *D = A.getArgument()
.getAsTemplateOrTemplatePattern()
.getAsTemplateDecl())
Targets.push_back(D);
reportReference(ReferenceLoc{A.getTemplateQualifierLoc(),
A.getTemplateNameLoc(),
/*IsDecl=*/false,
{A.getArgument()
.getAsTemplateOrTemplatePattern()
.getAsTemplateDecl()}},
/*IsDecl=*/false, Targets},
DynTypedNode::create(A.getArgument()));
break;
case TemplateArgument::Declaration:
Expand Down
Loading

0 comments on commit 1a5165e

Please sign in to comment.