Skip to content

Commit b9883c5

Browse files
committed
Merge from 'master' to 'sycl-web' (#710)
Resolve merge conflict in README.md
2 parents 23fd3a0 + 905ccf8 commit b9883c5

File tree

8,011 files changed

+156745
-805054
lines changed

Some content is hidden

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

8,011 files changed

+156745
-805054
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
2121
## SYCL Extension Proposal Documents
2222

2323
See [sycl/doc/extensions](sycl/doc/extensions)
24+

clang-tools-extra/clang-tidy/ClangTidyCheck.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
133133
/// ``CheckOptions``. If the corresponding key is not present, returns
134134
/// \p Default.
135135
template <typename T>
136-
typename std::enable_if<std::is_integral<T>::value, T>::type
137-
get(StringRef LocalName, T Default) const {
136+
std::enable_if_t<std::is_integral<T>::value, T> get(StringRef LocalName,
137+
T Default) const {
138138
std::string Value = get(LocalName, "");
139139
T Result = Default;
140140
if (!Value.empty())
@@ -150,7 +150,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
150150
/// present, falls back to get global option. If global option is not
151151
/// present either, returns Default.
152152
template <typename T>
153-
typename std::enable_if<std::is_integral<T>::value, T>::type
153+
std::enable_if_t<std::is_integral<T>::value, T>
154154
getLocalOrGlobal(StringRef LocalName, T Default) const {
155155
std::string Value = getLocalOrGlobal(LocalName, "");
156156
T Result = Default;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ static std::string getCondVarNames(const Stmt *Cond) {
152152
return Result;
153153
}
154154

155+
static bool isKnownFalse(const Expr &Cond, const ASTContext &Ctx) {
156+
bool Result = false;
157+
if (Cond.EvaluateAsBooleanCondition(Result, Ctx))
158+
return !Result;
159+
return false;
160+
}
161+
155162
void InfiniteLoopCheck::registerMatchers(MatchFinder *Finder) {
156163
const auto LoopCondition = allOf(
157164
hasCondition(
@@ -170,6 +177,9 @@ void InfiniteLoopCheck::check(const MatchFinder::MatchResult &Result) {
170177
const auto *LoopStmt = Result.Nodes.getNodeAs<Stmt>("loop-stmt");
171178
const auto *Func = Result.Nodes.getNodeAs<FunctionDecl>("func");
172179

180+
if (isKnownFalse(*Cond, *Result.Context))
181+
return;
182+
173183
bool ShouldHaveConditionVariables = true;
174184
if (const auto *While = dyn_cast<WhileStmt>(LoopStmt)) {
175185
if (const VarDecl *LoopVarDecl = While->getConditionVariable()) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ void DefinitionsInHeadersCheck::check(const MatchFinder::MatchResult &Result) {
134134
DiagnosticIDs::Note)
135135
<< FixItHint::CreateInsertion(FD->getInnerLocStart(), "inline ");
136136
} else if (const auto *VD = dyn_cast<VarDecl>(ND)) {
137+
// C++14 variable templates are allowed.
138+
if (VD->getDescribedVarTemplate())
139+
return;
137140
// Static data members of a class template are allowed.
138141
if (VD->getDeclContext()->isDependentContext() && VD->isStaticDataMember())
139142
return;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@ void UseUncaughtExceptionsCheck::registerMatchers(MatchFinder *Finder) {
3434
.bind("decl_ref_expr"),
3535
this);
3636

37+
auto DirectCallToUncaughtException = callee(expr(ignoringImpCasts(
38+
declRefExpr(hasDeclaration(functionDecl(hasName(MatchText)))))));
39+
3740
// CallExpr: warning, fix-it.
38-
Finder->addMatcher(callExpr(hasDeclaration(functionDecl(hasName(MatchText))),
41+
Finder->addMatcher(callExpr(DirectCallToUncaughtException,
3942
unless(hasAncestor(initListExpr())))
4043
.bind("call_expr"),
4144
this);
4245
// CallExpr in initialisation list: warning, fix-it with avoiding narrowing
4346
// conversions.
44-
Finder->addMatcher(callExpr(hasAncestor(initListExpr()),
45-
hasDeclaration(functionDecl(hasName(MatchText))))
47+
Finder->addMatcher(callExpr(DirectCallToUncaughtException,
48+
hasAncestor(initListExpr()))
4649
.bind("init_call_expr"),
4750
this);
4851
}

clang-tools-extra/clang-tidy/objc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS support)
22

33
add_clang_library(clangTidyObjCModule
44
AvoidNSErrorInitCheck.cpp
5+
DeallocInCategoryCheck.cpp
56
ForbiddenSubclassingCheck.cpp
67
MissingHashCheck.cpp
78
ObjCTidyModule.cpp
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//===--- DeallocInCategoryCheck.cpp - clang-tidy -------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "DeallocInCategoryCheck.h"
10+
#include "clang/AST/ASTContext.h"
11+
#include "clang/AST/DeclObjC.h"
12+
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
14+
using namespace clang::ast_matchers;
15+
16+
namespace clang {
17+
namespace tidy {
18+
namespace objc {
19+
20+
void DeallocInCategoryCheck::registerMatchers(MatchFinder *Finder) {
21+
// This check should only be applied to Objective-C sources.
22+
if (!getLangOpts().ObjC)
23+
return;
24+
25+
// Non-NSObject/NSProxy-derived objects may not have -dealloc as a special
26+
// method. However, it seems highly unrealistic to expect many false-positives
27+
// by warning on -dealloc in categories on classes without one of those
28+
// base classes.
29+
Finder->addMatcher(
30+
objcMethodDecl(isInstanceMethod(), hasName("dealloc"),
31+
hasDeclContext(objcCategoryImplDecl().bind("impl")))
32+
.bind("dealloc"),
33+
this);
34+
}
35+
36+
void DeallocInCategoryCheck::check(const MatchFinder::MatchResult &Result) {
37+
const auto *DeallocDecl = Result.Nodes.getNodeAs<ObjCMethodDecl>("dealloc");
38+
const auto *CID = Result.Nodes.getNodeAs<ObjCCategoryImplDecl>("impl");
39+
assert(DeallocDecl != nullptr);
40+
diag(DeallocDecl->getLocation(), "category %0 should not implement -dealloc")
41+
<< CID;
42+
}
43+
44+
} // namespace objc
45+
} // namespace tidy
46+
} // namespace clang
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===--- DeallocInCategoryCheck.h - clang-tidy ------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_DEALLOCINCATEGORYCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_DEALLOCINCATEGORYCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang {
15+
namespace tidy {
16+
namespace objc {
17+
18+
/// Finds implementations of -dealloc in Objective-C categories. The category
19+
/// implementation will override any dealloc in the class implementation,
20+
/// potentially causing issues.
21+
///
22+
/// For the user-facing documentation see:
23+
/// http://clang.llvm.org/extra/clang-tidy/checks/objc-dealloc-in-category.html
24+
class DeallocInCategoryCheck final : public ClangTidyCheck {
25+
public:
26+
DeallocInCategoryCheck(StringRef Name, ClangTidyContext *Context)
27+
: ClangTidyCheck(Name, Context) {}
28+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
29+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
30+
};
31+
32+
} // namespace objc
33+
} // namespace tidy
34+
} // namespace clang
35+
36+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_DEALLOCINCATEGORYCHECK_H

clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "../ClangTidyModule.h"
1111
#include "../ClangTidyModuleRegistry.h"
1212
#include "AvoidNSErrorInitCheck.h"
13+
#include "DeallocInCategoryCheck.h"
1314
#include "ForbiddenSubclassingCheck.h"
1415
#include "MissingHashCheck.h"
1516
#include "PropertyDeclarationCheck.h"
@@ -26,6 +27,8 @@ class ObjCModule : public ClangTidyModule {
2627
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
2728
CheckFactories.registerCheck<AvoidNSErrorInitCheck>(
2829
"objc-avoid-nserror-init");
30+
CheckFactories.registerCheck<DeallocInCategoryCheck>(
31+
"objc-dealloc-in-category");
2932
CheckFactories.registerCheck<ForbiddenSubclassingCheck>(
3033
"objc-forbidden-subclassing");
3134
CheckFactories.registerCheck<MissingHashCheck>(

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ void ClangdLSPServer::onDocumentDidChange(
647647
return;
648648
}
649649

650-
Server->addDocument(File, *Contents, WantDiags);
650+
Server->addDocument(File, *Contents, WantDiags, Params.forceRebuild);
651651
}
652652

653653
void ClangdLSPServer::onFileEvent(const DidChangeWatchedFilesParams &Params) {

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
170170
}
171171

172172
void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
173-
WantDiagnostics WantDiags) {
173+
WantDiagnostics WantDiags, bool ForceRebuild) {
174174
auto FS = FSProvider.getFileSystem();
175175

176176
ParseOptions Opts;
@@ -184,6 +184,7 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
184184
ParseInputs Inputs;
185185
Inputs.FS = FS;
186186
Inputs.Contents = std::string(Contents);
187+
Inputs.ForceRebuild = ForceRebuild;
187188
Inputs.Opts = std::move(Opts);
188189
Inputs.Index = Index;
189190
bool NewFile = WorkScheduler.update(File, Inputs, WantDiags);

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ class ClangdServer {
172172
/// separate thread. When the parsing is complete, DiagConsumer passed in
173173
/// constructor will receive onDiagnosticsReady callback.
174174
void addDocument(PathRef File, StringRef Contents,
175-
WantDiagnostics WD = WantDiagnostics::Auto);
175+
WantDiagnostics WD = WantDiagnostics::Auto,
176+
bool ForceRebuild = false);
176177

177178
/// Get the contents of \p File, which should have been added.
178179
llvm::StringRef getDocument(PathRef File) const;

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,7 @@ class CodeCompleteFlow {
14731473
}
14741474
Output.HasMore = Incomplete;
14751475
Output.Context = CCContextKind;
1476+
Output.CompletionRange = ReplacedRange;
14761477
return Output;
14771478
}
14781479

clang-tools-extra/clangd/CodeComplete.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ struct CodeCompleteResult {
216216
std::vector<CodeCompletion> Completions;
217217
bool HasMore = false;
218218
CodeCompletionContext::Kind Context = CodeCompletionContext::CCC_Other;
219+
// The text that is being directly completed.
220+
// Example: foo.pb^ -> foo.push_back()
221+
// ~~
222+
// Typically matches the textEdit.range of Completions, but not guaranteed to.
223+
llvm::Optional<Range> CompletionRange;
219224
// Usually the source will be parsed with a real C++ parser.
220225
// But heuristics may be used instead if e.g. the preamble is not ready.
221226
bool RanParser = true;

clang-tools-extra/clangd/Compiler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ struct ParseInputs {
4545
tooling::CompileCommand CompileCommand;
4646
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;
4747
std::string Contents;
48+
// Prevent reuse of the cached preamble/AST. Slow! Useful to workaround
49+
// clangd's assumption that missing header files will stay missing.
50+
bool ForceRebuild = false;
4851
// Used to recover from diagnostics (e.g. find missing includes for symbol).
4952
const SymbolIndex *Index = nullptr;
5053
ParseOptions Opts;

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,17 @@ llvm::SmallVector<ReferenceLoc, 2> refInExpr(const Expr *E) {
672672
// Select the getter, setter, or @property depending on the call.
673673
explicitReferenceTargets(DynTypedNode::create(*E), {})});
674674
}
675+
676+
void VisitDesignatedInitExpr(const DesignatedInitExpr *DIE) {
677+
for (const DesignatedInitExpr::Designator &D : DIE->designators()) {
678+
if (!D.isFieldDesignator())
679+
continue;
680+
Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
681+
D.getFieldLoc(),
682+
/*IsDecl=*/false,
683+
{D.getField()}});
684+
}
685+
}
675686
};
676687

677688
Visitor V;

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,10 @@ bool fromJSON(const llvm::json::Value &Params, DidCloseTextDocumentParams &R) {
430430

431431
bool fromJSON(const llvm::json::Value &Params, DidChangeTextDocumentParams &R) {
432432
llvm::json::ObjectMapper O(Params);
433-
return O && O.map("textDocument", R.textDocument) &&
433+
if (!O)
434+
return false;
435+
O.map("forceRebuild", R.forceRebuild); // Optional clangd extension.
436+
return O.map("textDocument", R.textDocument) &&
434437
O.map("contentChanges", R.contentChanges) &&
435438
O.map("wantDiagnostics", R.wantDiagnostics);
436439
}

clang-tools-extra/clangd/Protocol.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,12 @@ struct DidChangeTextDocumentParams {
652652
/// either they will be provided for this version or some subsequent one.
653653
/// This is a clangd extension.
654654
llvm::Optional<bool> wantDiagnostics;
655+
656+
/// Force a complete rebuild of the file, ignoring all cached state. Slow!
657+
/// This is useful to defeat clangd's assumption that missing headers will
658+
/// stay missing.
659+
/// This is a clangd extension.
660+
bool forceRebuild = false;
655661
};
656662
bool fromJSON(const llvm::json::Value &, DidChangeTextDocumentParams &);
657663

clang-tools-extra/clangd/Shutdown.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bool shutdownRequested();
6666
/// requested (which interrupts IO), we'll fail rather than retry.
6767
template <typename Fun, typename Ret = decltype(std::declval<Fun>()())>
6868
Ret retryAfterSignalUnlessShutdown(
69-
const typename std::enable_if<true, Ret>::type &Fail, // Suppress deduction.
69+
const std::enable_if_t<true, Ret> &Fail, // Suppress deduction.
7070
const Fun &F) {
7171
Ret Res;
7272
do {

clang-tools-extra/clangd/TUScheduler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ void ASTWorker::update(ParseInputs Inputs, WantDiagnostics WantDiags) {
436436
}
437437

438438
std::shared_ptr<const PreambleData> OldPreamble =
439-
getPossiblyStalePreamble();
439+
Inputs.ForceRebuild ? std::shared_ptr<const PreambleData>()
440+
: getPossiblyStalePreamble();
440441
std::shared_ptr<const PreambleData> NewPreamble = buildPreamble(
441442
FileName, *Invocation, OldPreamble, OldCommand, Inputs,
442443
StorePreambleInMemory,

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ void SymbolCollector::finish() {
574574
// FIXME: All MacroRefs are marked as Spelled now, but this should be checked.
575575
for (const auto &IDAndRefs : MacroRefs)
576576
for (const auto &LocAndRole : IDAndRefs.second)
577-
CollectRef(IDAndRefs.first, LocAndRole);
577+
CollectRef(IDAndRefs.first, LocAndRole, /*Spelled=*/true);
578578
// Populate Refs slab from DeclRefs.
579579
llvm::DenseMap<FileID, std::vector<syntax::Token>> FilesToTokensCache;
580580
for (auto &DeclAndRef : DeclRefs) {
@@ -592,7 +592,10 @@ void SymbolCollector::finish() {
592592
const auto *IdentifierToken =
593593
spelledIdentifierTouching(LocAndRole.first, Tokens);
594594
DeclarationName Name = DeclAndRef.first->getDeclName();
595-
bool Spelled = IdentifierToken && Name.isIdentifier() &&
595+
const auto NameKind = Name.getNameKind();
596+
bool IsTargetKind = NameKind == DeclarationName::Identifier ||
597+
NameKind == DeclarationName::CXXConstructorName;
598+
bool Spelled = IdentifierToken && IsTargetKind &&
596599
Name.getAsString() == IdentifierToken->text(SM);
597600
CollectRef(*ID, LocAndRole, Spelled);
598601
}

clang-tools-extra/clangd/index/SymbolID.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class SymbolID {
3636
bool operator==(const SymbolID &Sym) const {
3737
return HashValue == Sym.HashValue;
3838
}
39+
bool operator!=(const SymbolID &Sym) const {
40+
return !(*this == Sym);
41+
}
3942
bool operator<(const SymbolID &Sym) const {
4043
return HashValue < Sym.HashValue;
4144
}

clang-tools-extra/clangd/refactor/Rename.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ llvm::DenseSet<const NamedDecl *> locateDeclAt(ParsedAST &AST,
9696
return Result;
9797
}
9898

99+
// By default, we blacklist C++ standard symbols and protobuf symbols as rename
100+
// these symbols would change system/generated files which are unlikely to be
101+
// modified.
99102
bool isBlacklisted(const NamedDecl &RenameDecl) {
103+
if (isProtoFile(RenameDecl.getLocation(),
104+
RenameDecl.getASTContext().getSourceManager()))
105+
return true;
100106
static const auto *StdSymbols = new llvm::DenseSet<llvm::StringRef>({
101107
#define SYMBOL(Name, NameSpace, Header) {#NameSpace #Name},
102108
#include "StdSymbolMap.inc"
@@ -306,6 +312,8 @@ findOccurrencesOutsideFile(const NamedDecl &RenameDecl,
306312
bool HasMore = Index.refs(RQuest, [&](const Ref &R) {
307313
if (AffectedFiles.size() > MaxLimitFiles)
308314
return;
315+
if ((R.Kind & RefKind::Spelled) == RefKind::Unknown)
316+
return;
309317
if (auto RefFilePath = filePath(R.Location, /*HintFilePath=*/MainFile)) {
310318
if (*RefFilePath != MainFile)
311319
AffectedFiles[*RefFilePath].push_back(toRange(R.Location));
@@ -344,9 +352,6 @@ findOccurrencesOutsideFile(const NamedDecl &RenameDecl,
344352
// index (background index) is relatively stale. We choose the dirty buffers
345353
// as the file content we rename on, and fallback to file content on disk if
346354
// there is no dirty buffer.
347-
//
348-
// FIXME: Our index may return implicit references, which are not eligible for
349-
// rename, we should filter out these references.
350355
llvm::Expected<FileEdits> renameOutsideFile(
351356
const NamedDecl &RenameDecl, llvm::StringRef MainFilePath,
352357
llvm::StringRef NewName, const SymbolIndex &Index,

0 commit comments

Comments
 (0)