Skip to content

Commit 9dfc289

Browse files
committed
Merge from 'master' to 'sycl-web' (#496)
CONFLICT (add/add): Merge conflict in clang/test/Driver/sycl.c CONFLICT (content): Merge conflict in clang/lib/Driver/ToolChains/Clang.cpp CONFLICT (content): Merge conflict in clang/include/clang/Driver/Options.td
2 parents d9ce963 + 863d975 commit 9dfc289

File tree

1,335 files changed

+54132
-19256
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,335 files changed

+54132
-19256
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ InitVariablesCheck::InitVariablesCheck(StringRef Name,
2929
MathHeader(Options.get("MathHeader", "math.h")) {}
3030

3131
void InitVariablesCheck::registerMatchers(MatchFinder *Finder) {
32-
Finder->addMatcher(varDecl(unless(hasInitializer(anything())),
33-
unless(isInstantiated()), isLocalVarDecl(),
34-
unless(isStaticLocal()), isDefinition())
35-
.bind("vardecl"),
36-
this);
32+
std::string BadDecl = "badDecl";
33+
Finder->addMatcher(
34+
varDecl(unless(hasInitializer(anything())), unless(isInstantiated()),
35+
isLocalVarDecl(), unless(isStaticLocal()), isDefinition(),
36+
optionally(hasParent(declStmt(hasParent(
37+
cxxForRangeStmt(hasLoopVariable(varDecl().bind(BadDecl))))))),
38+
unless(equalsBoundNode(BadDecl)))
39+
.bind("vardecl"),
40+
this);
3741
}
3842

3943
void InitVariablesCheck::registerPPCallbacks(const SourceManager &SM,

clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ class LLVMModule : public ClangTidyModule {
3636
"llvm-qualified-auto");
3737
CheckFactories.registerCheck<TwineLocalCheck>("llvm-twine-local");
3838
}
39+
40+
ClangTidyOptions getModuleOptions() override {
41+
ClangTidyOptions Options;
42+
Options.CheckOptions["llvm-qualified-auto.AddConstToQualified"] = "0";
43+
return Options;
44+
}
3945
};
4046

4147
// Register the LLVMTidyModule using this statically initialized variable.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ AST_POLYMORPHIC_MATCHER_P(
3838
*Builder = std::move(Result);
3939
return Matched;
4040
}
41+
42+
AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl,
43+
clang::ast_matchers::internal::Matcher<NamedDecl>, DeclMatcher) {
44+
if (const auto *TD = Node.getTemplateName().getAsTemplateDecl())
45+
return DeclMatcher.matches(*TD, Finder, Builder);
46+
return false;
47+
}
4148
} // namespace
4249

4350
// A function that helps to tell whether a TargetDecl in a UsingDecl will be
@@ -56,6 +63,9 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
5663
Finder->addMatcher(loc(enumType(DeclMatcher)), this);
5764
Finder->addMatcher(loc(recordType(DeclMatcher)), this);
5865
Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
66+
Finder->addMatcher(loc(deducedTemplateSpecializationType(
67+
refsToTemplatedDecl(namedDecl().bind("used")))),
68+
this);
5969
Finder->addMatcher(declRefExpr().bind("used"), this);
6070
Finder->addMatcher(callExpr(callee(unresolvedLookupExpr().bind("used"))),
6171
this);

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
2525
return;
2626
Finder->addMatcher(typedefDecl(unless(isInstantiated())).bind("typedef"),
2727
this);
28-
// This matcher used to find structs defined in source code within typedefs.
28+
// This matcher used to find tag declarations in source code within typedefs.
2929
// They appear in the AST just *prior* to the typedefs.
30-
Finder->addMatcher(cxxRecordDecl(unless(isImplicit())).bind("struct"), this);
30+
Finder->addMatcher(tagDecl(unless(isImplicit())).bind("tagdecl"), this);
3131
}
3232

