Skip to content

Commit 1a5165e

Browse files
authored
LLVM and LLVM-SPIRV-Translator pulldown
LLVM: 145dcef LLVM-SPIRV-Translator: KhronosGroup/SPIRV-LLVM-Translator@10cdc73
2 parents abe533c + 6b757e5 commit 1a5165e

File tree

2,907 files changed

+85917
-25731
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,907 files changed

+85917
-25731
lines changed

clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp

+8-13
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,14 @@ namespace abseil {
2323
// `FactoryName`, return `None`.
2424
static llvm::Optional<DurationScale>
2525
getScaleForFactory(llvm::StringRef FactoryName) {
26-
static const std::unordered_map<std::string, DurationScale> ScaleMap(
27-
{{"Nanoseconds", DurationScale::Nanoseconds},
28-
{"Microseconds", DurationScale::Microseconds},
29-
{"Milliseconds", DurationScale::Milliseconds},
30-
{"Seconds", DurationScale::Seconds},
31-
{"Minutes", DurationScale::Minutes},
32-
{"Hours", DurationScale::Hours}});
33-
34-
auto ScaleIter = ScaleMap.find(std::string(FactoryName));
35-
if (ScaleIter == ScaleMap.end())
36-
return llvm::None;
37-
38-
return ScaleIter->second;
26+
return llvm::StringSwitch<llvm::Optional<DurationScale>>(FactoryName)
27+
.Case("Nanoseconds", DurationScale::Nanoseconds)
28+
.Case("Microseconds", DurationScale::Microseconds)
29+
.Case("Milliseconds", DurationScale::Milliseconds)
30+
.Case("Seconds", DurationScale::Seconds)
31+
.Case("Minutes", DurationScale::Minutes)
32+
.Case("Hours", DurationScale::Hours)
33+
.Default(llvm::None);
3934
}
4035

4136
// Given either an integer or float literal, return its value.

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
456456
// Don't suggest fixes for bitfields because in-class initialization is not
457457
// possible until C++2a.
458458
if (F->getType()->isEnumeralType() ||
459-
(!getLangOpts().CPlusPlus2a && F->isBitField()))
459+
(!getLangOpts().CPlusPlus20 && F->isBitField()))
460460
return;
461461
if (!F->getParent()->isUnion() || UnionsSeen.insert(F->getParent()).second)
462462
FieldsToFix.insert(F);

clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ static constexpr std::array<StringRef, 5> DeprecatedTypes = {
2121
"::std::ios_base::seek_dir", "::std::ios_base::streamoff",
2222
"::std::ios_base::streampos"};
2323

24-
static const llvm::StringMap<StringRef> ReplacementTypes = {
25-
{"io_state", "iostate"},
26-
{"open_mode", "openmode"},
27-
{"seek_dir", "seekdir"}};
24+
static llvm::Optional<const char *> getReplacementType(StringRef Type) {
25+
return llvm::StringSwitch<llvm::Optional<const char *>>(Type)
26+
.Case("io_state", "iostate")
27+
.Case("open_mode", "openmode")
28+
.Case("seek_dir", "seekdir")
29+
.Default(llvm::None);
30+
}
2831

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

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

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

4851
// Do not generate fixits for matches depending on template arguments and
4952
// macro expansions.
50-
bool Fix = HasReplacement && !TL->getType()->isDependentType();
53+
bool Fix = Replacement && !TL->getType()->isDependentType();
5154
if (IoStateLoc.isMacroID()) {
5255
IoStateLoc = SM.getSpellingLoc(IoStateLoc);
5356
Fix = false;
5457
}
5558

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

