Skip to content

Commit 4fed824

Browse files
authored
LLVM and SPIRV-LLVM-Translator pulldown (WW06)
LLVM: llvm/llvm-project@6663330 SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@bd39160 Pull down was reapplied as merge commit.
2 parents baa6493 + 87e9823 commit 4fed824

File tree

1,867 files changed

+852298
-29963
lines changed

Some content is hidden

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

1,867 files changed

+852298
-29963
lines changed

clang-tools-extra/clang-query/Query.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
156156
if (QS.DetailedASTOutput) {
157157
OS << "Binding for \"" << BI->first << "\":\n";
158158
const ASTContext &Ctx = AST->getASTContext();
159-
const SourceManager &SM = Ctx.getSourceManager();
160-
ASTDumper Dumper(OS, Ctx, SM.getDiagnostics().getShowColors());
159+
ASTDumper Dumper(OS, Ctx, AST->getDiagnostics().getShowColors());
161160
Dumper.SetTraversalKind(QS.TK);
162161
Dumper.Visit(BI->second);
163162
OS << "\n";

clang-tools-extra/clang-query/tool/ClangQuery.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ using namespace llvm;
4949
static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
5050
static cl::OptionCategory ClangQueryCategory("clang-query options");
5151

52+
static cl::opt<bool>
53+
UseColor("use-color",
54+
cl::desc(
55+
R"(Use colors in detailed AST output. If not set, colors
56+
will be used if the terminal connected to
57+
standard output supports colors.)"),
58+
cl::init(false), cl::cat(ClangQueryCategory));
59+
5260
static cl::list<std::string> Commands("c", cl::desc("Specify command to run"),
5361
cl::value_desc("command"),
5462
cl::cat(ClangQueryCategory));
@@ -109,6 +117,19 @@ int main(int argc, const char **argv) {
109117

110118
ClangTool Tool(OptionsParser->getCompilations(),
111119
OptionsParser->getSourcePathList());
120+
121+
if (UseColor.getNumOccurrences() > 0) {
122+
ArgumentsAdjuster colorAdjustor = [](const CommandLineArguments &Args, StringRef /*unused*/) {
123+
CommandLineArguments AdjustedArgs = Args;
124+
if (UseColor)
125+
AdjustedArgs.push_back("-fdiagnostics-color");
126+
else
127+
AdjustedArgs.push_back("-fno-diagnostics-color");
128+
return AdjustedArgs;
129+
};
130+
Tool.appendArgumentsAdjuster(colorAdjustor);
131+
}
132+
112133
std::vector<std::unique_ptr<ASTUnit>> ASTs;
113134
int ASTStatus = 0;
114135
switch (Tool.buildASTs(ASTs)) {

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
258258
};
259259
}
260260

261+
template <typename Result>
262+
void bind(const char *Method,
263+
void (ClangdLSPServer::*Handler)(Callback<Result>)) {
264+
Calls[Method] = [Handler, this](llvm::json::Value RawParams,
265+
ReplyOnce Reply) {
266+
(Server.*Handler)(std::move(Reply));
267+
};
268+
}
269+
261270
// Bind a reply callback to a request. The callback will be invoked when
262271
// clangd receives the reply from the LSP client.
263272
// Return a call id of the request.
@@ -301,6 +310,12 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
301310
};
302311
}
303312

313+
void bind(const char *Method, void (ClangdLSPServer::*Handler)()) {
314+
Notifications[Method] = [Handler, this](llvm::json::Value RawParams) {
315+
(Server.*Handler)();
316+
};
317+
}
318+
304319
private:
305320
// Function object to reply to an LSP call.
306321
// Each instance must be called exactly once, otherwise:
@@ -443,6 +458,14 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
443458
};
444459
constexpr int ClangdLSPServer::MessageHandler::MaxReplayCallbacks;
445460

461+
template <>
462+
void ClangdLSPServer::MessageHandler::bind<NoParams>(
463+
const char *Method, void (ClangdLSPServer::*Handler)(const NoParams &)) {
464+
Notifications[Method] = [Handler, this](llvm::json::Value RawParams) {
465+
(Server.*Handler)(NoParams{});
466+
};
467+
}
468+
446469
// call(), notify(), and reply() wrap the Transport, adding logging and locking.
447470
void ClangdLSPServer::callRaw(StringRef Method, llvm::json::Value Params,
448471
Callback<llvm::json::Value> CB) {
@@ -487,6 +510,11 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
487510
"semanticTokens request, choosing the latter (no notifications).");
488511
Opts.TheiaSemanticHighlighting = false;
489512
}
513+
if (Opts.TheiaSemanticHighlighting) {
514+
log("Using legacy semanticHighlights notification, which will be removed "
515+
"in clangd 13. Clients should use the standard semanticTokens "
516+
"request instead.");
517+
}
490518

