Skip to content

Commit 0d1183e

Browse files
vmaksimoaelovikov-intel
authored andcommitted
Merge from 'master' to 'sycl-web' (#242)
CONFLICT (modify/delete): clang/test/CodeGenSYCL/unique-stable-name.cpp deleted in cec49a5 and modified in HEAD. Version HEAD of clang/test/CodeGenSYCL/unique-stable-name.cpp left in tree.
2 parents 0f62ae0 + cec49a5 commit 0d1183e

File tree

814 files changed

+290395
-282248
lines changed

Some content is hidden

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

814 files changed

+290395
-282248
lines changed

clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,9 @@ void FunctionCognitiveComplexityCheck::storeOptions(
501501

502502
void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
503503
Finder->addMatcher(
504-
functionDecl(
505-
allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(),
506-
isImplicit(), isInstantiated()))))
504+
functionDecl(isDefinition(),
505+
unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
506+
isInstantiated(), isWeak())))
507507
.bind("func"),
508508
this);
509509
}

clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ IncludeSorter &IncludeInserter::getOrCreate(FileID FileID) {
6767
}
6868

6969
llvm::Optional<FixItHint>
70-
IncludeInserter::createIncludeInsertion(FileID FileID, StringRef Header,
71-
bool IsAngled) {
70+
IncludeInserter::createIncludeInsertion(FileID FileID, llvm::StringRef Header) {
71+
bool IsAngled = Header.consume_front("<");
72+
if (IsAngled != Header.consume_back(">"))
73+
return llvm::None;
7274
// We assume the same Header will never be included both angled and not
7375
// angled.
7476
if (!InsertedHeaders[FileID].insert(Header).second)
@@ -77,22 +79,6 @@ IncludeInserter::createIncludeInsertion(FileID FileID, StringRef Header,
7779
return getOrCreate(FileID).CreateIncludeInsertion(Header, IsAngled);
7880
}
7981

80-
llvm::Optional<FixItHint>
81-
IncludeInserter::createIncludeInsertion(FileID FileID, llvm::StringRef Header) {
82-
bool IsAngled = Header.consume_front("<");
83-
if (IsAngled != Header.consume_back(">"))
84-
return llvm::None;
85-
return createIncludeInsertion(FileID, Header, IsAngled);
86-
}
87-
88-
llvm::Optional<FixItHint>
89-
IncludeInserter::createMainFileIncludeInsertion(StringRef Header,
90-
bool IsAngled) {
91-
assert(SourceMgr && "SourceMgr shouldn't be null; did you remember to call "
92-
"registerPreprocessor()?");
93-
return createIncludeInsertion(SourceMgr->getMainFileID(), Header, IsAngled);
94-
}
95-
9682
llvm::Optional<FixItHint>
9783
IncludeInserter::createMainFileIncludeInsertion(StringRef Header) {
9884
assert(SourceMgr && "SourceMgr shouldn't be null; did you remember to call "

clang-tools-extra/clang-tidy/utils/IncludeInserter.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,6 @@ class IncludeInserter {
6666
/// class is used.
6767
void registerPreprocessor(Preprocessor *PP);
6868

69-
/// Creates a \p Header inclusion directive fixit in the File \p FileID.
70-
/// Returns ``llvm::None`` on error or if the inclusion directive already
71-
/// exists.
72-
/// FIXME: This should be removed once the clients are migrated to the
73-
/// overload without the ``IsAngled`` parameter.
74-
llvm::Optional<FixItHint>
75-
createIncludeInsertion(FileID FileID, llvm::StringRef Header, bool IsAngled);
76-
7769
/// Creates a \p Header inclusion directive fixit in the File \p FileID.
7870
/// When \p Header is enclosed in angle brackets, uses angle brackets in the
7971
/// inclusion directive, otherwise uses quotes.
@@ -82,18 +74,10 @@ class IncludeInserter {
8274
llvm::Optional<FixItHint> createIncludeInsertion(FileID FileID,
8375
llvm::StringRef Header);
8476

85-
/// Creates a \p Header inclusion directive fixit in the main file.
86-
/// Returns``llvm::None`` on error or if the inclusion directive already
87-
/// exists.
88-
/// FIXME: This should be removed once the clients are migrated to the
89-
/// overload without the ``IsAngled`` parameter.
90-
llvm::Optional<FixItHint>
91-
createMainFileIncludeInsertion(llvm::StringRef Header, bool IsAngled);
92-
9377
/// Creates a \p Header inclusion directive fixit in the main file.
9478
/// When \p Header is enclosed in angle brackets, uses angle brackets in the
9579
/// inclusion directive, otherwise uses quotes.
96-
/// Returns``llvm::None`` on error or if the inclusion directive already
80+
/// Returns ``llvm::None`` on error or if the inclusion directive already
9781
/// exists.
9882
llvm::Optional<FixItHint>
9983
createMainFileIncludeInsertion(llvm::StringRef Header);

clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,10 @@ void TransformerClangTidyCheck::check(
9595
case transformer::EditKind::Range:
9696
Diag << FixItHint::CreateReplacement(T.Range, T.Replacement);
9797
break;
98-
case transformer::EditKind::AddInclude: {
99-
StringRef FileName = T.Replacement;
100-
bool IsAngled = FileName.startswith("<") && FileName.endswith(">");
101-
Diag << Inserter.createMainFileIncludeInsertion(
102-
IsAngled ? FileName.substr(1, FileName.size() - 2) : FileName,
103-
IsAngled);
98+
case transformer::EditKind::AddInclude:
99+
Diag << Inserter.createMainFileIncludeInsertion(T.Replacement);
104100
break;
105101
}
106-
}
107102
}
108103

109104
void TransformerClangTidyCheck::storeOptions(

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,15 @@ void ClangdLSPServer::onCodeAction(const CodeActionParams &Params,
10301030
return Reply(llvm::json::Array(Commands));
10311031
};
10321032

1033-
Server->enumerateTweaks(File.file(), Params.range, std::move(ConsumeActions));
1033+
Server->enumerateTweaks(
1034+
File.file(), Params.range,
1035+
[&](const Tweak &T) {
1036+
if (!Opts.TweakFilter(T))
1037+
return false;
1038+
// FIXME: also consider CodeActionContext.only
1039+
return true;
1040+
},
1041+
std::move(ConsumeActions));
10341042
}
10351043

10361044
void ClangdLSPServer::onCompletion(const CompletionParams &Params,

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
5050
/// per-request, but LSP allows limited/no customizations.
5151
clangd::CodeCompleteOptions CodeComplete;
5252
clangd::RenameOptions Rename;
53+
/// Returns true if the tweak should be enabled.
54+
std::function<bool(const Tweak &)> TweakFilter = [](const Tweak &T) {
55+
return !T.hidden(); // only enable non-hidden tweaks.
56+
};
5357
};
5458

5559
ClangdLSPServer(Transport &Transp, const ThreadsafeFS &TFS,

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
180180
SuggestMissingIncludes(Opts.SuggestMissingIncludes),
181181
BuildRecoveryAST(Opts.BuildRecoveryAST),
182182
PreserveRecoveryASTType(Opts.PreserveRecoveryASTType),
183-
TweakFilter(Opts.TweakFilter), WorkspaceRoot(Opts.WorkspaceRoot),
183+
WorkspaceRoot(Opts.WorkspaceRoot),
184184
// Pass a callback into `WorkScheduler` to extract symbols from a newly
185185
// parsed file and rebuild the file index synchronously each time an AST
186186
// is parsed.
@@ -492,13 +492,15 @@ tweakSelection(const Range &Sel, const InputsAndAST &AST) {
492492
return std::move(Result);
493493
}
494494

495-
void ClangdServer::enumerateTweaks(PathRef File, Range Sel,
496-
Callback<std::vector<TweakRef>> CB) {
495+
void ClangdServer::enumerateTweaks(
496+
PathRef File, Range Sel, llvm::unique_function<bool(const Tweak &)> Filter,
497+
Callback<std::vector<TweakRef>> CB) {
497498
// Tracks number of times a tweak has been offered.
498499
static constexpr trace::Metric TweakAvailable(
499500
"tweak_available", trace::Metric::Counter, "tweak_id");
500501
auto Action = [File = File.str(), Sel, CB = std::move(CB),
501-
this](Expected<InputsAndAST> InpAST) mutable {
502+
Filter =
503+
std::move(Filter)](Expected<InputsAndAST> InpAST) mutable {
502504
if (!InpAST)
503505
return CB(InpAST.takeError());
504506
auto Selections = tweakSelection(Sel, *InpAST);
@@ -507,11 +509,11 @@ void ClangdServer::enumerateTweaks(PathRef File, Range Sel,
507509
std::vector<TweakRef> Res;
508510
// Don't allow a tweak to fire more than once across ambiguous selections.
509511
llvm::DenseSet<llvm::StringRef> PreparedTweaks;
510-
auto Filter = [&](const Tweak &T) {
511-
return TweakFilter(T) && !PreparedTweaks.count(T.id());
512+
auto DeduplicatingFilter = [&](const Tweak &T) {
513+
return Filter(T) && !PreparedTweaks.count(T.id());
512514
};
513515
for (const auto &Sel : *Selections) {
514-
for (auto &T : prepareTweaks(*Sel, Filter)) {
516+
for (auto &T : prepareTweaks(*Sel, DeduplicatingFilter)) {
515517
Res.push_back({T->id(), T->title(), T->kind()});
516518
PreparedTweaks.insert(T->id());
517519
TweakAvailable.record(1, T->id());

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ class ClangdServer {
163163
/// Enable preview of FoldingRanges feature.
164164
bool FoldingRanges = false;
165165

166-
/// Returns true if the tweak should be enabled.
167-
std::function<bool(const Tweak &)> TweakFilter = [](const Tweak &T) {
168-
return !T.hidden(); // only enable non-hidden tweaks.
169-
};
170-
171166
explicit operator TUScheduler::Options() const;
172167
};
173168
// Sensible default options for use in tests.
@@ -294,7 +289,9 @@ class ClangdServer {
294289
llvm::StringLiteral Kind;
295290
};
296291
/// Enumerate the code tweaks available to the user at a specified point.
292+
/// Tweaks where Filter returns false will not be checked or included.
297293
void enumerateTweaks(PathRef File, Range Sel,
294+
llvm::unique_function<bool(const Tweak &)> Filter,
298295
Callback<std::vector<TweakRef>> CB);
299296

300297
/// Apply the code tweak with a specified \p ID.
@@ -382,8 +379,6 @@ class ClangdServer {
382379
// If true, preserve the type for recovery AST.
383380
bool PreserveRecoveryASTType = false;
384381

385-
std::function<bool(const Tweak &)> TweakFilter;
386-
387382
// GUARDED_BY(CachedCompletionFuzzyFindRequestMutex)
388383
llvm::StringMap<llvm::Optional<FuzzyFindRequest>>
389384
CachedCompletionFuzzyFindRequestByFile;

clang-tools-extra/clangd/FindSymbols.cpp

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
#include "clang/Index/IndexDataConsumer.h"
1919
#include "clang/Index/IndexSymbol.h"
2020
#include "clang/Index/IndexingAction.h"
21+
#include "llvm/ADT/ArrayRef.h"
22+
#include "llvm/ADT/STLExtras.h"
23+
#include "llvm/ADT/SmallVector.h"
2124
#include "llvm/ADT/StringRef.h"
2225
#include "llvm/Support/FormatVariadic.h"
2326
#include "llvm/Support/Path.h"
2427
#include "llvm/Support/ScopedPrinter.h"
28+
#include <tuple>
2529

2630
#define DEBUG_TYPE "FindSymbols"
2731

@@ -38,6 +42,21 @@ struct ScoredSymbolGreater {
3842
}
3943
};
4044

45+
// Returns true if \p Query can be found as a sub-sequence inside \p Scope.
46+
bool approximateScopeMatch(llvm::StringRef Scope, llvm::StringRef Query) {
47+
assert(Scope.empty() || Scope.endswith("::"));
48+
assert(Query.empty() || Query.endswith("::"));
49+
while (!Scope.empty() && !Query.empty()) {
50+
auto Colons = Scope.find("::");
51+
assert(Colons != llvm::StringRef::npos);
52+
53+
llvm::StringRef LeadingSpecifier = Scope.slice(0, Colons + 2);
54+
Scope = Scope.slice(Colons + 2, llvm::StringRef::npos);
55+
Query.consume_front(LeadingSpecifier);
56+
}
57+
return Query.empty();
58+
}
59+
4160
} // namespace
4261

4362
llvm::Expected<Location> indexToLSPLocation(const SymbolLocation &Loc,
@@ -71,44 +90,54 @@ getWorkspaceSymbols(llvm::StringRef Query, int Limit,
7190
if (Query.empty() || !Index)
7291
return Result;
7392

93+
// Lookup for qualified names are performed as:
94+
// - Exact namespaces are boosted by the index.
95+
// - Approximate matches are (sub-scope match) included via AnyScope logic.
96+
// - Non-matching namespaces (no sub-scope match) are post-filtered.
7497
auto Names = splitQualifiedName(Query);
7598

7699
FuzzyFindRequest Req;
77100
Req.Query = std::string(Names.second);
78101

79-
// FuzzyFind doesn't want leading :: qualifier
80-
bool IsGlobalQuery = Names.first.consume_front("::");
81-
// Restrict results to the scope in the query string if present (global or
82-
// not).
83-
if (IsGlobalQuery || !Names.first.empty())
102+
// FuzzyFind doesn't want leading :: qualifier.
103+
auto HasLeadingColons = Names.first.consume_front("::");
104+
// Limit the query to specific namespace if it is fully-qualified.
105+
Req.AnyScope = !HasLeadingColons;
106+
// Boost symbols from desired namespace.
107+
if (HasLeadingColons || !Names.first.empty())
84108
Req.Scopes = {std::string(Names.first)};
85-
else
86-
Req.AnyScope = true;
87-
if (Limit)
109+
if (Limit) {
88110
Req.Limit = Limit;
111+
// If we are boosting a specific scope allow more results to be retrieved,
112+
// since some symbols from preferred namespaces might not make the cut.
113+
if (Req.AnyScope && !Req.Scopes.empty())
114+
*Req.Limit *= 5;
115+
}
89116
TopN<ScoredSymbolInfo, ScoredSymbolGreater> Top(
90117
Req.Limit ? *Req.Limit : std::numeric_limits<size_t>::max());
91118
FuzzyMatcher Filter(Req.Query);
92-
Index->fuzzyFind(Req, [HintPath, &Top, &Filter](const Symbol &Sym) {
119+
120+
Index->fuzzyFind(Req, [HintPath, &Top, &Filter, AnyScope = Req.AnyScope,
121+
ReqScope = Names.first](const Symbol &Sym) {
122+
llvm::StringRef Scope = Sym.Scope;
123+
// Fuzzyfind might return symbols from irrelevant namespaces if query was
124+
// not fully-qualified, drop those.
125+
if (AnyScope && !approximateScopeMatch(Scope, ReqScope))
126+
return;
127+
93128
auto Loc = symbolToLocation(Sym, HintPath);
94129
if (!Loc) {
95130
log("Workspace symbols: {0}", Loc.takeError());
96131
return;
97132
}
98133

99-
llvm::StringRef Scope = Sym.Scope;
100-
Scope.consume_back("::");
101-
SymbolInformation Info;
102-
Info.name = (Sym.Name + Sym.TemplateSpecializationArgs).str();
103-
Info.kind = indexSymbolKindToSymbolKind(Sym.SymInfo.Kind);
104-
Info.location = *Loc;
105-
Info.containerName = Scope.str();
106-
107134
SymbolQualitySignals Quality;
108135
Quality.merge(Sym);
109136
SymbolRelevanceSignals Relevance;
110137
Relevance.Name = Sym.Name;
111138
Relevance.Query = SymbolRelevanceSignals::Generic;
139+
// If symbol and request scopes do not match exactly, apply a penalty.
140+
Relevance.InBaseClass = AnyScope && Scope != ReqScope;
112141
if (auto NameMatch = Filter.match(Sym.Name))
113142
Relevance.NameMatch = *NameMatch;
114143
else {
@@ -122,6 +151,13 @@ getWorkspaceSymbols(llvm::StringRef Query, int Limit,
122151
dlog("FindSymbols: {0}{1} = {2}\n{3}{4}\n", Sym.Scope, Sym.Name, Score,
123152
Quality, Relevance);
124153

154+
SymbolInformation Info;
155+
Info.name = (Sym.Name + Sym.TemplateSpecializationArgs).str();
156+
Info.kind = indexSymbolKindToSymbolKind(Sym.SymInfo.Kind);
157+
Info.location = *Loc;
158+
Scope.consume_back("::");
159+
Info.containerName = Scope.str();
160+
125161
// Exposed score excludes fuzzy-match component, for client-side re-ranking.
126162
Info.score = Score / Relevance.NameMatch;
127163
Top.push({Score, std::move(Info)});

clang-tools-extra/clangd/IncludeFixer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
7272
case diag::err_incomplete_base_class:
7373
case diag::err_incomplete_member_access:
7474
case diag::err_incomplete_type:
75+
case diag::err_typecheck_decl_incomplete_type:
76+
case diag::err_typecheck_incomplete_tag:
77+
case diag::err_invalid_incomplete_type_use:
78+
case diag::err_sizeof_alignof_incomplete_or_sizeless_type:
79+
case diag::err_for_range_incomplete_type:
80+
case diag::err_func_def_incomplete_result:
7581
// Incomplete type diagnostics should have a QualType argument for the
7682
// incomplete type.
7783
for (unsigned Idx = 0; Idx < Info.getNumArgs(); ++Idx) {

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,15 +851,15 @@ static llvm::StringRef toTextKind(MarkupKind Kind) {
851851
bool fromJSON(const llvm::json::Value &V, MarkupKind &K, llvm::json::Path P) {
852852
auto Str = V.getAsString();
853853
if (!Str) {
854-
elog("Failed to parse markup kind: expected a string");
854+
P.report("expected string");
855855
return false;
856856
}
857857
if (*Str == "plaintext")
858858
K = MarkupKind::PlainText;
859859
else if (*Str == "markdown")
860860
K = MarkupKind::Markdown;
861861
else {
862-
elog("Unknown markup kind: {0}", *Str);
862+
P.report("unknown markup kind");
863863
return false;
864864
}
865865
return true;

clang-tools-extra/clangd/index/CanonicalIncludes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ void CanonicalIncludes::addSystemHeadersMapping(const LangOptions &Language) {
420420
{"bits/signum.h", "<csignal>"},
421421
{"bits/sigset.h", "<csignal>"},
422422
{"bits/sigstack.h", "<csignal>"},
423+
{"bits/stdint-intn.h", "<cstdint>"},
424+
{"bits/stdint-uintn.h", "<cstdint>"},
423425
{"bits/stdio_lim.h", "<cstdio>"},
424426
{"bits/sys_errlist.h", "<cstdio>"},
425427
{"bits/time.h", "<ctime>"},

0 commit comments

Comments
 (0)