Skip to content

Commit a7bc1a7

Browse files
committed
Merge from 'main' to 'sycl-web' (207 commits)
CONFLICT (content): Merge conflict in llvm/lib/Passes/PassRegistry.def
2 parents 102df2a + 913b561 commit a7bc1a7

File tree

1,301 files changed

+28370
-6114
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,301 files changed

+28370
-6114
lines changed

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,9 @@ int clangTidyMain(int argc, const char **argv) {
519519
std::vector<clang::tidy::ClangTidyOptionsProvider::OptionsSource>
520520
RawOptions = OptionsProvider->getRawOptions(FilePath);
521521
for (const std::string &Check : EnabledChecks) {
522-
for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) {
523-
if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) {
524-
llvm::outs() << "'" << Check << "' is enabled in the " << It->second
522+
for (const auto &[Opts, Source] : llvm::reverse(RawOptions)) {
523+
if (Opts.Checks && GlobList(*Opts.Checks).contains(Check)) {
524+
llvm::outs() << "'" << Check << "' is enabled in the " << Source
525525
<< ".\n";
526526
break;
527527
}
@@ -557,20 +557,16 @@ int clangTidyMain(int argc, const char **argv) {
557557
NamesAndOptions Valid =
558558
getAllChecksAndOptions(AllowEnablingAnalyzerAlphaCheckers);
559559
bool AnyInvalid = false;
560-
for (const std::pair<ClangTidyOptions, std::string> &OptionWithSource :
561-
RawOptions) {
562-
const ClangTidyOptions &Opts = OptionWithSource.first;
560+
for (const auto &[Opts, Source] : RawOptions) {
563561
if (Opts.Checks)
564-
AnyInvalid |=
565-
verifyChecks(Valid.Names, *Opts.Checks, OptionWithSource.second);
562+
AnyInvalid |= verifyChecks(Valid.Names, *Opts.Checks, Source);
566563

567564
for (auto Key : Opts.CheckOptions.keys()) {
568565
if (Valid.Options.contains(Key))
569566
continue;
570567
AnyInvalid = true;
571-
auto &Output =
572-
llvm::WithColor::warning(llvm::errs(), OptionWithSource.second)
573-
<< "unknown check option '" << Key << '\'';
568+
auto &Output = llvm::WithColor::warning(llvm::errs(), Source)
569+
<< "unknown check option '" << Key << '\'';
574570
llvm::StringRef Closest = closest(Key, Valid.Options);
575571
if (!Closest.empty())
576572
Output << "; did you mean '" << Closest << '\'';

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ add_clang_library(clangDaemon
9797
SemanticHighlighting.cpp
9898
SemanticSelection.cpp
9999
SourceCode.cpp
100-
QueryDriverDatabase.cpp
100+
SystemIncludeExtractor.cpp
101101
TidyProvider.cpp
102102
TUScheduler.cpp
103103
URI.cpp

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,14 +502,14 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
502502
CDBOpts.ContextProvider = Opts.ContextProvider;
503503
BaseCDB =
504504
std::make_unique<DirectoryBasedGlobalCompilationDatabase>(CDBOpts);
505-
BaseCDB = getQueryDriverDatabase(llvm::makeArrayRef(Opts.QueryDriverGlobs),
506-
std::move(BaseCDB));
507505
}
508506
auto Mangler = CommandMangler::detect();
507+
Mangler.SystemIncludeExtractor =
508+
getSystemIncludeExtractor(llvm::makeArrayRef(Opts.QueryDriverGlobs));
509509
if (Opts.ResourceDir)
510510
Mangler.ResourceDir = *Opts.ResourceDir;
511511
CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags,
512-
tooling::ArgumentsAdjuster(std::move(Mangler)));
512+
std::move(Mangler));
513513
{
514514
// Switch caller's context with LSPServer's background context. Since we
515515
// rather want to propagate information from LSPServer's context into the
@@ -1815,5 +1815,6 @@ void ClangdLSPServer::onSemanticsMaybeChanged(PathRef File) {
18151815
});
18161816
}
18171817
}
1818+
18181819
} // namespace clangd
18191820
} // namespace clang

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "clang/Driver/Driver.h"
1414
#include "clang/Driver/Options.h"
1515
#include "clang/Frontend/CompilerInvocation.h"
16-
#include "clang/Tooling/ArgumentsAdjusters.h"
1716
#include "clang/Tooling/CompilationDatabase.h"
1817
#include "llvm/ADT/ArrayRef.h"
1918
#include "llvm/ADT/STLExtras.h"
@@ -195,8 +194,9 @@ CommandMangler CommandMangler::detect() {
195194

196195
CommandMangler CommandMangler::forTests() { return CommandMangler(); }
197196

198-
void CommandMangler::adjust(std::vector<std::string> &Cmd,
199-
llvm::StringRef File) const {
197+
void CommandMangler::operator()(tooling::CompileCommand &Command,
198+
llvm::StringRef File) const {
199+
std::vector<std::string> &Cmd = Command.CommandLine;
200200
trace::Span S("AdjustCompileFlags");
201201
// Most of the modifications below assumes the Cmd starts with a driver name.
202202
// We might consider injecting a generic driver name like "cc" or "c++", but
@@ -301,6 +301,17 @@ void CommandMangler::adjust(std::vector<std::string> &Cmd,
301301
for (auto &Edit : Config::current().CompileFlags.Edits)
302302
Edit(Cmd);
303303

304+
// The system include extractor needs to run:
305+
// - AFTER transferCompileCommand(), because the -x flag it adds may be
306+
// necessary for the system include extractor to identify the file type
307+
// - AFTER applying CompileFlags.Edits, because the name of the compiler
308+
// that needs to be invoked may come from the CompileFlags->Compiler key
309+
// - BEFORE resolveDriver() because that can mess up the driver path,
310+
// e.g. changing gcc to /path/to/clang/bin/gcc
311+
if (SystemIncludeExtractor) {
312+
SystemIncludeExtractor(Command, File);
313+
}
314+
304315
// Check whether the flag exists, either as -flag or -flag=*
305316
auto Has = [&](llvm::StringRef Flag) {
306317
for (llvm::StringRef Arg : Cmd) {
@@ -340,16 +351,6 @@ void CommandMangler::adjust(std::vector<std::string> &Cmd,
340351
}
341352
}
342353

343-
CommandMangler::operator clang::tooling::ArgumentsAdjuster() && {
344-
// ArgumentsAdjuster is a std::function and so must be copyable.
345-
return [Mangler = std::make_shared<CommandMangler>(std::move(*this))](
346-
const std::vector<std::string> &Args, llvm::StringRef File) {
347-
auto Result = Args;
348-
Mangler->adjust(Result, File);
349-
return Result;
350-
};
351-
}
352-
353354
// ArgStripper implementation
354355
namespace {
355356

clang-tools-extra/clangd/CompileCommands.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILECOMMANDS_H
99
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILECOMMANDS_H
1010

11+
#include "GlobalCompilationDatabase.h"
1112
#include "support/Threading.h"
12-
#include "clang/Tooling/ArgumentsAdjusters.h"
1313
#include "llvm/ADT/StringMap.h"
1414
#include "llvm/ADT/StringRef.h"
1515
#include <deque>
@@ -32,6 +32,7 @@ struct CommandMangler {
3232
llvm::Optional<std::string> ResourceDir;
3333
// Root for searching for standard library (passed to -isysroot).
3434
llvm::Optional<std::string> Sysroot;
35+
SystemIncludeExtractorFn SystemIncludeExtractor;
3536

3637
// A command-mangler that doesn't know anything about the system.
3738
// This is hermetic for unit-tests, but won't work well in production.
@@ -42,11 +43,14 @@ struct CommandMangler {
4243
// - on mac, find clang and isysroot by querying the `xcrun` launcher
4344
static CommandMangler detect();
4445

45-
void adjust(std::vector<std::string> &Cmd, llvm::StringRef File) const;
46-
explicit operator clang::tooling::ArgumentsAdjuster() &&;
46+
// `Cmd` may describe compilation of a different file, and will be updated
47+
// for parsing `TargetFile`.
48+
void operator()(tooling::CompileCommand &Cmd,
49+
llvm::StringRef TargetFile) const;
4750

4851
private:
4952
CommandMangler() = default;
53+
5054
Memoize<llvm::StringMap<std::string>> ResolvedDrivers;
5155
Memoize<llvm::StringMap<std::string>> ResolvedDriversNoFollow;
5256
};

clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,8 @@ DirectoryBasedGlobalCompilationDatabase::getProjectInfo(PathRef File) const {
740740

741741
OverlayCDB::OverlayCDB(const GlobalCompilationDatabase *Base,
742742
std::vector<std::string> FallbackFlags,
743-
tooling::ArgumentsAdjuster Adjuster)
744-
: DelegatingCDB(Base), ArgsAdjuster(std::move(Adjuster)),
743+
CommandMangler Mangler)
744+
: DelegatingCDB(Base), Mangler(std::move(Mangler)),
745745
FallbackFlags(std::move(FallbackFlags)) {}
746746

747747
llvm::Optional<tooling::CompileCommand>
@@ -757,8 +757,8 @@ OverlayCDB::getCompileCommand(PathRef File) const {
757757
Cmd = DelegatingCDB::getCompileCommand(File);
758758
if (!Cmd)
759759
return llvm::None;
760-
if (ArgsAdjuster)
761-
Cmd->CommandLine = ArgsAdjuster(Cmd->CommandLine, File);
760+
if (Mangler)
761+
Mangler(*Cmd, File);
762762
return Cmd;
763763
}
764764

@@ -767,8 +767,8 @@ tooling::CompileCommand OverlayCDB::getFallbackCommand(PathRef File) const {
767767
std::lock_guard<std::mutex> Lock(Mutex);
768768
Cmd.CommandLine.insert(Cmd.CommandLine.end(), FallbackFlags.begin(),
769769
FallbackFlags.end());
770-
if (ArgsAdjuster)
771-
Cmd.CommandLine = ArgsAdjuster(Cmd.CommandLine, File);
770+
if (Mangler)
771+
Mangler(Cmd, File);
772772
return Cmd;
773773
}
774774

clang-tools-extra/clangd/GlobalCompilationDatabase.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "support/ThreadsafeFS.h"
1616
#include "clang/Tooling/ArgumentsAdjusters.h"
1717
#include "clang/Tooling/CompilationDatabase.h"
18+
#include "llvm/ADT/FunctionExtras.h"
1819
#include "llvm/ADT/Optional.h"
1920
#include "llvm/ADT/StringMap.h"
2021
#include <memory>
@@ -161,22 +162,28 @@ class DirectoryBasedGlobalCompilationDatabase
161162
};
162163

163164
/// Extracts system include search path from drivers matching QueryDriverGlobs
164-
/// and adds them to the compile flags. Base may not be nullptr.
165-
/// Returns Base when \p QueryDriverGlobs is empty.
166-
std::unique_ptr<GlobalCompilationDatabase>
167-
getQueryDriverDatabase(llvm::ArrayRef<std::string> QueryDriverGlobs,
168-
std::unique_ptr<GlobalCompilationDatabase> Base);
165+
/// and adds them to the compile flags.
166+
/// Returns null when \p QueryDriverGlobs is empty.
167+
using SystemIncludeExtractorFn = llvm::unique_function<void(
168+
tooling::CompileCommand &, llvm::StringRef) const>;
169+
SystemIncludeExtractorFn
170+
getSystemIncludeExtractor(llvm::ArrayRef<std::string> QueryDriverGlobs);
169171

170172
/// Wraps another compilation database, and supports overriding the commands
171173
/// using an in-memory mapping.
172174
class OverlayCDB : public DelegatingCDB {
173175
public:
176+
// Makes adjustments to a tooling::CompileCommand which will be used to
177+
// process a file (possibly different from the one in the command).
178+
using CommandMangler = llvm::unique_function<void(tooling::CompileCommand &,
179+
StringRef File) const>;
180+
174181
// Base may be null, in which case no entries are inherited.
175182
// FallbackFlags are added to the fallback compile command.
176183
// Adjuster is applied to all commands, fallback or not.
177184
OverlayCDB(const GlobalCompilationDatabase *Base,
178185
std::vector<std::string> FallbackFlags = {},
179-
tooling::ArgumentsAdjuster Adjuster = nullptr);
186+
CommandMangler Mangler = nullptr);
180187

181188
llvm::Optional<tooling::CompileCommand>
182189
getCompileCommand(PathRef File) const override;
@@ -190,7 +197,7 @@ class OverlayCDB : public DelegatingCDB {
190197
private:
191198
mutable std::mutex Mutex;
192199
llvm::StringMap<tooling::CompileCommand> Commands; /* GUARDED_BY(Mut) */
193-
tooling::ArgumentsAdjuster ArgsAdjuster;
200+
CommandMangler Mangler;
194201
std::vector<std::string> FallbackFlags;
195202
};
196203

clang-tools-extra/clangd/Headers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class IncludeStructure::RecordHeaders : public PPCallbacks,
164164
LastPragmaKeepInMainFileLine =
165165
SM.getLineNumber(SM.getMainFileID(), Offset) - 1;
166166
} else {
167-
// Memorize headers that that have export pragmas in them. Include Cleaner
167+
// Memorize headers that have export pragmas in them. Include Cleaner
168168
// does not support them properly yet, so they will be not marked as
169169
// unused.
170170
// FIXME: Once IncludeCleaner supports export pragmas, remove this.

clang-tools-extra/clangd/Protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ struct SemanticTokensDeltaParams {
17001700
bool fromJSON(const llvm::json::Value &Params, SemanticTokensDeltaParams &R,
17011701
llvm::json::Path);
17021702

1703-
/// Describes a a replacement of a contiguous range of semanticTokens.
1703+
/// Describes a replacement of a contiguous range of semanticTokens.
17041704
struct SemanticTokensEdit {
17051705
// LSP specifies `start` and `deleteCount` which are relative to the array
17061706
// encoding of the previous tokens.

clang-tools-extra/clangd/Selection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ class SelectionTester {
395395
// Implausible if upperbound(Tok) < First.
396396
if (auto Offset = LastAffectedToken(Tok.location()))
397397
return *Offset < First;
398-
// A prefix of the expanded tokens may be from an an implicit
398+
// A prefix of the expanded tokens may be from an implicit
399399
// inclusion (e.g. preamble patch, or command-line -include).
400400
return true;
401401
});

0 commit comments

Comments
 (0)