491519
if (Params.rootUri && *Params.rootUri)
492520
Opts.WorkspaceRoot = std::string(Params.rootUri->file());
@@ -500,6 +528,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
500528
if (Opts.UseDirBasedCDB) {
501529
DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
502530
CDBOpts.CompileCommandsDir = Opts.CompileCommandsDir;
531+
CDBOpts.ContextProvider = Opts.ContextProvider;
503532
BaseCDB =
504533
std::make_unique<DirectoryBasedGlobalCompilationDatabase>(CDBOpts);
505534
BaseCDB = getQueryDriverDatabase(llvm::makeArrayRef(Opts.QueryDriverGlobs),
@@ -647,17 +676,15 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
647676

648677
void ClangdLSPServer::onInitialized(const InitializedParams &Params) {}
649678

650-
void ClangdLSPServer::onShutdown(const ShutdownParams &Params,
651-
Callback<std::nullptr_t> Reply) {
679+
void ClangdLSPServer::onShutdown(Callback<std::nullptr_t> Reply) {
652680
// Do essentially nothing, just say we're ready to exit.
653681
ShutdownRequestReceived = true;
654682
Reply(nullptr);
655683
}
656684

657685
// sync is a clangd extension: it blocks until all background work completes.
658686
// It blocks the calling thread, so no messages are processed until it returns!
659-
void ClangdLSPServer::onSync(const NoParams &Params,
660-
Callback<std::nullptr_t> Reply) {
687+
void ClangdLSPServer::onSync(Callback<std::nullptr_t> Reply) {
661688
if (Server->blockUntilIdleForTest(/*TimeoutSeconds=*/60))
662689
Reply(nullptr);
663690
else
@@ -1445,8 +1472,7 @@ void ClangdLSPServer::onSemanticTokensDelta(
14451472
});
14461473
}
14471474

1448-
void ClangdLSPServer::onMemoryUsage(const NoParams &,
1449-
Callback<MemoryTree> Reply) {
1475+
void ClangdLSPServer::onMemoryUsage(Callback<MemoryTree> Reply) {
14501476
llvm::BumpPtrAllocator DetailAlloc;
14511477
MemoryTree MT(&DetailAlloc);
14521478
profile(MT);

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
9393
// Calls have signature void(const Params&, Callback<Response>).
9494
void onInitialize(const InitializeParams &, Callback<llvm::json::Value>);
9595
void onInitialized(const InitializedParams &);
96-
void onShutdown(const ShutdownParams &, Callback<std::nullptr_t>);
97-
void onSync(const NoParams &, Callback<std::nullptr_t>);
96+
void onShutdown(Callback<std::nullptr_t>);
97+
void onSync(Callback<std::nullptr_t>);
9898
void onDocumentDidOpen(const DidOpenTextDocumentParams &);
9999
void onDocumentDidChange(const DidChangeTextDocumentParams &);
100100
void onDocumentDidClose(const DidCloseTextDocumentParams &);
@@ -161,7 +161,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
161161
Callback<SemanticTokensOrDelta>);
162162
/// This is a clangd extension. Provides a json tree representing memory usage
163163
/// hierarchy.
164-
void onMemoryUsage(const NoParams &, Callback<MemoryTree>);
164+
void onMemoryUsage(Callback<MemoryTree>);
165165

166166
std::vector<Fix> getFixes(StringRef File, const clangd::Diagnostic &D);
167167

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ void ClangdServer::formatOnType(PathRef File, llvm::StringRef Code,
407407
Result.push_back(replacementToEdit(Code, R));
408408
return CB(Result);
409409
};
410-
WorkScheduler.run("FormatOnType", File, std::move(Action));
410+
WorkScheduler.runQuick("FormatOnType", File, std::move(Action));
411411
}
412412

413413
void ClangdServer::prepareRename(PathRef File, Position Pos,
@@ -635,7 +635,7 @@ void ClangdServer::formatCode(PathRef File, llvm::StringRef Code,
635635
tooling::calculateRangesAfterReplacements(IncludeReplaces, Ranges),
636636
File)));
637637
};
638-
WorkScheduler.run("Format", File, std::move(Action));
638+
WorkScheduler.runQuick("Format", File, std::move(Action));
639639
}
640640

