Skip to content

Commit 0393b87

Browse files
committed
Merge from 'master' to 'sycl-web' (#184)
2 parents d41ed54 + 631be5c commit 0393b87

File tree

644 files changed

+24332
-12301
lines changed

Some content is hidden

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

644 files changed

+24332
-12301
lines changed

clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def main():
8989
database = json.load(open(os.path.join(build_path, db_path)))
9090
files = [entry['file'] for entry in database]
9191

92+
# Filter out .rc files on Windows. CMake includes them for some reason.
93+
files = [f for f in files if not f.endswith('.rc')]
94+
9295
max_task = args.j
9396
if max_task == 0:
9497
max_task = multiprocessing.cpu_count()

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

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,46 @@ static bool CheckRemoval(SourceManager &SM, SourceLocation StartLoc,
3939
File.begin(), TokenBegin, File.end());
4040

4141
Token Tok;
42-
int ParenLevel = 0;
42+
int NestingLevel = 0; // Parens, braces, and square brackets
43+
int AngleBracketLevel = 0;
4344
bool FoundTypedef = false;
4445

4546
while (!DeclLexer.LexFromRawLexer(Tok) && !Tok.is(tok::semi)) {
4647
switch (Tok.getKind()) {
4748
case tok::l_brace:
48-
case tok::r_brace:
49-
// This might be the `typedef struct {...} T;` case.
50-
return false;
49+
if (NestingLevel == 0 && AngleBracketLevel == 0) {
50+
// At top level, this might be the `typedef struct {...} T;` case.
51+
// Inside parens, square brackets, or angle brackets it's not.
52+
return false;
53+
}
54+
++NestingLevel;
55+
break;
5156
case tok::l_paren:
52-
ParenLevel++;
57+
case tok::l_square:
58+
++NestingLevel;
5359
break;
60+
case tok::r_brace:
5461
case tok::r_paren:
55-
ParenLevel--;
62+
case tok::r_square:
63+
--NestingLevel;
64+
break;
65+
case tok::less:
66+
// If not nested in paren/brace/square bracket, treat as opening angle bracket.
67+
if (NestingLevel == 0)
68+
++AngleBracketLevel;
69+
break;
70+
case tok::greater:
71+
// Per C++ 17 Draft N4659, Section 17.2/3
72+
// https://timsong-cpp.github.io/cppwp/n4659/temp.names#3:
73+
// "When parsing a template-argument-list, the first non-nested > is
74+
// taken as the ending delimiter rather than a greater-than operator."
75+
// If not nested in paren/brace/square bracket, treat as closing angle bracket.
76+
if (NestingLevel == 0)
77+
--AngleBracketLevel;
5678
break;
5779
case tok::comma:
58-
if (ParenLevel == 0) {
59-
// If there is comma and we are not between open parenthesis then it is
60-
// two or more declarations in this chain.
80+
if (NestingLevel == 0 && AngleBracketLevel == 0) {
81+
// If there is a non-nested comma we have two or more declarations in this chain.
6182
return false;
6283
}
6384
break;
@@ -88,8 +109,7 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
88109
if (StartLoc.isMacroID() && IgnoreMacros)
89110
return;
90111

91-
auto Diag =
92-
diag(StartLoc, "use 'using' instead of 'typedef'");
112+
auto Diag = diag(StartLoc, "use 'using' instead of 'typedef'");
93113

94114
// do not fix if there is macro or array
95115
if (MatchedDecl->getUnderlyingType()->isArrayType() || StartLoc.isMacroID())

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,23 @@ void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) {
4646
// string bar("");
4747
Finder->addMatcher(
4848
namedDecl(
49-
varDecl(hasType(hasUnqualifiedDesugaredType(recordType(
50-
hasDeclaration(cxxRecordDecl(hasName("basic_string")))))),
51-
hasInitializer(expr(ignoringImplicit(anyOf(
52-
EmptyStringCtorExpr,
53-
EmptyStringCtorExprWithTemporaries)))
54-
.bind("expr"))),
55-
unless(parmVarDecl()))
56-
.bind("decl"),
49+
varDecl(
50+
hasType(hasUnqualifiedDesugaredType(recordType(
51+
hasDeclaration(cxxRecordDecl(hasName("basic_string")))))),
52+
hasInitializer(expr(ignoringImplicit(anyOf(
53+
EmptyStringCtorExpr, EmptyStringCtorExprWithTemporaries)))))
54+
.bind("vardecl"),
55+
unless(parmVarDecl())),
5756
this);
5857
}
5958

6059
void RedundantStringInitCheck::check(const MatchFinder::MatchResult &Result) {
61-
const auto *CtorExpr = Result.Nodes.getNodeAs<Expr>("expr");
62-
const auto *Decl = Result.Nodes.getNodeAs<NamedDecl>("decl");
63-
diag(CtorExpr->getExprLoc(), "redundant string initialization")
64-
<< FixItHint::CreateReplacement(CtorExpr->getSourceRange(),
65-
Decl->getName());
60+
const auto *VDecl = Result.Nodes.getNodeAs<VarDecl>("vardecl");
61+
// VarDecl's getSourceRange() spans 'string foo = ""' or 'string bar("")'.
62+
// So start at getLocation() to span just 'foo = ""' or 'bar("")'.
63+
SourceRange ReplaceRange(VDecl->getLocation(), VDecl->getEndLoc());
64+
diag(VDecl->getLocation(), "redundant string initialization")
65+
<< FixItHint::CreateReplacement(ReplaceRange, VDecl->getName());
6666
}
6767

6868
} // namespace readability

clang-tools-extra/clangd/AST.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ std::string printName(const ASTContext &Ctx, const NamedDecl &ND) {
127127
std::string Name;
128128
llvm::raw_string_ostream Out(Name);
129129
PrintingPolicy PP(Ctx.getLangOpts());
130+
// We don't consider a class template's args part of the constructor name.
131+
PP.SuppressTemplateArgsInCXXConstructors = true;
130132

131133
// Handle 'using namespace'. They all have the same name - <using-directive>.
132134
if (auto *UD = llvm::dyn_cast<UsingDirectiveDecl>(&ND)) {

clang-tools-extra/clangd/HeaderSourceSwitch.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "HeaderSourceSwitch.h"
1010
#include "AST.h"
1111
#include "Logger.h"
12+
#include "SourceCode.h"
1213
#include "index/SymbolCollector.h"
1314
#include "clang/AST/Decl.h"
1415

@@ -96,7 +97,7 @@ llvm::Optional<Path> getCorrespondingHeaderOrSource(const Path &OriginalFile,
9697
//
9798
// For each symbol in the original file, we get its target location (decl or
9899
// def) from the index, then award that target file.
99-
bool IsHeader = AST.getASTContext().getLangOpts().IsHeaderFile;
100+
bool IsHeader = isHeaderFile(OriginalFile, AST.getASTContext().getLangOpts());
100101
Index->lookup(Request, [&](const Symbol &Sym) {
101102
if (IsHeader)
102103
AwardTarget(Sym.Definition.FileURI);

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ SymbolKind indexSymbolKindToSymbolKind(index::SymbolKind Kind) {
257257
return SymbolKind::Property;
258258
case index::SymbolKind::Constructor:
259259
case index::SymbolKind::Destructor:
260-
return SymbolKind::Method;
260+
return SymbolKind::Constructor;
261261
case index::SymbolKind::ConversionFunction:
262262
return SymbolKind::Function;
263263
case index::SymbolKind::Parameter:

clang-tools-extra/clangd/Selection.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
#include "Logger.h"
1111
#include "SourceCode.h"
1212
#include "clang/AST/ASTTypeTraits.h"
13+
#include "clang/AST/DeclCXX.h"
14+
#include "clang/AST/Expr.h"
1315
#include "clang/AST/PrettyPrinter.h"
1416
#include "clang/AST/RecursiveASTVisitor.h"
1517
#include "clang/AST/TypeLoc.h"
18+
#include "clang/Basic/OperatorKinds.h"
1619
#include "clang/Basic/SourceLocation.h"
1720
#include "clang/Basic/SourceManager.h"
1821
#include "clang/Basic/TokenKinds.h"
@@ -145,6 +148,32 @@ std::string printNodeToString(const DynTypedNode &N, const PrintingPolicy &PP) {
145148
}
146149
#endif
147150

151+
bool isImplicit(const Stmt* S) {
152+
// Some Stmts are implicit and shouldn't be traversed, but there's no
153+
// "implicit" attribute on Stmt/Expr.
154+
// Unwrap implicit casts first if present (other nodes too?).
155+
if (auto *ICE = llvm::dyn_cast<ImplicitCastExpr>(S))
156+
S = ICE->getSubExprAsWritten();
157+
// Implicit this in a MemberExpr is not filtered out by RecursiveASTVisitor.
158+
// It would be nice if RAV handled this (!shouldTraverseImplicitCode()).
159+
if (auto *CTI = llvm::dyn_cast<CXXThisExpr>(S))
160+
if (CTI->isImplicit())
161+
return true;
162+
// Refs to operator() and [] are (almost?) always implicit as part of calls.
163+
if (auto *DRE = llvm::dyn_cast<DeclRefExpr>(S)) {
164+
if (auto *FD = llvm::dyn_cast<FunctionDecl>(DRE->getDecl())) {
165+
switch (FD->getOverloadedOperator()) {
166+
case OO_Call:
167+
case OO_Subscript:
168+
return true;
169+
default:
170+
break;
171+
}
172+
}
173+
}
174+
return false;
175+
}
176+
148177
// We find the selection by visiting written nodes in the AST, looking for nodes
149178
// that intersect with the selected character range.
150179
//
@@ -210,13 +239,8 @@ class SelectionVisitor : public RecursiveASTVisitor<SelectionVisitor> {
210239
}
211240
// Stmt is the same, but this form allows the data recursion optimization.
212241
bool dataTraverseStmtPre(Stmt *X) {
213-
if (!X)
242+
if (!X || isImplicit(X))
214243
return false;
215-
// Implicit this in a MemberExpr is not filtered out by RecursiveASTVisitor.
216-
// It would be nice if RAV handled this (!shouldTRaverseImplicitCode()).
217-
if (auto *CTI = llvm::dyn_cast<CXXThisExpr>(X))
218-
if (CTI->isImplicit())
219-
return false;
220244
auto N = DynTypedNode::create(*X);
221245
if (canSafelySkipNode(N))
222246
return false;
@@ -374,6 +398,9 @@ class SelectionVisitor : public RecursiveASTVisitor<SelectionVisitor> {
374398
// int (*[[s]])();
375399
else if (auto *VD = llvm::dyn_cast<VarDecl>(D))
376400
return VD->getLocation();
401+
} else if (const auto* CCI = N.get<CXXCtorInitializer>()) {
402+
// : [[b_]](42)
403+
return CCI->getMemberLocation();
377404
}
378405
return SourceRange();
379406
}

clang-tools-extra/clangd/SourceCode.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/Basic/SourceLocation.h"
1818
#include "clang/Basic/SourceManager.h"
1919
#include "clang/Basic/TokenKinds.h"
20+
#include "clang/Driver/Types.h"
2021
#include "clang/Format/Format.h"
2122
#include "clang/Lex/Lexer.h"
2223
#include "clang/Lex/Preprocessor.h"
@@ -1122,5 +1123,17 @@ EligibleRegion getEligiblePoints(llvm::StringRef Code,
11221123
return ER;
11231124
}
11241125

1126+
bool isHeaderFile(llvm::StringRef FileName,
1127+
llvm::Optional<LangOptions> LangOpts) {
1128+
// Respect the langOpts, for non-file-extension cases, e.g. standard library
1129+
// files.
1130+
if (LangOpts && LangOpts->IsHeaderFile)
1131+
return true;
1132+
namespace types = clang::driver::types;
1133+
auto Lang = types::lookupTypeForExtension(
1134+
llvm::sys::path::extension(FileName).substr(1));
1135+
return Lang != types::TY_INVALID && types::onlyPrecompileType(Lang);
1136+
}
1137+
11251138
} // namespace clangd
11261139
} // namespace clang

clang-tools-extra/clangd/SourceCode.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,15 @@ struct DefinedMacro {
292292
llvm::StringRef Name;
293293
const MacroInfo *Info;
294294
};
295-
// Gets the macro at a specified \p Loc.
295+
/// Gets the macro at a specified \p Loc.
296296
llvm::Optional<DefinedMacro> locateMacroAt(SourceLocation Loc,
297297
Preprocessor &PP);
298298

299+
/// Infers whether this is a header from the FileName and LangOpts (if
300+
/// presents).
301+
bool isHeaderFile(llvm::StringRef FileName,
302+
llvm::Optional<LangOptions> LangOpts = llvm::None);
303+
299304
} // namespace clangd
300305
} // namespace clang
301306
#endif

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ static std::string getLocalScope(const Decl *D) {
417417
auto GetName = [](const Decl *D) {
418418
const NamedDecl *ND = dyn_cast<NamedDecl>(D);
419419
std::string Name = ND->getNameAsString();
420+
// FIXME(sammccall): include template params/specialization args?.
420421
if (!Name.empty())
421422
return Name;
422423
if (auto RD = dyn_cast<RecordDecl>(D))
@@ -455,6 +456,7 @@ static std::string printDefinition(const Decl *D) {
455456
PrintingPolicy Policy =
456457
printingPolicyForDecls(D->getASTContext().getPrintingPolicy());
457458
Policy.IncludeTagDefinition = false;
459+
Policy.SuppressTemplateArgsInCXXConstructors = true;
458460
D->print(OS, Policy);
459461
OS.flush();
460462
return Definition;
@@ -657,6 +659,10 @@ static HoverInfo getHoverContents(const Decl *D, const SymbolIndex *Index) {
657659
Init->getType());
658660
}
659661
}
662+
} else if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
663+
// Dependent enums (e.g. nested in template classes) don't have values yet.
664+
if (!ECD->getType()->isDependentType())
665+
HI.Value = ECD->getInitVal().toString(10);
660666
}
661667

662668
HI.Definition = printDefinition(D);

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,7 @@ BackgroundIndex::indexFileTask(tooling::CompileCommand Cmd) {
205205
}
206206

207207
void BackgroundIndex::boostRelated(llvm::StringRef Path) {
208-
namespace types = clang::driver::types;
209-
auto Type =
210-
types::lookupTypeForExtension(llvm::sys::path::extension(Path).substr(1));
211-
// is this a header?
212-
if (Type != types::TY_INVALID && types::onlyPrecompileType(Type))
208+
if (isHeaderFile(Path))
213209
Queue.boost(filenameWithoutExtension(Path), IndexBoostedFile);
214210
}
215211

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,20 @@ bool MemIndex::refs(const RefsRequest &Req,
7272
trace::Span Tracer("MemIndex refs");
7373
uint32_t Remaining =
7474
Req.Limit.getValueOr(std::numeric_limits<uint32_t>::max());
75-
bool More = false;
7675
for (const auto &ReqID : Req.IDs) {
7776
auto SymRefs = Refs.find(ReqID);
7877
if (SymRefs == Refs.end())
7978
continue;
8079
for (const auto &O : SymRefs->second) {
8180
if (!static_cast<int>(Req.Filter & O.Kind))
8281
continue;
83-
if (Remaining == 0) {
84-
More = true;
85-
break;
86-
}
87-
if (Remaining > 0) {
88-
--Remaining;
89-
Callback(O);
90-
}
82+
if (Remaining == 0)
83+
return true; // More refs were available.
84+
--Remaining;
85+
Callback(O);
9186
}
9287
}
93-
return More;
88+
return false; // We reported all refs.
9489
}
9590

9691
void MemIndex::relations(

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,24 @@ bool MergedIndex::refs(const RefsRequest &Req,
107107
More |= Dynamic->refs(Req, [&](const Ref &O) {
108108
DynamicIndexFileURIs.insert(O.Location.FileURI);
109109
Callback(O);
110+
assert(Remaining != 0);
110111
--Remaining;
111112
});
112113
if (Remaining == 0 && More)
113114
return More;
114115
// We return less than Req.Limit if static index returns more refs for dirty
115116
// files.
116-
More |= Static->refs(Req, [&](const Ref &O) {
117+
bool StaticHadMore = Static->refs(Req, [&](const Ref &O) {
117118
if (DynamicIndexFileURIs.count(O.Location.FileURI))
118119
return; // ignore refs that have been seen from dynamic index.
119-
if (Remaining == 0)
120+
if (Remaining == 0) {
120121
More = true;
121-
if (Remaining > 0) {
122-
--Remaining;
123-
Callback(O);
122+
return;
124123
}
124+
--Remaining;
125+
Callback(O);
125126
});
126-
return More;
127+
return More || StaticHadMore;
127128
}
128129

129130
void MergedIndex::relations(

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ bool SymbolCollector::handleDeclOccurence(
304304
// it's main-file only.
305305
bool IsMainFileOnly =
306306
SM.isWrittenInMainFile(SM.getExpansionLoc(ND->getBeginLoc())) &&
307-
!ASTCtx->getLangOpts().IsHeaderFile;
307+
!isHeaderFile(SM.getFileEntryForID(SM.getMainFileID())->getName(),
308+
ASTCtx->getLangOpts());
308309
// In C, printf is a redecl of an implicit builtin! So check OrigD instead.
309310
if (ASTNode.OrigD->isImplicit() ||
310311
!shouldCollectSymbol(*ND, *ASTCtx, Opts, IsMainFileOnly))

0 commit comments

Comments
 (0)