3333
void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
3434
// Match CXXRecordDecl only to store the range of the last non-implicit full
3535
// declaration, to later check whether it's within the typdef itself.
36-
const auto *MatchedCxxRecordDecl =
37-
Result.Nodes.getNodeAs<CXXRecordDecl>("struct");
38-
if (MatchedCxxRecordDecl) {
39-
LastCxxDeclRange = MatchedCxxRecordDecl->getSourceRange();
36+
const auto *MatchedTagDecl = Result.Nodes.getNodeAs<TagDecl>("tagdecl");
37+
if (MatchedTagDecl) {
38+
LastTagDeclRange = MatchedTagDecl->getSourceRange();
4039
return;
4140
}
4241

@@ -70,9 +69,13 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
7069
// consecutive TypedefDecl nodes whose SourceRanges overlap. Each range starts
7170
// at the "typedef" and then continues *across* previous definitions through
7271
// the end of the current TypedefDecl definition.
72+
// But also we need to check that the ranges belong to the same file because
73+
// different files may contain overlapping ranges.
7374
std::string Using = "using ";
7475
if (ReplaceRange.getBegin().isMacroID() ||
75-
ReplaceRange.getBegin() >= LastReplacementEnd) {
76+
(Result.SourceManager->getFileID(ReplaceRange.getBegin()) !=
77+
Result.SourceManager->getFileID(LastReplacementEnd)) ||
78+
(ReplaceRange.getBegin() >= LastReplacementEnd)) {
7679
// This is the first (and possibly the only) TypedefDecl in a typedef. Save
7780
// Type and Name in case we find subsequent TypedefDecl's in this typedef.
7881
FirstTypedefType = Type;
@@ -95,11 +98,12 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
9598

9699
auto Diag = diag(ReplaceRange.getBegin(), UseUsingWarning);
97100

98-
// If typedef contains a full struct/class declaration, extract its full text.
99-
if (LastCxxDeclRange.isValid() && ReplaceRange.fullyContains(LastCxxDeclRange)) {
101+
// If typedef contains a full tag declaration, extract its full text.
102+
if (LastTagDeclRange.isValid() &&
103+
ReplaceRange.fullyContains(LastTagDeclRange)) {
100104
bool Invalid;
101105
Type = std::string(
102-
Lexer::getSourceText(CharSourceRange::getTokenRange(LastCxxDeclRange),
106+
Lexer::getSourceText(CharSourceRange::getTokenRange(LastTagDeclRange),
103107
*Result.SourceManager, getLangOpts(), &Invalid));
104108
if (Invalid)
105109
return;

clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class UseUsingCheck : public ClangTidyCheck {
2323

2424
const bool IgnoreMacros;
2525
SourceLocation LastReplacementEnd;
26-
SourceRange LastCxxDeclRange;
26+
SourceRange LastTagDeclRange;
2727
std::string FirstTypedefType;
2828
std::string FirstTypedefName;
2929

clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ SourceLocation forwardSkipWhitespaceAndComments(SourceLocation Loc,
4242
Loc = Loc.getLocWithOffset(1);
4343

4444
tok::TokenKind TokKind = getTokenKind(Loc, SM, Context);
45-
if (TokKind == tok::NUM_TOKENS || TokKind != tok::comment)
45+
if (TokKind != tok::comment)
4646
return Loc;
4747

4848
// Fast-forward current token.

clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ static const char WarningMessage[] = "do not use 'else' after '%0'";
2727
static const char WarnOnUnfixableStr[] = "WarnOnUnfixable";
2828

2929
const DeclRefExpr *findUsage(const Stmt *Node, int64_t DeclIdentifier) {
30+
if (!Node)
31+
return nullptr;
3032
if (const auto *DeclRef = dyn_cast<DeclRefExpr>(Node)) {
3133
if (DeclRef->getDecl()->getID() == DeclIdentifier) {
3234
return DeclRef;
@@ -44,6 +46,8 @@ const DeclRefExpr *findUsage(const Stmt *Node, int64_t DeclIdentifier) {
4446
const DeclRefExpr *
4547
findUsageRange(const Stmt *Node,
4648
const llvm::iterator_range<int64_t *> &DeclIdentifiers) {
49+
if (!Node)
50+
return nullptr;
4751
if (const auto *DeclRef = dyn_cast<DeclRefExpr>(Node)) {
4852
if (llvm::is_contained(DeclIdentifiers, DeclRef->getDecl()->getID())) {
4953
return DeclRef;

clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ bool isAutoPointerConst(QualType QType) {
102102

103103
} // namespace
104104

105+
void QualifiedAutoCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
106+
Options.store(Opts, "AddConstToQualified", AddConstToQualified);
107+
}
108+
105109
void QualifiedAutoCheck::registerMatchers(MatchFinder *Finder) {
106110
if (!getLangOpts().CPlusPlus11)
107111
return; // Auto deduction not used in 'C or C++03 and earlier', so don't
@@ -142,6 +146,8 @@ void QualifiedAutoCheck::registerMatchers(MatchFinder *Finder) {
142146
hasAnyTemplateArgument(IsBoundToType))))),
143147
"auto"),
144148
this);
149+
if (!AddConstToQualified)
150+
return;
145151
Finder->addMatcher(ExplicitSingleVarDecl(
146152
hasType(pointerType(pointee(autoType()))), "auto_ptr"),
147153
this);
@@ -177,11 +183,9 @@ void QualifiedAutoCheck::check(const MatchFinder::MatchResult &Result) {
177183
bool IsLocalVolatile = Var->getType().isLocalVolatileQualified();
178184
bool IsLocalRestrict = Var->getType().isLocalRestrictQualified();
179185

180-
if (CheckQualifier(IsLocalConst, Qualifier::Const))
181-
return;
182-
if (CheckQualifier(IsLocalVolatile, Qualifier::Volatile))
183-
return;
184-
if (CheckQualifier(IsLocalRestrict, Qualifier::Restrict))
186+
if (CheckQualifier(IsLocalConst, Qualifier::Const) ||
187+
CheckQualifier(IsLocalVolatile, Qualifier::Volatile) ||
188+
CheckQualifier(IsLocalRestrict, Qualifier::Restrict))
185189
return;
186190

187191
// Check for bridging the gap between the asterisk and name.
@@ -214,8 +218,7 @@ void QualifiedAutoCheck::check(const MatchFinder::MatchResult &Result) {
214218
<< (IsLocalRestrict ? "__restrict " : "") << Var->getName() << ReplStr;
215219

216220
for (SourceRange &Range : RemoveQualifiersRange) {
217-
Diag << FixItHint::CreateRemoval(
218-
CharSourceRange::getCharRange(Range.getBegin(), Range.getEnd()));
221+
Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(Range));
219222
}
220223

221224
Diag << FixItHint::CreateReplacement(FixItRange, ReplStr);
@@ -247,22 +250,17 @@ void QualifiedAutoCheck::check(const MatchFinder::MatchResult &Result) {
247250
return;
248251
}
249252

250-
CharSourceRange FixItRange;
251253
if (llvm::Optional<SourceRange> TypeSpec =
252254
getTypeSpecifierLocation(Var, Result)) {
253-
FixItRange = CharSourceRange::getCharRange(*TypeSpec);
254-
if (FixItRange.isInvalid())
255+
if (TypeSpec->isInvalid() || TypeSpec->getBegin().isMacroID() ||
256+
TypeSpec->getEnd().isMacroID())
255257
return;
256-
} else
257-
return;
258-
259-
DiagnosticBuilder Diag =
260-
diag(FixItRange.getBegin(),
261-
"'auto *%0%1%2' can be declared as 'const auto *%0%1%2'")
262-
<< (Var->getType().isLocalConstQualified() ? "const " : "")
263-
<< (Var->getType().isLocalVolatileQualified() ? "volatile " : "")
264-
<< Var->getName();
265-
Diag << FixItHint::CreateReplacement(FixItRange, "const auto *");
258+
SourceLocation InsertPos = TypeSpec->getBegin();
259+
diag(InsertPos, "'auto *%0%1%2' can be declared as 'const auto *%0%1%2'")
260+
<< (Var->getType().isLocalConstQualified() ? "const " : "")
261+
<< (Var->getType().isLocalVolatileQualified() ? "volatile " : "")
262+
<< Var->getName() << FixItHint::CreateInsertion(InsertPos, "const ");
263+
}
266264
return;
267265
}
268266
if (const auto *Var = Result.Nodes.getNodeAs<VarDecl>("auto_ref")) {
@@ -272,20 +270,15 @@ void QualifiedAutoCheck::check(const MatchFinder::MatchResult &Result) {
272270
// Const isnt wrapped in the auto type, so must be declared explicitly.
273271
return;
274272

275-
CharSourceRange FixItRange;
276273
if (llvm::Optional<SourceRange> TypeSpec =
277274
getTypeSpecifierLocation(Var, Result)) {
278-
FixItRange = CharSourceRange::getCharRange(*TypeSpec);
279-
if (FixItRange.isInvalid())
275+
if (TypeSpec->isInvalid() || TypeSpec->getBegin().isMacroID() ||
276+
TypeSpec->getEnd().isMacroID())
280277
return;
281-
} else
282-
return;
283-
284-
DiagnosticBuilder Diag =
285-
diag(FixItRange.getBegin(),
286-
"'auto &%0' can be declared as 'const auto &%0'")
287-
<< Var->getName();
288-
Diag << FixItHint::CreateReplacement(FixItRange, "const auto &");
278+
SourceLocation InsertPos = TypeSpec->getBegin();
279+
diag(InsertPos, "'auto &%0' can be declared as 'const auto &%0'")
280+
<< Var->getName() << FixItHint::CreateInsertion(InsertPos, "const ");
281+
}
289282
return;
290283
}
291284
}

clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ namespace readability {
2424
class QualifiedAutoCheck : public ClangTidyCheck {
2525
public:
2626
QualifiedAutoCheck(StringRef Name, ClangTidyContext *Context)
27-
: ClangTidyCheck(Name, Context) {}
27+
: ClangTidyCheck(Name, Context),
28+
AddConstToQualified(Options.get("AddConstToQualified", true)) {}
29+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
2830
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2931
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
32+
33+
private:
34+
const bool AddConstToQualified;
3035
};
3136

3237
} // namespace readability

clang-tools-extra/clangd/AST.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,5 +473,12 @@ std::string getQualification(ASTContext &Context,
473473
});
474474
}
475475

476+
bool hasUnstableLinkage(const Decl *D) {
477+
// Linkage of a ValueDecl depends on the type.
478+
// If that's not deduced yet, deducing it may change the linkage.
479+
auto *VD = llvm::dyn_cast_or_null<ValueDecl>(D);
480+
return VD && !VD->getType().isNull() && VD->getType()->isUndeducedType();
481+
}
482+
476483
} // namespace clangd
477484
} // namespace clang

clang-tools-extra/clangd/AST.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@ std::string getQualification(ASTContext &Context,
148148
const NamedDecl *ND,
149149
llvm::ArrayRef<std::string> VisibleNamespaces);
150150

151+
/// Whether we must avoid computing linkage for D during code completion.
152+
/// Clang aggressively caches linkage computation, which is stable after the AST
153+
/// is built. Unfortunately the AST is incomplete during code completion, so
154+
/// linkage may still change.
155+
///
156+
/// Example: `auto x = []{^}` at file scope.
157+
/// During code completion, the initializer for x hasn't been parsed yet.
158+
/// x has type `undeduced auto`, and external linkage.
159+
/// If we compute linkage at this point, the external linkage will be cached.
160+
///
161+
/// After code completion the initializer is attached, and x has a lambda type.
162+
/// This means x has "unique external" linkage. If we computed linkage above,
163+
/// the cached value is incorrect. (clang catches this with an assertion).
164+
bool hasUnstableLinkage(const Decl *D);
165+
151166
} // namespace clangd
152167
} // namespace clang
153168

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,22 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
106106

107107
ClangdServer::Options ClangdServer::optsForTest() {
108108
ClangdServer::Options Opts;
109-
Opts.UpdateDebounce = std::chrono::steady_clock::duration::zero(); // Faster!
109+
Opts.UpdateDebounce = DebouncePolicy::fixed(/*zero*/ {});
110110
Opts.StorePreamblesInMemory = true;
111111
Opts.AsyncThreadsCount = 4; // Consistent!
112112
Opts.SemanticHighlighting = true;
113113
return Opts;
114114
}
115115

116+
ClangdServer::Options::operator TUScheduler::Options() const {
117+
TUScheduler::Options Opts;
118+
Opts.AsyncThreadsCount = AsyncThreadsCount;
119+
Opts.RetentionPolicy = RetentionPolicy;
120+
Opts.StorePreamblesInMemory = StorePreamblesInMemory;
121+
Opts.UpdateDebounce = UpdateDebounce;
122+
return Opts;
123+
}
124+
116125
ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
117126
const FileSystemProvider &FSProvider,
118127
const Options &Opts, Callbacks *Callbacks)
@@ -129,10 +138,10 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
129138
// is parsed.
130139
// FIXME(ioeric): this can be slow and we may be able to index on less
131140
// critical paths.
132-
WorkScheduler(CDB, Opts.AsyncThreadsCount, Opts.StorePreamblesInMemory,
133-
std::make_unique<UpdateIndexCallbacks>(
134-
DynamicIdx.get(), Callbacks, Opts.SemanticHighlighting),
135-
Opts.UpdateDebounce, Opts.RetentionPolicy) {
141+
WorkScheduler(
142+
CDB, TUScheduler::Options(Opts),
143+
std::make_unique<UpdateIndexCallbacks>(DynamicIdx.get(), Callbacks,
144+
Opts.SemanticHighlighting)) {
136145
// Adds an index to the stack, at higher priority than existing indexes.
137146
auto AddIndex = [&](SymbolIndex *Idx) {
138147
if (this->Index != nullptr) {

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ class ClangdServer {
130130
llvm::Optional<std::string> ResourceDir = llvm::None;
131131

132132
/// Time to wait after a new file version before computing diagnostics.
133-
std::chrono::steady_clock::duration UpdateDebounce =
134-
std::chrono::milliseconds(500);
133+
DebouncePolicy UpdateDebounce =
134+
DebouncePolicy::fixed(std::chrono::milliseconds(500));
135135

136136
bool SuggestMissingIncludes = false;
137137

@@ -149,6 +149,8 @@ class ClangdServer {
149149
std::function<bool(const Tweak &)> TweakFilter = [](const Tweak &T) {
150150
return !T.hidden(); // only enable non-hidden tweaks.
151151
};
152+
153+
explicit operator TUScheduler::Options() const;
152154
};
153155
// Sensible default options for use in tests.
154156
// Features like indexing must be enabled if desired.

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,9 @@ llvm::Optional<SymbolID> getSymbolID(const CodeCompletionResult &R,
489489
switch (R.Kind) {
490490
case CodeCompletionResult::RK_Declaration:
491491
case CodeCompletionResult::RK_Pattern: {
492+
// Computing USR caches linkage, which may change after code completion.
493+
if (hasUnstableLinkage(R.Declaration))
494+
return llvm::None;
492495
return clang::clangd::getSymbolID(R.Declaration);
493496
}
494497
case CodeCompletionResult::RK_Macro:
@@ -1001,10 +1004,12 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
10011004
ScoredSignature Result;
10021005
Result.Signature = std::move(Signature);
10031006
Result.Quality = Signal;
1004-
Result.IDForDoc =
1005-
Result.Signature.documentation.empty() && Candidate.getFunction()
1006-
? clangd::getSymbolID(Candidate.getFunction())
1007-
: None;
1007+
const FunctionDecl *Func = Candidate.getFunction();
1008+
if (Func && Result.Signature.documentation.empty()) {
1009+
// Computing USR caches linkage, which may change after code completion.
1010+
if (!hasUnstableLinkage(Func))
1011+
Result.IDForDoc = clangd::getSymbolID(Func);
1012+
}
10081013
return Result;
10091014
}
10101015

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ struct TargetFinder {
379379
Outer.add(TT->getAsTagDecl(), Flags);
380380
}
381381

382+
void VisitElaboratedType(const ElaboratedType *ET) {
383+
Outer.add(ET->desugar(), Flags);
384+
}
385+
382386
void VisitInjectedClassNameType(const InjectedClassNameType *ICNT) {
383387
Outer.add(ICNT->getDecl(), Flags);
384388
}

0 commit comments

Comments
 (0)