641641
void ClangdServer::findDocumentHighlights(

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,9 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
11231123
// skip all includes in this case; these completions are really simple.
11241124
PreambleBounds PreambleRegion =
11251125
ComputePreambleBounds(*CI->getLangOpts(), *ContentsBuffer, 0);
1126-
bool CompletingInPreamble = PreambleRegion.Size > Input.Offset;
1126+
bool CompletingInPreamble = Input.Offset < PreambleRegion.Size ||
1127+
(!PreambleRegion.PreambleEndsAtStartOfLine &&
1128+
Input.Offset == PreambleRegion.Size);
11271129
if (Input.Patch)
11281130
Input.Patch->apply(*CI);
11291131
// NOTE: we must call BeginSourceFile after prepareCompilerInstance. Otherwise

clang-tools-extra/clangd/Config.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "llvm/ADT/FunctionExtras.h"
2929
#include "llvm/ADT/Optional.h"
3030
#include "llvm/ADT/StringMap.h"
31+
#include "llvm/ADT/StringSet.h"
3132
#include <string>
3233
#include <vector>
3334

@@ -51,11 +52,19 @@ struct Config {
5152
Config(Config &&) = default;
5253
Config &operator=(Config &&) = default;
5354

55+
struct CDBSearchSpec {
56+
enum { Ancestors, FixedDir, NoCDBSearch } Policy = Ancestors;
57+
// Absolute, native slashes, no trailing slash.
58+
llvm::Optional<std::string> FixedCDBPath;
59+
};
60+
5461
/// Controls how the compile command for the current file is determined.
5562
struct {
56-
// Edits to apply to the compile command, in sequence.
63+
/// Edits to apply to the compile command, in sequence.
5764
std::vector<llvm::unique_function<void(std::vector<std::string> &) const>>
5865
Edits;
66+
/// Where to search for compilation databases for this file's flags.
67+
CDBSearchSpec CDBSearch = {CDBSearchSpec::Ancestors, llvm::None};
5968
} CompileFlags;
6069

6170
enum class BackgroundPolicy { Build, Skip };
@@ -77,21 +86,26 @@ struct Config {
7786
llvm::Optional<ExternalIndexSpec> External;
7887
} Index;
7988

89+
/// Controls warnings and errors when parsing code.
90+
struct {
91+
bool SuppressAll = false;
92+
llvm::StringSet<> Suppress;
93+
94+
/// Configures what clang-tidy checks to run and options to use with them.
95+
struct {
96+
// A comma-seperated list of globs specify which clang-tidy checks to run.
97+
std::string Checks;
98+
llvm::StringMap<std::string> CheckOptions;
99+
} ClangTidy;
100+
} Diagnostics;
101+
80102
/// Style of the codebase.
81103
struct {
82104
// Namespaces that should always be fully qualified, meaning no "using"
83105
// declarations, always spell out the whole name (with or without leading
84106
// ::). All nested namespaces are affected as well.
85107
std::vector<std::string> FullyQualifiedNamespaces;
86108
} Style;
87-
88-
/// Configures what clang-tidy checks to run and options to use with them.
89-
struct {
90-
// A comma-seperated list of globs to specify which clang-tidy checks to
91-
// run.
92-
std::string Checks;
93-
llvm::StringMap<std::string> CheckOptions;
94-
} ClangTidy;
95109
};
96110

97111
} // namespace clangd

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "Config.h"
2828
#include "ConfigFragment.h"
2929
#include "ConfigProvider.h"
30+
#include "Diagnostics.h"
3031
#include "Features.inc"
3132
#include "TidyProvider.h"
3233
#include "support/Logger.h"
@@ -187,7 +188,7 @@ struct FragmentCompiler {
187188
compile(std::move(F.If));
188189
compile(std::move(F.CompileFlags));
189190
compile(std::move(F.Index));
190-
compile(std::move(F.ClangTidy));
191+
compile(std::move(F.Diagnostics));
191192
}
192193