58-
if (HasReplacement) {
59-
auto FixName = ReplacementTypes.lookup(TypeName);
61+
if (Replacement) {
62+
auto FixName = *Replacement;
6063
auto Builder = diag(IoStateLoc, "'std::ios_base::%0' is deprecated; use "
6164
"'std::ios_base::%1' instead")
6265
<< TypeName << FixName;

clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,11 @@ void LoopConvertCheck::doConversion(
525525
const ValueDecl *MaybeContainer, const UsageResult &Usages,
526526
const DeclStmt *AliasDecl, bool AliasUseRequired, bool AliasFromForInit,
527527
const ForStmt *Loop, RangeDescriptor Descriptor) {
528-
auto Diag = diag(Loop->getForLoc(), "use range-based for loop instead");
529-
530528
std::string VarName;
531529
bool VarNameFromAlias = (Usages.size() == 1) && AliasDecl;
532530
bool AliasVarIsRef = false;
533531
bool CanCopy = true;
534-
532+
std::vector<FixItHint> FixIts;
535533
if (VarNameFromAlias) {
536534
const auto *AliasVar = cast<VarDecl>(AliasDecl->getSingleDecl());
537535
VarName = AliasVar->getName().str();
@@ -563,8 +561,8 @@ void LoopConvertCheck::doConversion(
563561
getAliasRange(Context->getSourceManager(), ReplaceRange);
564562
}
565563

566-
Diag << FixItHint::CreateReplacement(
567-
CharSourceRange::getTokenRange(ReplaceRange), ReplacementText);
564+
FixIts.push_back(FixItHint::CreateReplacement(
565+
CharSourceRange::getTokenRange(ReplaceRange), ReplacementText));
568566
// No further replacements are made to the loop, since the iterator or index
569567
// was used exactly once - in the initialization of AliasVar.
570568
} else {
@@ -609,8 +607,8 @@ void LoopConvertCheck::doConversion(
609607
Usage.Kind == Usage::UK_CaptureByCopy ? "&" + VarName : VarName;
610608
}
611609
TUInfo->getReplacedVars().insert(std::make_pair(Loop, IndexVar));
612-
Diag << FixItHint::CreateReplacement(
613-
CharSourceRange::getTokenRange(Range), ReplaceText);
610+
FixIts.push_back(FixItHint::CreateReplacement(
611+
CharSourceRange::getTokenRange(Range), ReplaceText));
614612
}
615613
}
616614

@@ -648,8 +646,9 @@ void LoopConvertCheck::doConversion(
648646
std::string Range = ("(" + TypeString + " " + VarName + " : " +
649647
MaybeDereference + Descriptor.ContainerString + ")")
650648
.str();
651-
Diag << FixItHint::CreateReplacement(
652-
CharSourceRange::getTokenRange(ParenRange), Range);
649+
FixIts.push_back(FixItHint::CreateReplacement(
650+
CharSourceRange::getTokenRange(ParenRange), Range));
651+
diag(Loop->getForLoc(), "use range-based for loop instead") << FixIts;
653652
TUInfo->getGeneratedDecls().insert(make_pair(Loop, VarName));
654653
}
655654

clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
217217
isDefaultConstructor(), unless(isInstantiated()),
218218
forEachConstructorInitializer(
219219
cxxCtorInitializer(
220-
forField(unless(anyOf(getLangOpts().CPlusPlus2a
220+
forField(unless(anyOf(getLangOpts().CPlusPlus20
221221
? unless(anything())
222222
: isBitField(),
223223
hasInClassInitializer(anything()),

clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
5858
printPolicy.SuppressScope = true;
5959
printPolicy.ConstantArraySizeAsWritten = true;
6060
printPolicy.UseVoidForZeroParams = false;
61+
printPolicy.PrintInjectedClassNameWithArguments = false;
6162

6263
std::string Type = MatchedDecl->getUnderlyingType().getAsString(printPolicy);
6364
std::string Name = MatchedDecl->getNameAsString();

clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp

+10-16
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,15 @@ static StringRef TrySuggestPPC(StringRef Name) {
4343
if (!Name.consume_front("vec_"))
4444
return {};
4545

46-
static const llvm::StringMap<StringRef> Mapping{
47-
// [simd.alg]
48-
{"max", "$std::max"},
49-
{"min", "$std::min"},
50-
51-
// [simd.binary]
52-
{"add", "operator+ on $simd objects"},
53-
{"sub", "operator- on $simd objects"},
54-
{"mul", "operator* on $simd objects"},
55-
};
56-
57-
auto It = Mapping.find(Name);
58-
if (It != Mapping.end())
59-
return It->second;
60-
return {};
46+
return llvm::StringSwitch<StringRef>(Name)
47+
// [simd.alg]
48+
.Case("max", "$std::max")
49+
.Case("min", "$std::min")
50+
// [simd.binary]
51+
.Case("add", "operator+ on $simd objects")
52+
.Case("sub", "operator- on $simd objects")
53+
.Case("mul", "operator* on $simd objects")
54+
.Default({});
6155
}
6256

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

10195
Finder->addMatcher(callExpr(callee(functionDecl(
10296
matchesName("^::(_mm_|_mm256_|_mm512_|vec_)"),

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ def make_absolute(f, directory):
7878

7979

8080
def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
81-
header_filter, extra_arg, extra_arg_before, quiet,
82-
config):
81+
header_filter, allow_enabling_alpha_checkers,
82+
extra_arg, extra_arg_before, quiet, config):
8383
"""Gets a command line for clang-tidy."""
8484
start = [clang_tidy_binary]
85+
if allow_enabling_alpha_checkers is not None:
86+
start.append('-allow-enabling-analyzer-alpha-checkers')
8587
if header_filter is not None:
8688
start.append('-header-filter=' + header_filter)
8789
if checks:
@@ -159,6 +161,7 @@ def run_tidy(args, tmpdir, build_path, queue, lock, failed_files):
159161
name = queue.get()
160162
invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks,
161163
tmpdir, build_path, args.header_filter,
164+
args.allow_enabling_alpha_checkers,
162165
args.extra_arg, args.extra_arg_before,
163166
args.quiet, args.config)
164167

@@ -179,6 +182,9 @@ def main():
179182
'in a compilation database. Requires '
180183
'clang-tidy and clang-apply-replacements in '
181184
'$PATH.')
185+
parser.add_argument('-allow-enabling-alpha-checkers',
186+
action='store_true', help='allow alpha checkers from '
187+
'clang-analyzer.')
182188
parser.add_argument('-clang-tidy-binary', metavar='PATH',
183189
default='clang-tidy',
184190
help='path to clang-tidy binary')
@@ -238,6 +244,8 @@ def main():
238244

239245
try:
240246
invocation = [args.clang_tidy_binary, '-list-checks']
247+
if args.allow_enabling_alpha_checkers:
248+
invocation.append('-allow-enabling-analyzer-alpha-checkers')
241249
invocation.append('-p=' + build_path)
242250
if args.checks:
243251
invocation.append('-checks=' + args.checks)

clang-tools-extra/clangd/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
140140
endif()
141141
add_subdirectory(tool)
142142
add_subdirectory(indexer)
143-
add_subdirectory(index/dex/dexp)
144143

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

161160
if (CLANGD_ENABLE_REMOTE)
162161
include(FindGRPC)
163-
add_subdirectory(index/remote)
164162
endif()
163+
add_subdirectory(index/remote)
164+
add_subdirectory(index/dex/dexp)

clang-tools-extra/clangd/ClangdServer.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,8 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos,
280280
Pos, FS, Index));
281281
};
282282

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

clang-tools-extra/clangd/CodeComplete.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ struct SemaCompleteInput {
10231023
PathRef FileName;
10241024
const tooling::CompileCommand &Command;
10251025
const PreambleData &Preamble;
1026+
const PreamblePatch &Patch;
10261027
llvm::StringRef Contents;
10271028
size_t Offset;
10281029
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
@@ -1060,7 +1061,6 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
10601061
ParseInput.CompileCommand = Input.Command;
10611062
ParseInput.FS = VFS;
10621063
ParseInput.Contents = std::string(Input.Contents);
1063-
ParseInput.Opts = ParseOptions();
10641064

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

17611764
SignatureHelp signatureHelp(PathRef FileName,
@@ -1775,10 +1778,15 @@ SignatureHelp signatureHelp(PathRef FileName,
17751778
Options.IncludeMacros = false;
17761779
Options.IncludeCodePatterns = false;
17771780
Options.IncludeBriefComments = false;
1778-
IncludeStructure PreambleInclusions; // Unused for signatureHelp
1781+
1782+
ParseInputs PI;
1783+
PI.CompileCommand = Command;
1784+
PI.Contents = Contents.str();
1785+
PI.FS = std::move(VFS);
1786+
auto PP = PreamblePatch::create(FileName, PI, Preamble);
17791787
semaCodeComplete(
17801788
std::make_unique<SignatureHelpCollector>(Options, Index, Result), Options,
1781-
{FileName, Command, Preamble, Contents, *Offset, std::move(VFS)});
1789+
{FileName, Command, Preamble, PP, Contents, *Offset, std::move(PI.FS)});
17821790
return Result;
17831791
}
17841792

clang-tools-extra/clangd/Compiler.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ buildCompilerInvocation(const ParseInputs &Inputs,
6565
CI->getFrontendOpts().DisableFree = false;
6666
CI->getLangOpts()->CommentOpts.ParseAllComments = true;
6767
CI->getLangOpts()->RetainCommentsFromSystemHeaders = true;
68+
69+
// Disable any dependency outputting, we don't want to generate files or write
70+
// to stdout/stderr.
71+
CI->getDependencyOutputOpts().ShowIncludesDest =
72+
ShowIncludesDestination::None;
73+
CI->getDependencyOutputOpts().OutputFile.clear();
74+
CI->getDependencyOutputOpts().HeaderIncludeOutputFile.clear();
75+
CI->getDependencyOutputOpts().DOTOutputFile.clear();
76+
CI->getDependencyOutputOpts().ModuleDependencyOutputDir.clear();
6877
return CI;
6978
}
7079

clang-tools-extra/clangd/Diagnostics.cpp

+18-5
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,23 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
556556
if (!InsideMainFile)
557557
return false;
558558

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

571584
llvm::SmallString<64> Message;
572585
// If requested and possible, create a message like "change 'foo' to 'bar'".
573-
if (SyntheticMessage && Info.getNumFixItHints() == 1) {
574-
const auto &FixIt = Info.getFixItHint(0);
586+
if (SyntheticMessage && FixIts.size() == 1) {
587+
const auto &FixIt = FixIts.front();
575588
bool Invalid = false;
576589
llvm::StringRef Remove =
577590
Lexer::getSourceText(FixIt.RemoveRange, SM, *LangOpts, &Invalid);
+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
2+
#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMOTE@

clang-tools-extra/clangd/FindTarget.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -860,15 +860,17 @@ class ExplicitReferenceCollector
860860
// TemplateArgumentLoc is the only way to get locations for references to
861861
// template template parameters.
862862
bool TraverseTemplateArgumentLoc(TemplateArgumentLoc A) {
863+
llvm::SmallVector<const NamedDecl *, 1> Targets;
863864
switch (A.getArgument().getKind()) {
864865
case TemplateArgument::Template:
865866
case TemplateArgument::TemplateExpansion:
867+
if (const auto *D = A.getArgument()
868+
.getAsTemplateOrTemplatePattern()
869+
.getAsTemplateDecl())
870+
Targets.push_back(D);
866871
reportReference(ReferenceLoc{A.getTemplateQualifierLoc(),
867872
A.getTemplateNameLoc(),
868-
/*IsDecl=*/false,
869-
{A.getArgument()
870-
.getAsTemplateOrTemplatePattern()
871-
.getAsTemplateDecl()}},
873+
/*IsDecl=*/false, Targets},
872874
DynTypedNode::create(A.getArgument()));
873875
break;
874876
case TemplateArgument::Declaration:

0 commit comments

Comments
 (0)