Skip to content

Commit b450017

Browse files
committed
Merge from 'main' to 'sycl-web' (1 commits)
2 parents 7b77c52 + d2cc6c2 commit b450017

File tree

620 files changed

+11288
-15066
lines changed

Some content is hidden

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

620 files changed

+11288
-15066
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ void VirtualClassDestructorCheck::check(
173173
"destructor of %0 is private and prevents using the type")
174174
<< MatchedClassOrStruct;
175175
diag(MatchedClassOrStruct->getLocation(),
176-
/*FixDescription=*/"make it public and virtual", DiagnosticIDs::Note)
176+
/*Description=*/"make it public and virtual", DiagnosticIDs::Note)
177177
<< changePrivateDestructorVisibilityTo(
178178
"public", *Destructor, *Result.SourceManager, getLangOpts());
179179
diag(MatchedClassOrStruct->getLocation(),
180-
/*FixDescription=*/"make it protected", DiagnosticIDs::Note)
180+
/*Description=*/"make it protected", DiagnosticIDs::Note)
181181
<< changePrivateDestructorVisibilityTo(
182182
"protected", *Destructor, *Result.SourceManager, getLangOpts());
183183

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void DefinitionsInHeadersCheck::check(const MatchFinder::MatchResult &Result) {
130130
// inline is not allowed for main function.
131131
if (FD->isMain())
132132
return;
133-
diag(FD->getLocation(), /*FixDescription=*/"make as 'inline'",
133+
diag(FD->getLocation(), /*Description=*/"make as 'inline'",
134134
DiagnosticIDs::Note)
135135
<< FixItHint::CreateInsertion(FD->getInnerLocStart(), "inline ");
136136
} else if (const auto *VD = dyn_cast<VarDecl>(ND)) {

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ struct CodeCompletionBuilder {
420420
SetDoc(C.IndexResult->Documentation);
421421
} else if (C.SemaResult) {
422422
const auto DocComment = getDocComment(*ASTCtx, *C.SemaResult,
423-
/*CommentsFromHeader=*/false);
423+
/*CommentsFromHeaders=*/false);
424424
SetDoc(formatDocumentation(*SemaCCS, DocComment));
425425
}
426426
}
@@ -959,9 +959,9 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
959959
paramIndexForArg(Candidate, SigHelp.activeParameter);
960960
}
961961

962-
const auto *CCS =
963-
Candidate.CreateSignatureString(CurrentArg, S, *Allocator, CCTUInfo,
964-
/*IncludeBriefComment=*/true, Braced);
962+
const auto *CCS = Candidate.CreateSignatureString(
963+
CurrentArg, S, *Allocator, CCTUInfo,
964+
/*IncludeBriefComments=*/true, Braced);
965965
assert(CCS && "Expected the CodeCompletionString to be non-null");
966966
ScoredSignatures.push_back(processOverloadCandidate(
967967
Candidate, *CCS,

clang-tools-extra/clangd/Config.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ struct Config {
122122
/// Whether hover show a.k.a type.
123123
bool ShowAKA = false;
124124
} Hover;
125+
126+
struct {
127+
/// If false, inlay hints are completely disabled.
128+
bool Enabled = true;
129+
130+
// Whether specific categories of hints are enabled.
131+
bool Parameters = true;
132+
bool DeducedTypes = true;
133+
} InlayHints;
125134
};
126135

127136
} // namespace clangd

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ struct FragmentCompiler {
197197
compile(std::move(F.Diagnostics));
198198
compile(std::move(F.Completion));
199199
compile(std::move(F.Hover));
200+
compile(std::move(F.InlayHints));
200201
}
201202

202203
void compile(Fragment::IfBlock &&F) {
@@ -526,6 +527,22 @@ struct FragmentCompiler {
526527
}
527528
}
528529

530+
void compile(Fragment::InlayHintsBlock &&F) {
531+
if (F.Enabled)
532+
Out.Apply.push_back([Value(**F.Enabled)](const Params &, Config &C) {
533+
C.InlayHints.Enabled = Value;
534+
});
535+
if (F.ParameterNames)
536+
Out.Apply.push_back(
537+
[Value(**F.ParameterNames)](const Params &, Config &C) {
538+
C.InlayHints.Parameters = Value;
539+
});
540+
if (F.DeducedTypes)
541+
Out.Apply.push_back([Value(**F.DeducedTypes)](const Params &, Config &C) {
542+
C.InlayHints.DeducedTypes = Value;
543+
});
544+
}
545+
529546
constexpr static llvm::SourceMgr::DiagKind Error = llvm::SourceMgr::DK_Error;
530547
constexpr static llvm::SourceMgr::DiagKind Warning =
531548
llvm::SourceMgr::DK_Warning;

clang-tools-extra/clangd/ConfigFragment.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ struct Fragment {
283283
llvm::Optional<Located<bool>> ShowAKA;
284284
};
285285
HoverBlock Hover;
286+
287+
/// Configures labels shown inline with the code.
288+
struct InlayHintsBlock {
289+
/// Enables/disables the inlay-hints feature.
290+
llvm::Optional<Located<bool>> Enabled;
291+
292+
/// Show parameter names before function arguments.
293+
llvm::Optional<Located<bool>> ParameterNames;
294+
/// Show deduced types for `auto`.
295+
llvm::Optional<Located<bool>> DeducedTypes;
296+
};
297+
InlayHintsBlock InlayHints;
286298
};
287299