193194
void compile(Fragment::IfBlock &&F) {
@@ -261,6 +262,36 @@ struct FragmentCompiler {
261262
});
262263
});
263264
}
265+
266+
if (F.CompilationDatabase) {
267+
llvm::Optional<Config::CDBSearchSpec> Spec;
268+
if (**F.CompilationDatabase == "Ancestors") {
269+
Spec.emplace();
270+
Spec->Policy = Config::CDBSearchSpec::Ancestors;
271+
} else if (**F.CompilationDatabase == "None") {
272+
Spec.emplace();
273+
Spec->Policy = Config::CDBSearchSpec::NoCDBSearch;
274+
} else {
275+
if (auto Path =
276+
makeAbsolute(*F.CompilationDatabase, "CompilationDatabase",
277+
llvm::sys::path::Style::native)) {
278+
// Drop trailing slash to put the path in canonical form.
279+
// Should makeAbsolute do this?
280+
llvm::StringRef Rel = llvm::sys::path::relative_path(*Path);
281+
if (!Rel.empty() && llvm::sys::path::is_separator(Rel.back()))
282+
Path->pop_back();
283+
284+
Spec.emplace();
285+
Spec->Policy = Config::CDBSearchSpec::FixedDir;
286+
Spec->FixedCDBPath = std::move(Path);
287+
}
288+
}
289+
if (Spec)
290+
Out.Apply.push_back(
291+
[Spec(std::move(*Spec))](const Params &, Config &C) {
292+
C.CompileFlags.CDBSearch = Spec;
293+
});
294+
}
264295
}
265296

266297
void compile(Fragment::IndexBlock &&F) {
@@ -328,6 +359,29 @@ struct FragmentCompiler {
328359
});
329360
}
330361

362+
void compile(Fragment::DiagnosticsBlock &&F) {
363+
std::vector<llvm::StringRef> Normalized;
364+
for (const auto &Suppressed : F.Suppress) {
365+
if (*Suppressed == "*") {
366+
Out.Apply.push_back([&](const Params &, Config &C) {
367+
C.Diagnostics.SuppressAll = true;
368+
C.Diagnostics.Suppress.clear();
369+
});
370+
return;
371+
}
372+
Normalized.push_back(normalizeSuppressedCode(*Suppressed));
373+
}
374+
if (!Normalized.empty())
375+
Out.Apply.push_back([Normalized](const Params &, Config &C) {
376+
if (C.Diagnostics.SuppressAll)
377+
return;
378+
for (llvm::StringRef N : Normalized)
379+
C.Diagnostics.Suppress.insert(N);
380+
});
381+
382+
compile(std::move(F.ClangTidy));
383+
}
384+
331385
void compile(Fragment::StyleBlock &&F) {
332386
if (!F.FullyQualifiedNamespaces.empty()) {
333387
std::vector<std::string> FullyQualifiedNamespaces;
@@ -369,7 +423,7 @@ struct FragmentCompiler {
369423
CurSpec += Str;
370424
}
371425

372-
void compile(Fragment::ClangTidyBlock &&F) {
426+
void compile(Fragment::DiagnosticsBlock::ClangTidyBlock &&F) {
373427
std::string Checks;
374428
for (auto &CheckGlob : F.Add)
375429
appendTidyCheckSpec(Checks, CheckGlob, true);
@@ -380,8 +434,9 @@ struct FragmentCompiler {
380434
if (!Checks.empty())
381435
Out.Apply.push_back(
382436
[Checks = std::move(Checks)](const Params &, Config &C) {
383-
C.ClangTidy.Checks.append(
384-
Checks, C.ClangTidy.Checks.empty() ? /*skip comma*/ 1 : 0,
437+
C.Diagnostics.ClangTidy.Checks.append(
438+
Checks,
439+
C.Diagnostics.ClangTidy.Checks.empty() ? /*skip comma*/ 1 : 0,
385440
std::string::npos);
386441
});
387442
if (!F.CheckOptions.empty()) {
@@ -392,8 +447,8 @@ struct FragmentCompiler {
392447
Out.Apply.push_back(
393448
[CheckOptions = std::move(CheckOptions)](const Params &, Config &C) {
394449
for (auto &StringPair : CheckOptions)
395-
C.ClangTidy.CheckOptions.insert_or_assign(StringPair.first,
396-
StringPair.second);
450+
C.Diagnostics.ClangTidy.CheckOptions.insert_or_assign(
451+
StringPair.first, StringPair.second);
397452
});
398453
}
399454
}

0 commit comments

Comments
 (0)