Skip to content

Commit 34dd7d2

Browse files
committed
Merge from 'master' to 'sycl-web' (#2)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaChecking.cpp
2 parents e0d64f5 + c93112d commit 34dd7d2

File tree

2,120 files changed

+75617
-30952
lines changed

Some content is hidden

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

2,120 files changed

+75617
-30952
lines changed

clang-tools-extra/clang-tidy/add_new_check.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def add_release_notes(module_path, module, check_name):
221221

222222
lineMatcher = re.compile('New checks')
223223
nextSectionMatcher = re.compile('New check aliases')
224-
checkerMatcher = re.compile('- New :doc:`(.*)')
224+
checkMatcher = re.compile('- New :doc:`(.*)')
225225

226226
print('Updating %s...' % filename)
227227
with open(filename, 'w') as f:
@@ -234,10 +234,10 @@ def add_release_notes(module_path, module, check_name):
234234
if not note_added:
235235
match = lineMatcher.match(line)
236236
match_next = nextSectionMatcher.match(line)
237-
match_checker = checkerMatcher.match(line)
238-
if match_checker:
239-
last_checker = match_checker.group(1)
240-
if last_checker > check_name_dashes:
237+
match_check = checkMatcher.match(line)
238+
if match_check:
239+
last_check = match_check.group(1)
240+
if last_check > check_name_dashes:
241241
add_note_here = True
242242

243243
if match_next:

clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <algorithm>
1515
#include <cctype>
1616

17+
// FixItHint
18+
1719
using namespace clang::ast_matchers;
1820

1921
namespace clang {

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ void NoRecursionCheck::handleSCC(ArrayRef<CallGraphNode *> SCC) {
204204

205205
// First of all, call out every stongly connected function.
206206
for (CallGraphNode *N : SCC) {
207-
Decl *D = N->getDecl();
208-
diag(D->getLocation(), "function %0 is within a recursive call chain")
209-
<< cast<NamedDecl>(D);
207+
FunctionDecl *D = N->getDefinition();
208+
diag(D->getLocation(), "function %0 is within a recursive call chain") << D;
210209
}
211210

212211
// Now, SCC only tells us about strongly connected function declarations in
@@ -228,13 +227,13 @@ void NoRecursionCheck::handleSCC(ArrayRef<CallGraphNode *> SCC) {
228227
assert(CyclicCallStack.size() >= 2 && "Cycle requires at least 2 frames");
229228

230229
// Which function we decided to be the entry point that lead to the recursion?
231-
Decl *CycleEntryFn = CyclicCallStack.front().Callee->getDecl();
230+
FunctionDecl *CycleEntryFn = CyclicCallStack.front().Callee->getDefinition();
232231
// And now, for ease of understanding, let's print the call sequence that
233232
// forms the cycle in question.
234233
diag(CycleEntryFn->getLocation(),
235234
"example recursive call chain, starting from function %0",
236235
DiagnosticIDs::Note)
237-
<< cast<NamedDecl>(CycleEntryFn);
236+
<< CycleEntryFn;
238237
for (int CurFrame = 1, NumFrames = CyclicCallStack.size();
239238
CurFrame != NumFrames; ++CurFrame) {
240239
CallGraphNode::CallRecord PrevNode = CyclicCallStack[CurFrame - 1];

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ void UnconventionalAssignOperatorCheck::registerMatchers(
6060
anyOf(unaryOperator(hasOperatorName("*"), hasUnaryOperand(cxxThisExpr())),
6161
cxxOperatorCallExpr(argumentCountIs(1),
6262
callee(unresolvedLookupExpr()),
63-
hasArgument(0, cxxThisExpr())))))));
63+
hasArgument(0, cxxThisExpr())),
64+
cxxOperatorCallExpr(
65+
hasOverloadedOperatorName("="),
66+
hasArgument(
67+
0, unaryOperator(hasOperatorName("*"),
68+
hasUnaryOperand(cxxThisExpr())))))))));
6469
const auto IsGoodAssign = cxxMethodDecl(IsAssign, HasGoodReturnType);
6570

