Skip to content

Commit 5ae9a37

Browse files
committed
Merge commit 'df4ad3625fad54d91b688564d5b2408aa943ebe4' into feature/merge-upstream-20220105
2 parents bdca31d + df4ad36 commit 5ae9a37

File tree

944 files changed

+31116
-9004
lines changed

Some content is hidden

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

944 files changed

+31116
-9004
lines changed

.clang-tidy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ CheckOptions:
1616
value: CamelCase
1717
- key: readability-identifier-naming.IgnoreMainLikeFunctions
1818
value: 1
19-
19+
- key: readability-redundant-member-init.IgnoreBaseInCopyConstructors
20+
value: 1

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,14 @@ void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
212212
InitBase);
213213

214214
Finder->addMatcher(
215-
cxxConstructorDecl(
216-
isDefaultConstructor(),
217-
forEachConstructorInitializer(
218-
cxxCtorInitializer(
219-
forField(unless(anyOf(getLangOpts().CPlusPlus20
220-
? unless(anything())
221-
: isBitField(),
222-
hasInClassInitializer(anything()),
223-
hasParent(recordDecl(isUnion()))))),
224-
withInitializer(Init))
225-
.bind("default"))),
215+
cxxConstructorDecl(forEachConstructorInitializer(
216+
cxxCtorInitializer(
217+
forField(unless(anyOf(
218+
getLangOpts().CPlusPlus20 ? unless(anything()) : isBitField(),
219+
hasInClassInitializer(anything()),
220+
hasParent(recordDecl(isUnion()))))),
221+
withInitializer(Init))
222+
.bind("default"))),
226223
this);
227224

