Skip to content

Commit dba9e78

Browse files
authored
Merge pull request llvm#7 from alexcrichton/merge-master
Merge upstream release/8.x branch
2 parents 73a75d3 + 2ebc272 commit dba9e78

File tree

403 files changed

+14333
-5257
lines changed

Some content is hidden

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

403 files changed

+14333
-5257
lines changed

clang-tools-extra/clang-tidy/ClangTidy.cpp

+1-17
Original file line numberDiff line numberDiff line change
@@ -529,24 +529,8 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
529529
return AdjustedArgs;
530530
};
531531

532-
// Remove plugins arguments.
533-
ArgumentsAdjuster PluginArgumentsRemover =
534-
[](const CommandLineArguments &Args, StringRef Filename) {
535-
CommandLineArguments AdjustedArgs;
536-
for (size_t I = 0, E = Args.size(); I < E; ++I) {
537-
if (I + 4 < Args.size() && Args[I] == "-Xclang" &&
538-
(Args[I + 1] == "-load" || Args[I + 1] == "-add-plugin" ||
539-
StringRef(Args[I + 1]).startswith("-plugin-arg-")) &&
540-
Args[I + 2] == "-Xclang") {
541-
I += 3;
542-
} else
543-
AdjustedArgs.push_back(Args[I]);
544-
}
545-
return AdjustedArgs;
546-
};
547-
548532
Tool.appendArgumentsAdjuster(PerFileExtraArgumentsInserter);
549-
Tool.appendArgumentsAdjuster(PluginArgumentsRemover);
533+
Tool.appendArgumentsAdjuster(getStripPluginsAdjuster());
550534
Context.setEnableProfiling(EnableCheckProfile);
551535
Context.setProfileStoragePrefix(StoreCheckProfile);
552536

clang-tools-extra/clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ AST_MATCHER(CXXRecordDecl, hasMethods) {
2323
return std::distance(Node.method_begin(), Node.method_end()) != 0;
2424
}
2525