6671
Finder->addMatcher(returnStmt(IsBadReturnStatement, forFunction(IsGoodAssign))

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#define DEBUG_TYPE "clang-tidy"
2020

21+
// FixItHint
22+
2123
using namespace clang::ast_matchers;
2224

2325
namespace clang {

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

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,55 @@ formatDereference(const ast_matchers::MatchFinder::MatchResult &Result,
6161
return (llvm::Twine("*") + Text).str();
6262
}
6363

64+
// Trying to get CallExpr in which CxxConstructExpr is called.
65+
static const clang::CallExpr *
66+
tryGetCallExprAncestorForCxxConstructExpr(const Expr *TheExpr,
67+
ASTContext &Context) {
68+
// We skip nodes such as CXXBindTemporaryExpr, MaterializeTemporaryExpr.
69+
for (ast_type_traits::DynTypedNode DynParent : Context.getParents(*TheExpr)) {
70+
if (const auto *Parent = DynParent.get<Expr>()) {
71+
if (const auto *TheCallExpr = dyn_cast<CallExpr>(Parent))
72+
return TheCallExpr;
73+
74+
if (const clang::CallExpr *TheCallExpr =
75+
tryGetCallExprAncestorForCxxConstructExpr(Parent, Context))
76+
return TheCallExpr;
77+
}
78+
}
79+
80+
return nullptr;
81+
}
82+
83+
// Check that ParamDecl of CallExprDecl has rvalue type.
84+
static bool checkParamDeclOfAncestorCallExprHasRValueRefType(
85+
const Expr *TheCxxConstructExpr, ASTContext &Context) {
86+
if (const clang::CallExpr *TheCallExpr =
87+
tryGetCallExprAncestorForCxxConstructExpr(TheCxxConstructExpr,
88+
Context)) {
89+
for (unsigned i = 0; i < TheCallExpr->getNumArgs(); ++i) {
90+
const Expr *Arg = TheCallExpr->getArg(i);
91+
if (Arg->getSourceRange() == TheCxxConstructExpr->getSourceRange()) {
92+
if (const auto *TheCallExprFuncProto =
93+
TheCallExpr->getCallee()
94+
->getType()
95+
->getPointeeType()
96+
->getAs<FunctionProtoType>()) {
97+
if (TheCallExprFuncProto->getParamType(i)->isRValueReferenceType())
98+
return true;
99+
}
100+
}
101+
}
102+
}
103+
104+
return false;
105+
}
106+
107+
AST_MATCHER(CXXConstructExpr,
108+
matchedParamDeclOfAncestorCallExprHasRValueRefType) {
109+
return checkParamDeclOfAncestorCallExprHasRValueRefType(
110+
&Node, Finder->getASTContext());
111+
}
112+
64113
} // end namespace
65114

66115
void RedundantStringCStrCheck::registerMatchers(
@@ -95,9 +144,13 @@ void RedundantStringCStrCheck::registerMatchers(
95144
.bind("call");
96145

97146
// Detect redundant 'c_str()' calls through a string constructor.
98-
Finder->addMatcher(cxxConstructExpr(StringConstructorExpr,
99-
hasArgument(0, StringCStrCallExpr)),
100-
this);
147+
// If CxxConstructExpr is the part of some CallExpr we need to
148+
// check that matched ParamDecl of the ancestor CallExpr is not rvalue.
149+
Finder->addMatcher(
150+
cxxConstructExpr(
151+
StringConstructorExpr, hasArgument(0, StringCStrCallExpr),
152+
unless(matchedParamDeclOfAncestorCallExprHasRValueRefType())),
153+
this);
101154

102155
// Detect: 's == str.c_str()' -> 's == str'
103156
Finder->addMatcher(

clang-tools-extra/clang-tidy/rename_check.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,45 @@ def add_release_notes(clang_tidy_path, old_check_name, new_check_name):
169169
with open(filename, 'r') as f:
170170
lines = f.readlines()
171171

172+
lineMatcher = re.compile('Renamed checks')
173+
nextSectionMatcher = re.compile('Improvements to include-fixer')
174+
checkMatcher = re.compile('- The \'(.*)')
175+
172176
print('Updating %s...' % filename)
173177
with open(filename, 'wb') as f:
174178
note_added = False
175179
header_found = False
180+
next_header_found = False
181+
add_note_here = False
176182

177183
for line in lines:
178184
if not note_added:
179-
match = re.search('Renamed checks', line)
185+
match = lineMatcher.match(line)
186+
match_next = nextSectionMatcher.match(line)
187+
match_check = checkMatcher.match(line)
188+
if match_check:
189+
last_check = match_check.group(1)
190+
if last_check > old_check_name:
191+
add_note_here = True
192+
193+
if match_next:
194+
next_header_found = True
195+
add_note_here = True
196+
180197
if match:
181198
header_found = True
182-
elif header_found:
199+
f.write(line)
200+
continue
201+
202+
if line.startswith('^^^^'):
203+
f.write(line)
204+
continue
205+
206+
if header_found and add_note_here:
183207
if not line.startswith('^^^^'):
184-
f.write("""
185-
- The '%s' check was renamed to :doc:`%s
208+
f.write("""- The '%s' check was renamed to :doc:`%s
186209
<clang-tidy/checks/%s>`
210+
187211
""" % (old_check_name, new_check_name, new_check_name))
188212
note_added = True
189213

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
559559
{"codeActionProvider", std::move(CodeActionProvider)},
560560
{"completionProvider",
561561
llvm::json::Object{
562+
{"allCommitCharacters", " \t()[]{}<>:;,+-/*%^&#?.=\"'|"},
562563
{"resolveProvider", false},
563564
// We do extra checks for '>' and ':' in completion to only
564565
// trigger on '->' and '::'.

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,26 @@ void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
395395
WorkScheduler.runWithAST("Rename", File, std::move(Action));
396396
}
397397

398-
static llvm::Expected<Tweak::Selection>
398+
// May generate several candidate selections, due to SelectionTree ambiguity.
399+
// vector of pointers because GCC doesn't like non-copyable Selection.
400+
static llvm::Expected<std::vector<std::unique_ptr<Tweak::Selection>>>
399401
tweakSelection(const Range &Sel, const InputsAndAST &AST) {
400402
auto Begin = positionToOffset(AST.Inputs.Contents, Sel.start);
401403
if (!Begin)
402404
return Begin.takeError();
403405
auto End = positionToOffset(AST.Inputs.Contents, Sel.end);
404406
if (!End)
405407
return End.takeError();
406-
return Tweak::Selection(AST.Inputs.Index, AST.AST, *Begin, *End);
408+
std::vector<std::unique_ptr<Tweak::Selection>> Result;
409+
SelectionTree::createEach(
410+
AST.AST.getASTContext(), AST.AST.getTokens(), *Begin, *End,
411+
[&](SelectionTree T) {
412+
Result.push_back(std::make_unique<Tweak::Selection>(
413+
AST.Inputs.Index, AST.AST, *Begin, *End, std::move(T)));
414+
return false;
415+
});
416+
assert(!Result.empty() && "Expected at least one SelectionTree");
417+
return std::move(Result);
407418
}
408419

409420
void ClangdServer::enumerateTweaks(PathRef File, Range Sel,
@@ -412,12 +423,21 @@ void ClangdServer::enumerateTweaks(PathRef File, Range Sel,
412423
this](Expected<InputsAndAST> InpAST) mutable {
413424
if (!InpAST)
414425
return CB(InpAST.takeError());
415-
auto Selection = tweakSelection(Sel, *InpAST);
416-
if (!Selection)
417-
return CB(Selection.takeError());
426+
auto Selections = tweakSelection(Sel, *InpAST);
427+
if (!Selections)
428+
return CB(Selections.takeError());
418429
std::vector<TweakRef> Res;
419-
for (auto &T : prepareTweaks(*Selection, TweakFilter))
420-
Res.push_back({T->id(), T->title(), T->intent()});
430+
// Don't allow a tweak to fire more than once across ambiguous selections.
431+
llvm::DenseSet<llvm::StringRef> PreparedTweaks;
432+
auto Filter = [&](const Tweak &T) {
433+
return TweakFilter(T) && !PreparedTweaks.count(T.id());
434+
};
435+
for (const auto &Sel : *Selections) {
436+
for (auto &T : prepareTweaks(*Sel, Filter)) {
437+
Res.push_back({T->id(), T->title(), T->intent()});
438+
PreparedTweaks.insert(T->id());
439+
}
440+
}
421441

422442
CB(std::move(Res));
423443
};
@@ -432,21 +452,30 @@ void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
432452
FS = FSProvider.getFileSystem()](Expected<InputsAndAST> InpAST) mutable {
433453
if (!InpAST)
434454
return CB(InpAST.takeError());
435-
auto Selection = tweakSelection(Sel, *InpAST);
436-
if (!Selection)
437-
return CB(Selection.takeError());
438-
auto A = prepareTweak(TweakID, *Selection);
439-
if (!A)
440-
return CB(A.takeError());
441-
auto Effect = (*A)->apply(*Selection);
442-
if (!Effect)
443-
return CB(Effect.takeError());
444-
for (auto &It : Effect->ApplyEdits) {
445-
Edit &E = It.second;
446-
format::FormatStyle Style =
447-
getFormatStyleForFile(File, E.InitialCode, FS.get());
448-
if (llvm::Error Err = reformatEdit(E, Style))
449-
elog("Failed to format {0}: {1}", It.first(), std::move(Err));
455+
auto Selections = tweakSelection(Sel, *InpAST);
456+
if (!Selections)
457+
return CB(Selections.takeError());
458+
llvm::Optional<llvm::Expected<Tweak::Effect>> Effect;
459+
// Try each selection, take the first one that prepare()s.
460+
// If they all fail, Effect will hold get the last error.
461+
for (const auto &Selection : *Selections) {
462+
auto T = prepareTweak(TweakID, *Selection);
463+
if (T) {
464+
Effect = (*T)->apply(*Selection);
465+
break;
466+
}
467+
Effect = T.takeError();
468+
}
469+
assert(Effect.hasValue() && "Expected at least one selection");
470+
if (*Effect) {
471+
// Tweaks don't apply clang-format, do that centrally here.
472+
for (auto &It : (*Effect)->ApplyEdits) {
473+
Edit &E = It.second;
474+
format::FormatStyle Style =
475+
getFormatStyleForFile(File, E.InitialCode, FS.get());
476+
if (llvm::Error Err = reformatEdit(E, Style))
477+
elog("Failed to format {0}: {1}", It.first(), std::move(Err));
478+
}
450479
}
451480
return CB(std::move(*Effect));
452481
};

clang-tools-extra/clangd/ClangdServer.h

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

132132
/// Time to wait after a new file version before computing diagnostics.
133-
DebouncePolicy UpdateDebounce =
134-
DebouncePolicy::fixed(std::chrono::milliseconds(500));
133+
DebouncePolicy UpdateDebounce = DebouncePolicy{
134+
/*Min=*/std::chrono::milliseconds(50),
135+
/*Max=*/std::chrono::milliseconds(500),
136+
/*RebuildRatio=*/1,
137+
};
135138

136139
bool SuggestMissingIncludes = false;
137140

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "clang/Basic/LangOptions.h"
3232
#include "clang/Basic/OperatorKinds.h"
3333
#include "clang/Basic/SourceLocation.h"
34+
#include "clang/Basic/Specifiers.h"
3435
#include "llvm/ADT/STLExtras.h"
3536
#include "llvm/ADT/SmallVector.h"
3637
#include "llvm/Support/Casting.h"
@@ -139,7 +140,14 @@ const Type *getPointeeType(const Type *T) {
139140

140141
const NamedDecl *getTemplatePattern(const NamedDecl *D) {
141142
if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(D)) {
142-
return CRD->getTemplateInstantiationPattern();
143+
if (const auto *Result = CRD->getTemplateInstantiationPattern())
144+
return Result;
145+
// getTemplateInstantiationPattern returns null if the Specialization is
146+
// incomplete (e.g. the type didn't need to be complete), fall back to the
147+
// primary template.
148+
if (CRD->getTemplateSpecializationKind() == TSK_Undeclared)
149+
if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(CRD))
150+
return Spec->getSpecializedTemplate()->getTemplatedDecl();
143151
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
144152
return FD->getTemplateInstantiationPattern();
145153
} else if (auto *VD = dyn_cast<VarDecl>(D)) {

clang-tools-extra/clangd/Hover.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,12 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
537537
llvm::consumeError(Offset.takeError());
538538
return llvm::None;
539539
}
540-
SelectionTree Selection(AST.getASTContext(), AST.getTokens(), *Offset);
540+
// Editors send the position on the left of the hovered character.
541+
// So our selection tree should be biased right. (Tested with VSCode).
542+
SelectionTree ST = SelectionTree::createRight(
543+
AST.getASTContext(), AST.getTokens(), *Offset, *Offset);
541544
std::vector<const Decl *> Result;
542-
if (const SelectionTree::Node *N = Selection.commonAncestor()) {
545+
if (const SelectionTree::Node *N = ST.commonAncestor()) {
543546
auto Decls = explicitReferenceTargets(N->ASTNode, DeclRelation::Alias);
544547
if (!Decls.empty()) {
545548
HI = getHoverContents(Decls.front(), Index);

clang-tools-extra/clangd/Protocol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,8 @@ struct CompletionItem {
11011101
/// the client side.
11021102
float score = 0.f;
11031103

1104+
// TODO: Add custom commitCharacters for some of the completion items. For
1105+
// example, it makes sense to use () only for the functions.
11041106
// TODO(krasimir): The following optional fields defined by the language
11051107
// server protocol are unsupported:
11061108
//

0 commit comments

Comments
 (0)