228225
Finder->addMatcher(
@@ -248,6 +245,14 @@ void UseDefaultMemberInitCheck::checkDefaultInit(
248245
const MatchFinder::MatchResult &Result, const CXXCtorInitializer *Init) {
249246
const FieldDecl *Field = Init->getAnyMember();
250247

248+
// Check whether we have multiple hand-written constructors and bomb out, as
249+
// it is hard to reconcile their sets of member initializers.
250+
const auto *ClassDecl = dyn_cast<CXXRecordDecl>(Field->getParent());
251+
if (llvm::count_if(ClassDecl->ctors(), [](const CXXConstructorDecl *Ctor) {
252+
return !Ctor->isCopyOrMoveConstructor();
253+
}) > 1)
254+
return;
255+
251256
SourceLocation StartLoc = Field->getBeginLoc();
252257
if (StartLoc.isMacroID() && IgnoreMacros)
253258
return;

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ add_clang_library(clangDaemon
131131
index/dex/PostingList.cpp
132132
index/dex/Trigram.cpp
133133

134+
refactor/InsertionPoint.cpp
134135
refactor/Rename.cpp
135136
refactor/Tweak.cpp
136137

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
555555
}},
556556
{"signatureHelpProvider",
557557
llvm::json::Object{
558-
{"triggerCharacters", {"(", ",", ")"}},
558+
{"triggerCharacters", {"(", ")", "{", "}", "<", ">", ","}},
559559
}},
560560
{"declarationProvider", true},
561561
{"definitionProvider", true},

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -895,14 +895,9 @@ struct ScoredSignature {
895895
// part of it.
896896
int paramIndexForArg(const CodeCompleteConsumer::OverloadCandidate &Candidate,
897897
int Arg) {
898-
int NumParams = 0;
899-
if (const auto *F = Candidate.getFunction()) {
900-
NumParams = F->getNumParams();
901-
if (F->isVariadic())
902-
++NumParams;
903-
} else if (auto *T = Candidate.getFunctionType()) {
898+
int NumParams = Candidate.getNumParams();
899+
if (auto *T = Candidate.getFunctionType()) {
904900
if (auto *Proto = T->getAs<FunctionProtoType>()) {
905-
NumParams = Proto->getNumParams();
906901
if (Proto->isVariadic())
907902
++NumParams;
908903
}
@@ -923,7 +918,8 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
923918
void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
924919
OverloadCandidate *Candidates,
925920
unsigned NumCandidates,
926-
SourceLocation OpenParLoc) override {
921+
SourceLocation OpenParLoc,
922+
bool Braced) override {
927923
assert(!OpenParLoc.isInvalid());
928924
SourceManager &SrcMgr = S.getSourceManager();
929925
OpenParLoc = SrcMgr.getFileLoc(OpenParLoc);
@@ -963,8 +959,9 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
963959
paramIndexForArg(Candidate, SigHelp.activeParameter);
964960
}
965961

966-
const auto *CCS = Candidate.CreateSignatureString(
967-
CurrentArg, S, *Allocator, CCTUInfo, true);
962+
const auto *CCS =
963+
Candidate.CreateSignatureString(CurrentArg, S, *Allocator, CCTUInfo,
964+
/*IncludeBriefComment=*/true, Braced);
968965
assert(CCS && "Expected the CodeCompletionString to be non-null");
969966
ScoredSignatures.push_back(processOverloadCandidate(
970967
Candidate, *CCS,
@@ -996,8 +993,7 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
996993
const ScoredSignature &R) {
997994
// Ordering follows:
998995
// - Less number of parameters is better.
999-
// - Function is better than FunctionType which is better than
1000-
// Function Template.
996+
// - Aggregate > Function > FunctionType > FunctionTemplate
1001997
// - High score is better.
1002998
// - Shorter signature is better.
1003999
// - Alphabetically smaller is better.
@@ -1009,15 +1005,22 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
10091005
R.Quality.NumberOfOptionalParameters;
10101006
if (L.Quality.Kind != R.Quality.Kind) {
10111007
using OC = CodeCompleteConsumer::OverloadCandidate;
1012-
switch (L.Quality.Kind) {
1013-
case OC::CK_Function:
1014-
return true;
1015-
case OC::CK_FunctionType:
1016-
return R.Quality.Kind != OC::CK_Function;
1017-
case OC::CK_FunctionTemplate:
1018-
return false;
1019-
}
1020-
llvm_unreachable("Unknown overload candidate type.");
1008+
auto KindPriority = [&](OC::CandidateKind K) {
1009+
switch (K) {
1010+
case OC::CK_Aggregate:
1011+
return 1;
1012+
case OC::CK_Function:
1013+
return 2;
1014+
case OC::CK_FunctionType:
1015+
return 3;
1016+
case OC::CK_FunctionTemplate:
1017+
return 4;
1018+
case OC::CK_Template:
1019+
return 5;
1020+
}
1021+
llvm_unreachable("Unknown overload candidate type.");
1022+
};
1023+
return KindPriority(L.Quality.Kind) < KindPriority(R.Quality.Kind);
10211024
}
10221025
if (L.Signature.label.size() != R.Signature.label.size())
10231026
return L.Signature.label.size() < R.Signature.label.size();
@@ -1162,24 +1165,15 @@ class ParamNameCollector final : public CodeCompleteConsumer {
11621165
void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
11631166
OverloadCandidate *Candidates,
11641167
unsigned NumCandidates,
1165-
SourceLocation OpenParLoc) override {
1168+
SourceLocation OpenParLoc,
1169+
bool Braced) override {
11661170
assert(CurrentArg <= (unsigned)std::numeric_limits<int>::max() &&
11671171
"too many arguments");
11681172

11691173
for (unsigned I = 0; I < NumCandidates; ++I) {
1170-
OverloadCandidate Candidate = Candidates[I];
1171-
auto *Func = Candidate.getFunction();
1172-
if (!Func || Func->getNumParams() <= CurrentArg)
1173-
continue;
1174-
auto *PVD = Func->getParamDecl(CurrentArg);
1175-
if (!PVD)
1176-
continue;
1177-
auto *Ident = PVD->getIdentifier();
1178-
if (!Ident)
1179-
continue;
1180-
auto Name = Ident->getName();
1181-
if (!Name.empty())
1182-
ParamNames.insert(Name.str());
1174+
if (const NamedDecl *ND = Candidates[I].getParamDecl(CurrentArg))
1175+
if (const auto *II = ND->getIdentifier())
1176+
ParamNames.emplace(II->getName());
11831177
}
11841178
}
11851179

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,38 @@ void CommandMangler::adjust(std::vector<std::string> &Cmd,
241241
if (ArchOptCount < 2)
242242
IndicesToDrop.clear();
243243

244+
// In some cases people may try to reuse the command from another file, e.g.
245+
// { File: "foo.h", CommandLine: "clang foo.cpp" }.
246+
// We assume the intent is to parse foo.h the same way as foo.cpp, or as if
247+
// it were being included from foo.cpp.
248+
//
249+
// We're going to rewrite the command to refer to foo.h, and this may change
250+
// its semantics (e.g. by parsing the file as C). If we do this, we should
251+
// use transferCompileCommand to adjust the argv.
252+
// In practice only the extension of the file matters, so do this only when
253+
// it differs.
254+
llvm::StringRef FileExtension = llvm::sys::path::extension(File);
255+
llvm::Optional<std::string> TransferFrom;
256+
auto SawInput = [&](llvm::StringRef Input) {
257+
if (llvm::sys::path::extension(Input) != FileExtension)
258+
TransferFrom.emplace(Input);
259+
};
260+
244261
// Strip all the inputs and `--`. We'll put the input for the requested file
245262
// explicitly at the end of the flags. This ensures modifications done in the
246263
// following steps apply in more cases (like setting -x, which only affects
247264
// inputs that come after it).
248-
for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
265+
for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT)) {
266+
SawInput(Input->getValue(0));
249267
IndicesToDrop.push_back(Input->getIndex());
268+
}
250269
// Anything after `--` is also treated as input, drop them as well.
251270
if (auto *DashDash =
252271
ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) {
253-
Cmd.resize(DashDash->getIndex() + 1); // +1 to account for Cmd[0].
272+
auto DashDashIndex = DashDash->getIndex() + 1; // +1 accounts for Cmd[0]
273+
for (unsigned I = DashDashIndex; I < Cmd.size(); ++I)
274+
SawInput(Cmd[I]);
275+
Cmd.resize(DashDashIndex);
254276
}
255277
llvm::sort(IndicesToDrop);
256278
llvm::for_each(llvm::reverse(IndicesToDrop),
@@ -262,6 +284,24 @@ void CommandMangler::adjust(std::vector<std::string> &Cmd,
262284
Cmd.push_back("--");
263285
Cmd.push_back(File.str());
264286

287+
if (TransferFrom) {
288+
tooling::CompileCommand TransferCmd;
289+
TransferCmd.Filename = std::move(*TransferFrom);
290+
TransferCmd.CommandLine = std::move(Cmd);
291+
TransferCmd = transferCompileCommand(std::move(TransferCmd), File);
292+
Cmd = std::move(TransferCmd.CommandLine);
293+
294+
// Restore the canonical "driver --opts -- filename" form we expect.
295+
// FIXME: This is ugly and coupled. Make transferCompileCommand ensure it?
296+
assert(!Cmd.empty() && Cmd.back() == File);
297+
Cmd.pop_back();
298+
if (!Cmd.empty() && Cmd.back() == "--")
299+
Cmd.pop_back();
300+
assert(!llvm::is_contained(Cmd, "--"));
301+
Cmd.push_back("--");
302+
Cmd.push_back(File.str());
303+
}
304+
265305
for (auto &Edit : Config::current().CompileFlags.Edits)
266306
Edit(Cmd);
267307

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ struct FragmentCompiler {
253253
}
254254

255255
void compile(Fragment::CompileFlagsBlock &&F) {
256+
if (F.Compiler)
257+
Out.Apply.push_back(
258+
[Compiler(std::move(**F.Compiler))](const Params &, Config &C) {
259+
C.CompileFlags.Edits.push_back(
260+
[Compiler](std::vector<std::string> &Args) {
261+
if (!Args.empty())
262+
Args.front() = Compiler;
263+
});
264+
});
265+
256266
if (!F.Remove.empty()) {
257267
auto Remove = std::make_shared<ArgStripper>();
258268
for (auto &A : F.Remove)

clang-tools-extra/clangd/ConfigFragment.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ struct Fragment {
134134
///
135135
/// This section modifies how the compile command is constructed.
136136
struct CompileFlagsBlock {
137+
/// Override the compiler executable name to simulate.
138+
///
139+
/// The name can affect how flags are parsed (clang++ vs clang).
140+
/// If the executable name is in the --query-driver allowlist, then it will
141+
/// be invoked to extract include paths.
142+
///
143+
/// (That this simply replaces argv[0], and may mangle commands that use
144+
/// more complicated drivers like ccache).
145+
llvm::Optional<Located<std::string>> Compiler;
146+
137147
/// List of flags to append to the compile command.
138148
std::vector<Located<std::string>> Add;
139149
/// List of flags to remove from the compile command.

clang-tools-extra/clangd/ConfigYAML.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ class Parser {
9090

9191
void parse(Fragment::CompileFlagsBlock &F, Node &N) {
9292
DictParser Dict("CompileFlags", this);
93+
Dict.handle("Compiler", [&](Node &N) {
94+
if (auto Value = scalarValue(N, "Compiler"))
95+
F.Compiler = std::move(*Value);
96+
});
9397
Dict.handle("Add", [&](Node &N) {
9498
if (auto Values = scalarValues(N))
9599
F.Add = std::move(*Values);

0 commit comments

Comments
 (0)