288300
} // namespace config

clang-tools-extra/clangd/ConfigYAML.cpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Parser {
6666
Dict.handle("Diagnostics", [&](Node &N) { parse(F.Diagnostics, N); });
6767
Dict.handle("Completion", [&](Node &N) { parse(F.Completion, N); });
6868
Dict.handle("Hover", [&](Node &N) { parse(F.Hover, N); });
69+
Dict.handle("InlayHints", [&](Node &N) { parse(F.InlayHints, N); });
6970
Dict.parse(N);
7071
return !(N.failed() || HadError);
7172
}
@@ -199,25 +200,34 @@ class Parser {
199200
void parse(Fragment::CompletionBlock &F, Node &N) {
200201
DictParser Dict("Completion", this);
201202
Dict.handle("AllScopes", [&](Node &N) {
202-
if (auto Value = scalarValue(N, "AllScopes")) {
203-
if (auto AllScopes = llvm::yaml::parseBool(**Value))
204-
F.AllScopes = *AllScopes;
205-
else
206-
warning("AllScopes should be a boolean", N);
207-
}
203+
if (auto AllScopes = boolValue(N, "AllScopes"))
204+
F.AllScopes = *AllScopes;
208205
});
209206
Dict.parse(N);
210207
}
211208

212209
void parse(Fragment::HoverBlock &F, Node &N) {
213210
DictParser Dict("Hover", this);
214211
Dict.handle("ShowAKA", [&](Node &N) {
215-
if (auto Value = scalarValue(N, "ShowAKA")) {
216-
if (auto ShowAKA = llvm::yaml::parseBool(**Value))
217-
F.ShowAKA = *ShowAKA;
218-
else
219-
warning("ShowAKA should be a boolean", N);
220-
}
212+
if (auto ShowAKA = boolValue(N, "ShowAKA"))
213+
F.ShowAKA = *ShowAKA;
214+
});
215+
Dict.parse(N);
216+
}
217+
218+
void parse(Fragment::InlayHintsBlock &F, Node &N) {
219+
DictParser Dict("InlayHints", this);
220+
Dict.handle("Enabled", [&](Node &N) {
221+
if (auto Value = boolValue(N, "Enabled"))
222+
F.Enabled = *Value;
223+
});
224+
Dict.handle("ParameterNames", [&](Node &N) {
225+
if (auto Value = boolValue(N, "ParameterNames"))
226+
F.ParameterNames = *Value;
227+
});
228+
Dict.handle("DeducedTypes", [&](Node &N) {
229+
if (auto Value = boolValue(N, "DeducedTypes"))
230+
F.DeducedTypes = *Value;
221231
});
222232
Dict.parse(N);
223233
}
@@ -331,6 +341,16 @@ class Parser {
331341
return llvm::None;
332342
}
333343

344+
llvm::Optional<Located<bool>> boolValue(Node &N, llvm::StringRef Desc) {
345+
if (auto Scalar = scalarValue(N, Desc)) {
346+
if (auto Bool = llvm::yaml::parseBool(**Scalar))
347+
return Located<bool>(*Bool, Scalar->Range);
348+
else
349+
warning(Desc + " should be a boolean", N);
350+
}
351+
return llvm::None;
352+
}
353+
334354
// Try to parse a list of single scalar values, or just a single value.
335355
llvm::Optional<std::vector<Located<std::string>>> scalarValues(Node &N) {
336356
std::vector<Located<std::string>> Result;

clang-tools-extra/clangd/Diagnostics.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Diag &D) {
419419
OS << Sep << Fix;
420420
Sep = ", ";
421421
}
422+
OS << "}";
422423
}
423424
return OS;
424425
}

