Skip to content

Commit 19e3cf9

Browse files
authored
LLVM and SPIRV-LLVM-Translator pulldown (ww25)
LLVM: 5a39bf2 LLVM-SPIRV-Translator: KhronosGroup/SPIRV-LLVM-Translator@43d1f10
2 parents 2e73da7 + 9947ba9 commit 19e3cf9

File tree

1,810 files changed

+75995
-23892
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,810 files changed

+75995
-23892
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
/GRTAGS
3636
/GSYMS
3737
/GTAGS
38+
/ID
3839
.gitusers
3940
autom4te.cache
4041
cscope.files

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
514514
if (ClangdServerOpts.ResourceDir)
515515
Mangler.ResourceDir = *ClangdServerOpts.ResourceDir;
516516
CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags,
517-
tooling::ArgumentsAdjuster(Mangler));
517+
tooling::ArgumentsAdjuster(std::move(Mangler)));
518518
{
519519
// Switch caller's context with LSPServer's background context. Since we
520520
// rather want to propagate information from LSPServer's context into the

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,16 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
179179
void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
180180
llvm::StringRef Version,
181181
WantDiagnostics WantDiags, bool ForceRebuild) {
182-
auto FS = FSProvider.getFileSystem();
183-
184182
ParseOptions Opts;
185183
Opts.ClangTidyOpts = tidy::ClangTidyOptions::getDefaults();
186184
// FIXME: call tidy options builder on the worker thread, it can do IO.
187185
if (GetClangTidyOptions)
188-
Opts.ClangTidyOpts = GetClangTidyOptions(*FS, File);
186+
Opts.ClangTidyOpts = GetClangTidyOptions(*FSProvider.getFileSystem(), File);
189187
Opts.SuggestMissingIncludes = SuggestMissingIncludes;
190188

191189
// Compile command is set asynchronously during update, as it can be slow.
192190
ParseInputs Inputs;
193-
Inputs.FS = FS;
191+
Inputs.FSProvider = &FSProvider;
194192
Inputs.Contents = std::string(Contents);
195193
Inputs.Version = Version.str();
196194
Inputs.ForceRebuild = ForceRebuild;
@@ -214,8 +212,7 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
214212
if (!CodeCompleteOpts.Index) // Respect overridden index.
215213
CodeCompleteOpts.Index = Index;
216214

217-
auto Task = [Pos, FS = FSProvider.getFileSystem(), CodeCompleteOpts,
218-
File = File.str(), CB = std::move(CB),
215+
auto Task = [Pos, CodeCompleteOpts, File = File.str(), CB = std::move(CB),
219216
this](llvm::Expected<InputsAndPreamble> IP) mutable {
220217
if (!IP)
221218
return CB(IP.takeError());
@@ -238,7 +235,7 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
238235
}
239236
}
240237
}
241-
ParseInputs ParseInput{IP->Command, FS, IP->Contents.str()};
238+
ParseInputs ParseInput{IP->Command, &FSProvider, IP->Contents.str()};
242239
ParseInput.Index = Index;
243240
ParseInput.Opts.BuildRecoveryAST = BuildRecoveryAST;
244241
ParseInput.Opts.PreserveRecoveryASTType = PreserveRecoveryASTType;
@@ -275,8 +272,7 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
275272
void ClangdServer::signatureHelp(PathRef File, Position Pos,
276273
Callback<SignatureHelp> CB) {
277274

278-
auto Action = [Pos, FS = FSProvider.getFileSystem(), File = File.str(),
279-
CB = std::move(CB),
275+
auto Action = [Pos, File = File.str(), CB = std::move(CB),
280276
this](llvm::Expected<InputsAndPreamble> IP) mutable {
281277
if (!IP)
282278
return CB(IP.takeError());
@@ -286,7 +282,7 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos,
286282
return CB(llvm::createStringError(llvm::inconvertibleErrorCode(),
287283
"Failed to parse includes"));
288284

289-
ParseInputs ParseInput{IP->Command, FS, IP->Contents.str()};
285+
ParseInputs ParseInput{IP->Command, &FSProvider, IP->Contents.str()};
290286
ParseInput.Index = Index;
291287
ParseInput.Opts.BuildRecoveryAST = BuildRecoveryAST;
292288
ParseInput.Opts.PreserveRecoveryASTType = PreserveRecoveryASTType;
@@ -399,8 +395,9 @@ void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
399395
return CB(Edits.takeError());
400396

401397
if (Opts.WantFormat) {
402-
auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
403-
InpAST->Inputs.FS.get());
398+
auto Style = getFormatStyleForFile(
399+
File, InpAST->Inputs.Contents,
400+
InpAST->Inputs.FSProvider->getFileSystem().get());
404401
llvm::Error Err = llvm::Error::success();
405402
for (auto &E : *Edits)
406403
Err =
@@ -600,8 +597,9 @@ void ClangdServer::findHover(PathRef File, Position Pos,
600597
this](llvm::Expected<InputsAndAST> InpAST) mutable {
601598
if (!InpAST)
602599
return CB(InpAST.takeError());
603-
format::FormatStyle Style = getFormatStyleForFile(
604-
File, InpAST->Inputs.Contents, InpAST->Inputs.FS.get());
600+
format::FormatStyle Style =
601+
getFormatStyleForFile(File, InpAST->Inputs.Contents,
602+
InpAST->Inputs.FSProvider->getFileSystem().get());
605603
CB(clangd::getHover(InpAST->AST, Pos, std::move(Style), Index));
606604
};
607605

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "index/Index.h"
3737
#include "index/Symbol.h"
3838
#include "index/SymbolOrigin.h"
39+
#include "support/FSProvider.h"
3940
#include "support/Logger.h"
4041
#include "support/Threading.h"
4142
#include "support/Trace.h"
@@ -44,10 +45,12 @@
4445
#include "clang/Basic/CharInfo.h"
4546
#include "clang/Basic/LangOptions.h"
4647
#include "clang/Basic/SourceLocation.h"
48+
#include "clang/Basic/TokenKinds.h"
4749
#include "clang/Format/Format.h"
4850
#include "clang/Frontend/CompilerInstance.h"
4951
#include "clang/Frontend/FrontendActions.h"
5052
#include "clang/Lex/ExternalPreprocessorSource.h"
53+
#include "clang/Lex/Lexer.h"
5154
#include "clang/Lex/Preprocessor.h"
5255
#include "clang/Lex/PreprocessorOptions.h"
5356
#include "clang/Sema/CodeCompleteConsumer.h"
@@ -254,10 +257,11 @@ struct CodeCompletionBuilder {
254257
const IncludeInserter &Includes,
255258
llvm::StringRef FileName,
256259
CodeCompletionContext::Kind ContextKind,
257-
const CodeCompleteOptions &Opts, bool GenerateSnippets)
260+
const CodeCompleteOptions &Opts,
261+
bool IsUsingDeclaration, tok::TokenKind NextTokenKind)
258262
: ASTCtx(ASTCtx), ExtractDocumentation(Opts.IncludeComments),
259263
EnableFunctionArgSnippets(Opts.EnableFunctionArgSnippets),
260-
GenerateSnippets(GenerateSnippets) {
264+
IsUsingDeclaration(IsUsingDeclaration), NextTokenKind(NextTokenKind) {
261265
add(C, SemaCCS);
262266
if (C.SemaResult) {
263267
assert(ASTCtx);
@@ -428,7 +432,13 @@ struct CodeCompletionBuilder {
428432
}
429433

430434
std::string summarizeSnippet() const {
431-
if (!GenerateSnippets)
435+
if (IsUsingDeclaration)
436+
return "";
437+
// Suppress function argument snippets if args are already present.
438+
if ((Completion.Kind == CompletionItemKind::Function ||
439+
Completion.Kind == CompletionItemKind::Method ||
440+
Completion.Kind == CompletionItemKind::Constructor) &&
441+
NextTokenKind == tok::l_paren)
432442
return "";
433443
auto *Snippet = onlyValue<&BundledEntry::SnippetSuffix>();
434444
if (!Snippet)
@@ -487,8 +497,10 @@ struct CodeCompletionBuilder {
487497
llvm::SmallVector<BundledEntry, 1> Bundled;
488498
bool ExtractDocumentation;
489499
bool EnableFunctionArgSnippets;
490-
/// When false, no snippets are generated argument lists.
491-
bool GenerateSnippets;
500+
// No snippets will be generated for using declarations and when the function
501+
// arguments are already present.
502+
bool IsUsingDeclaration;
503+
tok::TokenKind NextTokenKind;
492504
};
493505

494506
// Determine the symbol ID for a Sema code completion result, if possible.
@@ -1060,9 +1072,6 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
10601072
const SemaCompleteInput &Input,
10611073
IncludeStructure *Includes = nullptr) {
10621074
trace::Span Tracer("Sema completion");
1063-
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = Input.ParseInput.FS;
1064-
if (Input.Preamble.StatCache)
1065-
VFS = Input.Preamble.StatCache->getConsumingFS(std::move(VFS));
10661075

10671076
IgnoreDiagnostics IgnoreDiags;
10681077
auto CI = buildCompilerInvocation(Input.ParseInput, IgnoreDiags);
@@ -1103,6 +1112,13 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
11031112
Input.Patch->apply(*CI);
11041113
// NOTE: we must call BeginSourceFile after prepareCompilerInstance. Otherwise
11051114
// the remapped buffers do not get freed.
1115+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
1116+
Input.ParseInput.FSProvider->getFileSystem();
1117+
if (Input.Preamble.StatCache)
1118+
VFS = Input.Preamble.StatCache->getConsumingFS(std::move(VFS));
1119+
if (VFS->setCurrentWorkingDirectory(
1120+
Input.ParseInput.CompileCommand.Directory))
1121+
elog("Couldn't set working directory during code completion");
11061122
auto Clang = prepareCompilerInstance(
11071123
std::move(CI), !CompletingInPreamble ? &Input.Preamble.Preamble : nullptr,
11081124
std::move(ContentsBuffer), std::move(VFS), IgnoreDiags);
@@ -1221,6 +1237,10 @@ class CodeCompleteFlow {
12211237
CompletionRecorder *Recorder = nullptr;
12221238
CodeCompletionContext::Kind CCContextKind = CodeCompletionContext::CCC_Other;
12231239
bool IsUsingDeclaration = false;
1240+
// The snippets will not be generated if the token following completion
1241+
// location is an opening parenthesis (tok::l_paren) because this would add
1242+
// extra parenthesis.
1243+
tok::TokenKind NextTokenKind = tok::eof;
12241244
// Counters for logging.
12251245
int NSema = 0, NIndex = 0, NSemaAndIndex = 0, NIdent = 0;
12261246
bool Incomplete = false; // Would more be available with a higher limit?
@@ -1272,9 +1292,14 @@ class CodeCompleteFlow {
12721292
assert(Recorder && "Recorder is not set");
12731293
CCContextKind = Recorder->CCContext.getKind();
12741294
IsUsingDeclaration = Recorder->CCContext.isUsingDeclaration();
1275-
auto Style = getFormatStyleForFile(SemaCCInput.FileName,
1276-
SemaCCInput.ParseInput.Contents,
1277-
SemaCCInput.ParseInput.FS.get());
1295+
auto Style = getFormatStyleForFile(
1296+
SemaCCInput.FileName, SemaCCInput.ParseInput.Contents,
1297+
SemaCCInput.ParseInput.FSProvider->getFileSystem().get());
1298+
const auto NextToken = Lexer::findNextToken(
1299+
Recorder->CCSema->getPreprocessor().getCodeCompletionLoc(),
1300+
Recorder->CCSema->getSourceManager(), Recorder->CCSema->LangOpts);
1301+
if (NextToken)
1302+
NextTokenKind = NextToken->getKind();
12781303
// If preprocessor was run, inclusions from preprocessor callback should
12791304
// already be added to Includes.
12801305
Inserter.emplace(
@@ -1692,8 +1717,7 @@ class CodeCompleteFlow {
16921717
if (!Builder)
16931718
Builder.emplace(Recorder ? &Recorder->CCSema->getASTContext() : nullptr,
16941719
Item, SemaCCS, QueryScopes, *Inserter, FileName,
1695-
CCContextKind, Opts,
1696-
/*GenerateSnippets=*/!IsUsingDeclaration);
1720+
CCContextKind, Opts, IsUsingDeclaration, NextTokenKind);
16971721
else
16981722
Builder->add(Item, SemaCCS);
16991723
}
@@ -1759,8 +1783,9 @@ CodeCompleteResult codeComplete(PathRef FileName, Position Pos,
17591783
FileName, Preamble ? Preamble->Includes : IncludeStructure(),
17601784
SpecFuzzyFind, Opts);
17611785
return (!Preamble || Opts.RunParser == CodeCompleteOptions::NeverParse)
1762-
? std::move(Flow).runWithoutSema(ParseInput.Contents, *Offset,
1763-
ParseInput.FS)
1786+
? std::move(Flow).runWithoutSema(
1787+
ParseInput.Contents, *Offset,
1788+
ParseInput.FSProvider->getFileSystem())
17641789
: std::move(Flow).run({FileName, *Offset, *Preamble,
17651790
// We want to serve code completions with
17661791
// low latency, so don't bother patching.

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,48 @@ std::string detectStandardResourceDir() {
119119
return CompilerInvocation::GetResourcesPath("clangd", (void *)&Dummy);
120120
}
121121

122+
// The path passed to argv[0] is important:
123+
// - its parent directory is Driver::Dir, used for library discovery
124+
// - its basename affects CLI parsing (clang-cl) and other settings
125+
// Where possible it should be an absolute path with sensible directory, but
126+
// with the original basename.
127+
static std::string resolveDriver(llvm::StringRef Driver, bool FollowSymlink,
128+
llvm::Optional<std::string> ClangPath) {
129+
auto SiblingOf = [&](llvm::StringRef AbsPath) {
130+
llvm::SmallString<128> Result = llvm::sys::path::parent_path(AbsPath);
131+
llvm::sys::path::append(Result, llvm::sys::path::filename(Driver));
132+
return Result.str().str();
133+
};
134+
135+
// First, eliminate relative paths.
136+
std::string Storage;
137+
if (!llvm::sys::path::is_absolute(Driver)) {
138+
// If the driver is a generic like "g++" with no path, add clang dir.
139+
if (ClangPath &&
140+
(Driver == "clang" || Driver == "clang++" || Driver == "gcc" ||
141+
Driver == "g++" || Driver == "cc" || Driver == "c++")) {
142+
return SiblingOf(*ClangPath);
143+
}
144+
// Otherwise try to look it up on PATH. This won't change basename.
145+
auto Absolute = llvm::sys::findProgramByName(Driver);
146+
if (Absolute && llvm::sys::path::is_absolute(*Absolute))
147+
Driver = Storage = std::move(*Absolute);
148+
else if (ClangPath) // If we don't find it, use clang dir again.
149+
return SiblingOf(*ClangPath);
150+
else // Nothing to do: can't find the command and no detected dir.
151+
return Driver.str();
152+
}
153+
154+
// Now we have an absolute path, but it may be a symlink.
155+
assert(llvm::sys::path::is_absolute(Driver));
156+
if (FollowSymlink) {
157+
llvm::SmallString<256> Resolved;
158+
if (!llvm::sys::fs::real_path(Driver, Resolved))
159+
return SiblingOf(Resolved);
160+
}
161+
return Driver.str();
162+
}
163+
122164
} // namespace
123165

124166
CommandMangler CommandMangler::detect() {
@@ -162,25 +204,22 @@ void CommandMangler::adjust(std::vector<std::string> &Cmd) const {
162204
Cmd.push_back(*Sysroot);
163205
}
164206

165-
// If the driver is a generic name like "g++" with no path, add a clang path.
166-
// This makes it easier for us to find the standard libraries on mac.
167-
if (ClangPath && llvm::sys::path::is_absolute(*ClangPath) && !Cmd.empty()) {
168-
std::string &Driver = Cmd.front();
169-
if (Driver == "clang" || Driver == "clang++" || Driver == "gcc" ||
170-
Driver == "g++" || Driver == "cc" || Driver == "c++") {
171-
llvm::SmallString<128> QualifiedDriver =
172-
llvm::sys::path::parent_path(*ClangPath);
173-
llvm::sys::path::append(QualifiedDriver, Driver);
174-
Driver = std::string(QualifiedDriver.str());
175-
}
207+
if (!Cmd.empty()) {
208+
bool FollowSymlink = !Has("-no-canonical-prefixes");
209+
Cmd.front() =
210+
(FollowSymlink ? ResolvedDrivers : ResolvedDriversNoFollow)
211+
.get(Cmd.front(), [&, this] {
212+
return resolveDriver(Cmd.front(), FollowSymlink, ClangPath);
213+
});
176214
}
177215
}
178216

179-
CommandMangler::operator clang::tooling::ArgumentsAdjuster() {
180-
return [Mangler{*this}](const std::vector<std::string> &Args,
181-
llvm::StringRef File) {
217+
CommandMangler::operator clang::tooling::ArgumentsAdjuster() && {
218+
// ArgumentsAdjuster is a std::function and so must be copyable.
219+
return [Mangler = std::make_shared<CommandMangler>(std::move(*this))](
220+
const std::vector<std::string> &Args, llvm::StringRef File) {
182221
auto Result = Args;
183-
Mangler.adjust(Result);
222+
Mangler->adjust(Result);
184223
return Result;
185224
};
186225
}

clang-tools-extra/clangd/CompileCommands.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILECOMMANDS_H
99
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILECOMMANDS_H
1010

11+
#include "support/Threading.h"
1112
#include "clang/Tooling/ArgumentsAdjusters.h"
1213
#include "clang/Tooling/CompilationDatabase.h"
14+
#include "llvm/ADT/StringMap.h"
1315
#include <string>
1416
#include <vector>
1517

@@ -40,10 +42,12 @@ struct CommandMangler {
4042
static CommandMangler detect();
4143

4244
void adjust(std::vector<std::string> &Cmd) const;
43-
explicit operator clang::tooling::ArgumentsAdjuster();
45+
explicit operator clang::tooling::ArgumentsAdjuster() &&;
4446

4547
private:
4648
CommandMangler() = default;
49+
Memoize<llvm::StringMap<std::string>> ResolvedDrivers;
50+
Memoize<llvm::StringMap<std::string>> ResolvedDriversNoFollow;
4751
};
4852

4953
} // namespace clangd

clang-tools-extra/clangd/Compiler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
4747
for (const auto &S : Inputs.CompileCommand.CommandLine)
4848
ArgStrs.push_back(S.c_str());
4949

50-
if (Inputs.FS->setCurrentWorkingDirectory(Inputs.CompileCommand.Directory)) {
50+
auto VFS = Inputs.FSProvider->getFileSystem();
51+
if (VFS->setCurrentWorkingDirectory(Inputs.CompileCommand.Directory)) {
5152
log("Couldn't set working directory when creating compiler invocation.");
5253
// We proceed anyway, our lit-tests rely on results for non-existing working
5354
// dirs.
@@ -56,7 +57,7 @@ buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
5657
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> CommandLineDiagsEngine =
5758
CompilerInstance::createDiagnostics(new DiagnosticOptions, &D, false);
5859
std::unique_ptr<CompilerInvocation> CI = createInvocationFromCommandLine(
59-
ArgStrs, CommandLineDiagsEngine, Inputs.FS,
60+
ArgStrs, CommandLineDiagsEngine, std::move(VFS),
6061
/*ShouldRecoverOnErrors=*/true, CC1Args);
6162
if (!CI)
6263
return nullptr;

clang-tools-extra/clangd/Compiler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "../clang-tidy/ClangTidyOptions.h"
1919
#include "GlobalCompilationDatabase.h"
2020
#include "index/Index.h"
21+
#include "support/FSProvider.h"
2122
#include "clang/Frontend/CompilerInstance.h"
2223
#include "clang/Frontend/PrecompiledPreamble.h"
2324
#include "clang/Tooling/CompilationDatabase.h"
@@ -45,7 +46,7 @@ struct ParseOptions {
4546
/// Information required to run clang, e.g. to parse AST or do code completion.
4647
struct ParseInputs {
4748
tooling::CompileCommand CompileCommand;
48-
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;
49+
const FileSystemProvider *FSProvider;
4950
std::string Contents;
5051
// Version identifier for Contents, provided by the client and opaque to us.
5152
std::string Version = "null";

0 commit comments

Comments
 (0)