26-
AST_MATCHER(CXXRecordDecl, hasNonStaticMethod) {
27-
return hasMethod(unless(isStaticStorageClass()))
26+
AST_MATCHER(CXXRecordDecl, hasNonStaticNonImplicitMethod) {
27+
return hasMethod(unless(anyOf(isStaticStorageClass(), isImplicit())))
2828
.matches(Node, Finder, Builder);
2929
}
3030

@@ -67,10 +67,11 @@ void NonPrivateMemberVariablesInClassesCheck::registerMatchers(
6767
IgnorePublicMemberVariables ? isProtected() : unless(isPrivate()));
6868

6969
// We only want the records that not only contain the mutable data (non-static
70-
// member variables), but also have some logic (non-static member functions).
71-
// We may optionally ignore records where all the member variables are public.
70+
// member variables), but also have some logic (non-static, non-implicit
71+
// member functions). We may optionally ignore records where all the member
72+
// variables are public.
7273
Finder->addMatcher(cxxRecordDecl(anyOf(isStruct(), isClass()), hasMethods(),
73-
hasNonStaticMethod(),
74+
hasNonStaticNonImplicitMethod(),
7475
unless(ShouldIgnoreRecord),
7576
forEach(InterestingField.bind("field")))
7677
.bind("record"),

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ AST_MATCHER(clang::RecordDecl, isExternCContext) {
3131
return Node.isExternCContext();
3232
}
3333

34+
AST_MATCHER(clang::ParmVarDecl, isArgvOfMain) {
35+
const clang::DeclContext *DC = Node.getDeclContext();
36+
const auto *FD = llvm::dyn_cast<clang::FunctionDecl>(DC);
37+
return FD ? FD->isMain() : false;
38+
}
39+
3440
} // namespace
3541

3642
namespace clang {
@@ -44,7 +50,8 @@ void AvoidCArraysCheck::registerMatchers(MatchFinder *Finder) {
4450

4551
Finder->addMatcher(
4652
typeLoc(hasValidBeginLoc(), hasType(arrayType()),
47-
unless(anyOf(hasParent(varDecl(isExternC())),
53+
unless(anyOf(hasParent(parmVarDecl(isArgvOfMain())),
54+
hasParent(varDecl(isExternC())),
4855
hasParent(fieldDecl(
4956
hasParent(recordDecl(isExternCContext())))),
5057
hasAncestor(functionDecl(isExternC())))))

clang-tools-extra/clangd/ClangdLSPServer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
290290
if (UseDirBasedCDB)
291291
BaseCDB = llvm::make_unique<DirectoryBasedGlobalCompilationDatabase>(
292292
CompileCommandsDir);
293-
CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags);
293+
CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags,
294+
ClangdServerOpts.ResourceDir);
294295
Server.emplace(*CDB, FSProvider, static_cast<DiagnosticsConsumer &>(*this),
295296
ClangdServerOpts);
296297
applyConfiguration(Params.initializationOptions.ConfigSettings);

clang-tools-extra/clangd/ClangdServer.cpp

+1-12
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ namespace clang {
3838
namespace clangd {
3939
namespace {
4040

41-
std::string getStandardResourceDir() {
42-
static int Dummy; // Just an address in this process.
43-
return CompilerInvocation::GetResourcesPath("clangd", (void *)&Dummy);
44-
}
45-
4641
class RefactoringResultCollector final
4742
: public tooling::RefactoringResultConsumer {
4843
public:
@@ -108,8 +103,6 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
108103
DiagnosticsConsumer &DiagConsumer,
109104
const Options &Opts)
110105
: CDB(CDB), FSProvider(FSProvider),
111-
ResourceDir(Opts.ResourceDir ? *Opts.ResourceDir
112-
: getStandardResourceDir()),
113106
DynamicIdx(Opts.BuildDynamicSymbolIndex
114107
? new FileIndex(Opts.HeavyweightDynamicSymbolIndex)
115108
: nullptr),
@@ -137,7 +130,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
137130
AddIndex(Opts.StaticIndex);
138131
if (Opts.BackgroundIndex) {
139132
BackgroundIdx = llvm::make_unique<BackgroundIndex>(
140-
Context::current().clone(), ResourceDir, FSProvider, CDB,
133+
Context::current().clone(), FSProvider, CDB,
141134
BackgroundIndexStorage::createDiskBackedStorageFactory(),
142135
Opts.BackgroundIndexRebuildPeriodMs);
143136
AddIndex(BackgroundIdx.get());
@@ -462,10 +455,6 @@ tooling::CompileCommand ClangdServer::getCompileCommand(PathRef File) {
462455
llvm::Optional<tooling::CompileCommand> C = CDB.getCompileCommand(File);
463456
if (!C) // FIXME: Suppress diagnostics? Let the user know?
464457
C = CDB.getFallbackCommand(File);
465-
466-
// Inject the resource dir.
467-
// FIXME: Don't overwrite it if it's already there.
468-
C->CommandLine.push_back("-resource-dir=" + ResourceDir);
469458
return std::move(*C);
470459
}
471460

clang-tools-extra/clangd/ExpectedTypes.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ static llvm::Optional<QualType>
3535
typeOfCompletion(const CodeCompletionResult &R) {
3636
auto *VD = dyn_cast_or_null<ValueDecl>(R.Declaration);
3737
if (!VD)
38-
return None; // We handle only variables and functions below.
38+
return llvm::None; // We handle only variables and functions below.
3939
auto T = VD->getType();
40+
if (T.isNull())
41+
return llvm::None;
4042
if (auto FuncT = T->getAs<FunctionType>()) {
4143
// Functions are a special case. They are completed as 'foo()' and we want
4244
// to match their return type rather than the function type itself.

clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

+37-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,36 @@
99

1010
#include "GlobalCompilationDatabase.h"
1111
#include "Logger.h"
12+
#include "clang/Frontend/CompilerInvocation.h"
13+
#include "clang/Tooling/ArgumentsAdjusters.h"
1214
#include "clang/Tooling/CompilationDatabase.h"
15+
#include "llvm/ADT/Optional.h"
1316
#include "llvm/Support/FileSystem.h"
1417
#include "llvm/Support/Path.h"
1518

1619
namespace clang {
1720
namespace clangd {
21+
namespace {
22+
23+
void adjustArguments(tooling::CompileCommand &Cmd,
24+
llvm::StringRef ResourceDir) {
25+
// Strip plugin related command line arguments. Clangd does
26+
// not support plugins currently. Therefore it breaks if
27+
// compiler tries to load plugins.
28+
Cmd.CommandLine =
29+
tooling::getStripPluginsAdjuster()(Cmd.CommandLine, Cmd.Filename);
30+
// Inject the resource dir.
31+
// FIXME: Don't overwrite it if it's already there.
32+
if (!ResourceDir.empty())
33+
Cmd.CommandLine.push_back(("-resource-dir=" + ResourceDir).str());
34+
}
35+
36+
std::string getStandardResourceDir() {
37+
static int Dummy; // Just an address in this process.
38+
return CompilerInvocation::GetResourcesPath("clangd", (void *)&Dummy);
39+
}
40+
41+
} // namespace
1842

1943
static std::string getFallbackClangPath() {
2044
static int Dummy;
@@ -106,8 +130,11 @@ DirectoryBasedGlobalCompilationDatabase::getCDBForFile(
106130
}
107131

108132
OverlayCDB::OverlayCDB(const GlobalCompilationDatabase *Base,
109-
std::vector<std::string> FallbackFlags)
110-
: Base(Base), FallbackFlags(std::move(FallbackFlags)) {
133+
std::vector<std::string> FallbackFlags,
134+
llvm::Optional<std::string> ResourceDir)
135+
: Base(Base), ResourceDir(ResourceDir ? std::move(*ResourceDir)
136+
: getStandardResourceDir()),
137+
FallbackFlags(std::move(FallbackFlags)) {
111138
if (Base)
112139
BaseChanged = Base->watch([this](const std::vector<std::string> Changes) {
113140
OnCommandChanged.broadcast(Changes);
@@ -116,16 +143,22 @@ OverlayCDB::OverlayCDB(const GlobalCompilationDatabase *Base,
116143

117144
llvm::Optional<tooling::CompileCommand>
118145
OverlayCDB::getCompileCommand(PathRef File, ProjectInfo *Project) const {
146+
llvm::Optional<tooling::CompileCommand> Cmd;
119147
{
120148
std::lock_guard<std::mutex> Lock(Mutex);
121149
auto It = Commands.find(File);
122150
if (It != Commands.end()) {
123151
if (Project)
124152
Project->SourceRoot = "";
125-
return It->second;
153+
Cmd = It->second;
126154
}
127155
}
128-
return Base ? Base->getCompileCommand(File, Project) : None;
156+
if (!Cmd && Base)
157+
Cmd = Base->getCompileCommand(File, Project);
158+
if (!Cmd)
159+
return llvm::None;
160+
adjustArguments(*Cmd, ResourceDir);
161+
return Cmd;
129162
}
130163

131164
tooling::CompileCommand OverlayCDB::getFallbackCommand(PathRef File) const {

clang-tools-extra/clangd/GlobalCompilationDatabase.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "Function.h"
1414
#include "Path.h"
15+
#include "llvm/ADT/Optional.h"
1516
#include "llvm/ADT/StringMap.h"
1617
#include <memory>
1718
#include <mutex>
@@ -98,7 +99,8 @@ class OverlayCDB : public GlobalCompilationDatabase {
9899
// Base may be null, in which case no entries are inherited.
99100
// FallbackFlags are added to the fallback compile command.
100101
OverlayCDB(const GlobalCompilationDatabase *Base,
101-
std::vector<std::string> FallbackFlags = {});
102+
std::vector<std::string> FallbackFlags = {},
103+
llvm::Optional<std::string> ResourceDir = llvm::None);
102104

103105
llvm::Optional<tooling::CompileCommand>
104106
getCompileCommand(PathRef File, ProjectInfo * = nullptr) const override;
@@ -113,6 +115,7 @@ class OverlayCDB : public GlobalCompilationDatabase {
113115
mutable std::mutex Mutex;
114116
llvm::StringMap<tooling::CompileCommand> Commands; /* GUARDED_BY(Mut) */
115117
const GlobalCompilationDatabase *Base;
118+
std::string ResourceDir;
116119
std::vector<std::string> FallbackFlags;
117120
CommandChanged::Subscription BaseChanged;
118121
};

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,12 @@ llvm::SmallString<128> getAbsolutePath(const tooling::CompileCommand &Cmd) {
127127
} // namespace
128128

129129
BackgroundIndex::BackgroundIndex(
130-
Context BackgroundContext, llvm::StringRef ResourceDir,
131-
const FileSystemProvider &FSProvider, const GlobalCompilationDatabase &CDB,
130+
Context BackgroundContext, const FileSystemProvider &FSProvider,
131+
const GlobalCompilationDatabase &CDB,
132132
BackgroundIndexStorage::Factory IndexStorageFactory,
133133
size_t BuildIndexPeriodMs, size_t ThreadPoolSize)
134-
: SwapIndex(llvm::make_unique<MemIndex>()), ResourceDir(ResourceDir),
135-
FSProvider(FSProvider), CDB(CDB),
136-
BackgroundContext(std::move(BackgroundContext)),
134+
: SwapIndex(llvm::make_unique<MemIndex>()), FSProvider(FSProvider),
135+
CDB(CDB), BackgroundContext(std::move(BackgroundContext)),
137136
BuildIndexPeriodMs(BuildIndexPeriodMs),
138137
SymbolsUpdatedSinceLastIndex(false),
139138
IndexStorageFactory(std::move(IndexStorageFactory)),
@@ -230,7 +229,6 @@ void BackgroundIndex::enqueue(tooling::CompileCommand Cmd,
230229
BackgroundIndexStorage *Storage) {
231230
enqueueTask(Bind(
232231
[this, Storage](tooling::CompileCommand Cmd) {
233-
Cmd.CommandLine.push_back("-resource-dir=" + ResourceDir);
234232
// We can't use llvm::StringRef here since we are going to
235233
// move from Cmd during the call below.
236234
const std::string FileName = Cmd.Filename;

clang-tools-extra/clangd/index/Background.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ class BackgroundIndex : public SwapIndex {
6868
/// If BuildIndexPeriodMs is greater than 0, the symbol index will only be
6969
/// rebuilt periodically (one per \p BuildIndexPeriodMs); otherwise, index is
7070
/// rebuilt for each indexed file.
71-
// FIXME: resource-dir injection should be hoisted somewhere common.
72-
BackgroundIndex(Context BackgroundContext, llvm::StringRef ResourceDir,
73-
const FileSystemProvider &,
71+
BackgroundIndex(Context BackgroundContext, const FileSystemProvider &,
7472
const GlobalCompilationDatabase &CDB,
7573
BackgroundIndexStorage::Factory IndexStorageFactory,
7674
size_t BuildIndexPeriodMs = 0,
@@ -99,7 +97,6 @@ class BackgroundIndex : public SwapIndex {
9997
BackgroundIndexStorage *IndexStorage);
10098

10199
// configuration
102-
std::string ResourceDir;
103100
const FileSystemProvider &FSProvider;
104101
const GlobalCompilationDatabase &CDB;
105102
Context BackgroundContext;

0 commit comments

Comments
 (0)