clang-tools-extra/clangd/IncludeFixer.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
193193
case diag::err_no_member_suggest:
194194
case diag::err_no_member_template:
195195
case diag::err_no_member_template_suggest:
196+
case diag::warn_implicit_function_decl:
197+
case diag::ext_implicit_function_decl:
198+
case diag::err_opencl_implicit_function_decl:
199+
dlog("Unresolved name at {0}, last typo was {1}",
200+
Info.getLocation().printToString(Info.getSourceManager()),
201+
LastUnresolvedName
202+
? LastUnresolvedName->Loc.printToString(Info.getSourceManager())
203+
: "none");
196204
if (LastUnresolvedName) {
197205
// Try to fix unresolved name caused by missing declaration.
198206
// E.g.
@@ -205,8 +213,7 @@ std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
205213
// UnresolvedName
206214
// We only attempt to recover a diagnostic if it has the same location as
207215
// the last seen unresolved name.
208-
if (DiagLevel >= DiagnosticsEngine::Error &&
209-
LastUnresolvedName->Loc == Info.getLocation())
216+
if (LastUnresolvedName->Loc == Info.getLocation())
210217
return fixUnresolvedName();
211218
}
212219
break;
@@ -481,6 +488,7 @@ class IncludeFixer::UnresolvedNameRecorder : public ExternalSemaSource {
481488
CorrectionCandidateCallback &CCC,
482489
DeclContext *MemberContext, bool EnteringContext,
483490
const ObjCObjectPointerType *OPT) override {
491+
dlog("CorrectTypo: {0}", Typo.getAsString());
484492
assert(SemaPtr && "Sema must have been set.");
485493
if (SemaPtr->isSFINAEContext())
486494
return TypoCorrection();

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88
#include "InlayHints.h"
9+
#include "Config.h"
910
#include "HeuristicResolver.h"
1011
#include "ParsedAST.h"
1112
#include "clang/AST/DeclarationName.h"
@@ -23,8 +24,8 @@ enum class HintSide { Left, Right };
2324
class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
2425
public:
2526
InlayHintVisitor(std::vector<InlayHint> &Results, ParsedAST &AST,
26-
llvm::Optional<Range> RestrictRange)
27-
: Results(Results), AST(AST.getASTContext()),
27+
const Config &Cfg, llvm::Optional<Range> RestrictRange)
28+
: Results(Results), AST(AST.getASTContext()), Cfg(Cfg),
2829
RestrictRange(std::move(RestrictRange)),
2930
MainFileID(AST.getSourceManager().getMainFileID()),
3031
Resolver(AST.getHeuristicResolver()),
@@ -65,6 +66,9 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
6566
}
6667

6768
bool VisitCallExpr(CallExpr *E) {
69+
if (!Cfg.InlayHints.Parameters)
70+
return true;
71+
6872
// Do not show parameter hints for operator calls written using operator
6973
// syntax or user-defined literals. (Among other reasons, the resulting
7074
// hints can look awkard, e.g. the expression can itself be a function
@@ -135,7 +139,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
135139
// the entire argument list likely appears in the main file and can be hinted.
136140
void processCall(SourceLocation Anchor, const FunctionDecl *Callee,
137141
llvm::ArrayRef<const Expr *const> Args) {
138-
if (Args.size() == 0 || !Callee)
142+
if (!Cfg.InlayHints.Parameters || Args.size() == 0 || !Callee)
139143
return;
140144

141145
// If the anchor location comes from a macro defintion, there's nowhere to
@@ -323,6 +327,23 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
323327
void addInlayHint(SourceRange R, HintSide Side, InlayHintKind Kind,
324328
llvm::StringRef Prefix, llvm::StringRef Label,
325329
llvm::StringRef Suffix) {
330+
// We shouldn't get as far as adding a hint if the category is disabled.
331+
// We'd like to disable as much of the analysis as possible above instead.
332+
// Assert in debug mode but add a dynamic check in production.
333+
assert(Cfg.InlayHints.Enabled && "Shouldn't get here if disabled!");
334+
switch (Kind) {
335+
#define CHECK_KIND(Enumerator, ConfigProperty) \
336+
case InlayHintKind::Enumerator: \
337+
assert(Cfg.InlayHints.ConfigProperty && \
338+
"Shouldn't get here if kind is disabled!"); \
339+
if (!Cfg.InlayHints.ConfigProperty) \
340+
return; \
341+
break
342+
CHECK_KIND(ParameterHint, Parameters);
343+
CHECK_KIND(TypeHint, DeducedTypes);
344+
#undef CHECK_KIND
345+
}
346+
326347
auto FileRange =
327348
toHalfOpenFileRange(AST.getSourceManager(), AST.getLangOpts(), R);
328349
if (!FileRange)
@@ -348,8 +369,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
348369

349370
void addTypeHint(SourceRange R, QualType T, llvm::StringRef Prefix,
350371
const PrintingPolicy &Policy) {
351-
// Do not print useless "NULL TYPE" hint.
352-
if (!T.getTypePtrOrNull())
372+
if (!Cfg.InlayHints.DeducedTypes || T.isNull())
353373
return;
354374

355375
std::string TypeName = T.getAsString(Policy);
@@ -360,6 +380,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
360380

361381
std::vector<InlayHint> &Results;
362382
ASTContext &AST;
383+
const Config &Cfg;
363384
llvm::Optional<Range> RestrictRange;
364385
FileID MainFileID;
365386
StringRef MainFileBuf;
@@ -381,7 +402,10 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
381402
std::vector<InlayHint> inlayHints(ParsedAST &AST,
382403
llvm::Optional<Range> RestrictRange) {
383404
std::vector<InlayHint> Results;
384-
InlayHintVisitor Visitor(Results, AST, std::move(RestrictRange));
405+
const auto &Cfg = Config::current();
406+
if (!Cfg.InlayHints.Enabled)
407+
return Results;
408+
InlayHintVisitor Visitor(Results, AST, Cfg, std::move(RestrictRange));
385409
Visitor.TraverseAST(AST.getASTContext());
386410

387411
// De-duplicate hints. Duplicates can sometimes occur due to e.g. explicit

0 commit comments

Comments
 (0)