Skip to content

Commit 13de58e

Browse files
iclsrcdm-vodopyanov
iclsrc
authored andcommitted
Merge from 'main' to 'sycl-web' (intel#40)
CONFLICT (content): Merge conflict in llvm/tools/opt/opt.cpp
2 parents 8a962f3 + 2303e93 commit 13de58e

File tree

171 files changed

+3774
-608
lines changed

Some content is hidden

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

171 files changed

+3774
-608
lines changed

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

+17-32
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ AST_MATCHER(Expr, usedInBooleanContext) {
8383
});
8484
return Result;
8585
}
86+
AST_MATCHER(CXXConstructExpr, isDefaultConstruction) {
87+
return Node.getConstructor()->isDefaultConstructor();
88+
}
8689
} // namespace ast_matchers
8790
namespace tidy {
8891
namespace readability {
@@ -116,24 +119,16 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
116119
const auto ValidContainer = qualType(
117120
anyOf(ValidContainerNonTemplateType, ValidContainerTemplateType));
118121

119-
const auto WrongUse = traverse(
120-
TK_AsIs,
121-
anyOf(
122-
hasParent(binaryOperator(isComparisonOperator(),
123-
hasEitherOperand(ignoringImpCasts(
124-
anyOf(integerLiteral(equals(1)),
125-
integerLiteral(equals(0))))))
126-
.bind("SizeBinaryOp")),
127-
hasParent(implicitCastExpr(
128-
hasImplicitDestinationType(booleanType()),
129-
anyOf(hasParent(
130-
unaryOperator(hasOperatorName("!")).bind("NegOnSize")),
131-
anything()))),
132-
usedInBooleanContext()));
122+
const auto WrongUse =
123+
anyOf(hasParent(binaryOperator(
124+
isComparisonOperator(),
125+
hasEitherOperand(anyOf(integerLiteral(equals(1)),
126+
integerLiteral(equals(0)))))
127+
.bind("SizeBinaryOp")),
128+
usedInBooleanContext());
133129

134130
Finder->addMatcher(
135-
cxxMemberCallExpr(unless(isInTemplateInstantiation()),
136-
on(expr(anyOf(hasType(ValidContainer),
131+
cxxMemberCallExpr(on(expr(anyOf(hasType(ValidContainer),
137132
hasType(pointsTo(ValidContainer)),
138133
hasType(references(ValidContainer))))
139134
.bind("MemberCallObject")),
@@ -157,18 +152,9 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
157152
.bind("SizeCallExpr"),
158153
this);
159154

160-
// Empty constructor matcher.
161-
const auto DefaultConstructor = cxxConstructExpr(
162-
hasDeclaration(cxxConstructorDecl(isDefaultConstructor())));
163155
// Comparison to empty string or empty constructor.
164156
const auto WrongComparend = anyOf(
165-
ignoringImpCasts(stringLiteral(hasSize(0))),
166-
ignoringImpCasts(cxxBindTemporaryExpr(has(DefaultConstructor))),
167-
ignoringImplicit(DefaultConstructor),
168-
cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
169-
has(expr(ignoringImpCasts(DefaultConstructor)))),
170-
cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isMoveConstructor())),
171-
has(expr(ignoringImpCasts(DefaultConstructor)))),
157+
stringLiteral(hasSize(0)), cxxConstructExpr(isDefaultConstruction()),
172158
cxxUnresolvedConstructExpr(argumentCountIs(0)));
173159
// Match the object being compared.
174160
const auto STLArg =
@@ -178,12 +164,11 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
178164
expr(hasType(pointsTo(ValidContainer))).bind("Pointee"))),
179165
expr(hasType(ValidContainer)).bind("STLObject"));
180166
Finder->addMatcher(
181-
binaryOperation(unless(isInTemplateInstantiation()),
182-
hasAnyOperatorName("==", "!="),
183-
hasOperands(ignoringParenImpCasts(WrongComparend),
184-
ignoringParenImpCasts(STLArg)),
185-
unless(hasAncestor(cxxMethodDecl(
186-
ofClass(equalsBoundNode("container"))))))
167+
binaryOperation(hasAnyOperatorName("==", "!="),
168+
hasOperands(WrongComparend,
169+
STLArg),
170+
unless(hasAncestor(cxxMethodDecl(
171+
ofClass(equalsBoundNode("container"))))))
187172
.bind("BinCmp"),
188173
this);
189174
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class ContainerSizeEmptyCheck : public ClangTidyCheck {
3333
}
3434
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
3535
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
36+
llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
37+
return TK_IgnoreUnlessSpelledInSource;
38+
}
3639
};
3740

3841
} // namespace readability

clang-tools-extra/clangd/IncludeFixer.cpp

+19-27
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,14 @@
4040
#include "llvm/ADT/StringSet.h"
4141
#include "llvm/Support/Error.h"
4242
#include "llvm/Support/FormatVariadic.h"
43+
#include <algorithm>
44+
#include <set>
45+
#include <string>
4346
#include <vector>
4447

4548
namespace clang {
4649
namespace clangd {
4750

48-
namespace {
49-
50-
// Collects contexts visited during a Sema name lookup.
51-
class VisitedContextCollector : public VisibleDeclConsumer {
52-
public:
53-
void EnteredContext(DeclContext *Ctx) override { Visited.push_back(Ctx); }
54-
55-
void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
56-
bool InBaseClass) override {}
57-
58-
std::vector<DeclContext *> takeVisitedContexts() {
59-
return std::move(Visited);
60-
}
61-
62-
private:
63-
std::vector<DeclContext *> Visited;
64-
};
65-
66-
} // namespace
67-
6851
std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
6952
const clang::Diagnostic &Info) const {
7053
switch (Info.getID()) {
@@ -313,17 +296,26 @@ llvm::Optional<CheapUnresolvedName> extractUnresolvedNameCheaply(
313296
std::vector<std::string>
314297
collectAccessibleScopes(Sema &Sem, const DeclarationNameInfo &Typo, Scope *S,
315298
Sema::LookupNameKind LookupKind) {
299+
// Collects contexts visited during a Sema name lookup.
300+
struct VisitedContextCollector : public VisibleDeclConsumer {
301+
VisitedContextCollector(std::vector<std::string> &Out) : Out(Out) {}
302+
void EnteredContext(DeclContext *Ctx) override {
303+
if (llvm::isa<NamespaceDecl>(Ctx))
304+
Out.push_back(printNamespaceScope(*Ctx));
305+
}
306+
void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
307+
bool InBaseClass) override {}
308+
std::vector<std::string> &Out;
309+
};
310+
316311
std::vector<std::string> Scopes;
317-
VisitedContextCollector Collector;
312+
Scopes.push_back("");
313+
VisitedContextCollector Collector(Scopes);
318314
Sem.LookupVisibleDecls(S, LookupKind, Collector,
319315
/*IncludeGlobalScope=*/false,
320316
/*LoadExternal=*/false);
321-
322-
Scopes.push_back("");
323-
for (const auto *Ctx : Collector.takeVisitedContexts()) {
324-
if (isa<NamespaceDecl>(Ctx))
325-
Scopes.push_back(printNamespaceScope(*Ctx));
326-
}
317+
std::sort(Scopes.begin(), Scopes.end());
318+
Scopes.erase(std::unique(Scopes.begin(), Scopes.end()), Scopes.end());
327319
return Scopes;
328320
}
329321

clang-tools-extra/clangd/TUScheduler.cpp

+37-7
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ class ASTWorker {
465465
std::string Name;
466466
steady_clock::time_point AddTime;
467467
Context Ctx;
468+
llvm::Optional<Context> QueueCtx;
468469
llvm::Optional<UpdateType> Update;
469470
TUScheduler::ASTActionInvalidation InvalidationPolicy;
470471
Canceler Invalidate;
@@ -507,7 +508,7 @@ class ASTWorker {
507508
/// None means no builds yet, null means there was an error while building.
508509
/// Only written by ASTWorker's thread.
509510
llvm::Optional<std::shared_ptr<const PreambleData>> LatestPreamble;
510-
std::queue<Request> PreambleRequests; /* GUARDED_BY(Mutex) */
511+
std::deque<Request> PreambleRequests; /* GUARDED_BY(Mutex) */
511512
/// Signaled whenever LatestPreamble changes state or there's a new
512513
/// PreambleRequest.
513514
mutable std::condition_variable PreambleCV;
@@ -826,9 +827,10 @@ void ASTWorker::updatePreamble(std::unique_ptr<CompilerInvocation> CI,
826827
}
827828
{
828829
std::lock_guard<std::mutex> Lock(Mutex);
829-
PreambleRequests.push({std::move(Task), std::move(TaskName),
830-
steady_clock::now(), Context::current().clone(),
831-
llvm::None, TUScheduler::NoInvalidation, nullptr});
830+
PreambleRequests.push_back({std::move(Task), std::move(TaskName),
831+
steady_clock::now(), Context::current().clone(),
832+
llvm::None, llvm::None,
833+
TUScheduler::NoInvalidation, nullptr});
832834
}
833835
PreambleCV.notify_all();
834836
RequestsCV.notify_all();
@@ -1023,9 +1025,34 @@ void ASTWorker::startTask(llvm::StringRef Name,
10231025
std::tie(Ctx, Invalidate) = cancelableTask(
10241026
/*Reason=*/static_cast<int>(ErrorCode::ContentModified));
10251027
}
1028+
// Trace the time the request spends in the queue, and the requests that
1029+
// it's going to wait for.
1030+
llvm::Optional<Context> QueueCtx;
1031+
if (trace::enabled()) {
1032+
// Tracers that follow threads and need strict nesting will see a tiny
1033+
// instantaneous event "we're enqueueing", and sometime later it runs.
1034+
WithContext WC(Ctx.clone());
1035+
trace::Span Tracer("Queued:" + Name);
1036+
if (Tracer.Args) {
1037+
if (CurrentRequest)
1038+
SPAN_ATTACH(Tracer, "CurrentRequest", CurrentRequest->Name);
1039+
llvm::json::Array PreambleRequestsNames;
1040+
for (const auto &Req : PreambleRequests)
1041+
PreambleRequestsNames.push_back(Req.Name);
1042+
SPAN_ATTACH(Tracer, "PreambleRequestsNames",
1043+
std::move(PreambleRequestsNames));
1044+
llvm::json::Array RequestsNames;
1045+
for (const auto &Req : Requests)
1046+
RequestsNames.push_back(Req.Name);
1047+
SPAN_ATTACH(Tracer, "RequestsNames", std::move(RequestsNames));
1048+
}
1049+
// For tracers that follow contexts, keep the trace span's context alive
1050+
// until we dequeue the request, so they see the full duration.
1051+
QueueCtx = Context::current().clone();
1052+
}
10261053
Requests.push_back({std::move(Task), std::string(Name), steady_clock::now(),
1027-
std::move(Ctx), Update, Invalidation,
1028-
std::move(Invalidate)});
1054+
std::move(Ctx), std::move(QueueCtx), Update,
1055+
Invalidation, std::move(Invalidate)});
10291056
}
10301057
RequestsCV.notify_all();
10311058
}
@@ -1071,13 +1098,16 @@ void ASTWorker::run() {
10711098
// Requests.front(), so prefer them first to preserve LSP order.
10721099
if (!PreambleRequests.empty()) {
10731100
CurrentRequest = std::move(PreambleRequests.front());
1074-
PreambleRequests.pop();
1101+
PreambleRequests.pop_front();
10751102
} else {
10761103
CurrentRequest = std::move(Requests.front());
10771104
Requests.pop_front();
10781105
}
10791106
} // unlock Mutex
10801107

1108+
// Inform tracing that the request was dequeued.
1109+
CurrentRequest->QueueCtx.reset();
1110+
10811111
// It is safe to perform reads to CurrentRequest without holding the lock as
10821112
// only writer is also this thread.
10831113
{

clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,6 @@ static_assert(!L.size(), "");
477477

478478
struct StructWithLazyNoexcept {
479479
void func() noexcept(L.size());
480-
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: the 'empty' method should be used
481-
// CHECK-MESSAGES: :101:18: note: method 'Lazy'::empty() defined here
482-
// CHECK-FIXES: {{^ }}void func() noexcept(!L.empty());
483480
};
484481

485482
#define CHECKSIZE(x) if (x.size()) {}

clang/include/clang/AST/ASTContext.h

+3
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@ class ASTContext : public RefCountedBase<ASTContext> {
538538
/// need them (like static local vars).
539539
llvm::MapVector<const NamedDecl *, unsigned> MangleNumbers;
540540
llvm::MapVector<const VarDecl *, unsigned> StaticLocalNumbers;
541+
/// Mapping the associated device lambda mangling number if present.
542+
mutable llvm::DenseMap<const CXXRecordDecl *, unsigned>
543+
DeviceLambdaManglingNumbers;
541544

542545
/// Mapping that stores parameterIndex values for ParmVarDecls when
543546
/// that value exceeds the bitfield size of ParmVarDeclBits.ParameterIndex.

clang/include/clang/AST/DeclCXX.h

+6
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,12 @@ class CXXRecordDecl : public RecordDecl {
17351735
getLambdaData().HasKnownInternalLinkage = HasKnownInternalLinkage;
17361736
}
17371737

1738+
/// Set the device side mangling number.
1739+
void setDeviceLambdaManglingNumber(unsigned Num) const;
1740+
1741+
/// Retrieve the device side mangling number.
1742+
unsigned getDeviceLambdaManglingNumber() const;
1743+
17381744
/// Returns the inheritance model used for this record.
17391745
MSInheritanceModel getMSInheritanceModel() const;
17401746

clang/include/clang/AST/Mangle.h

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ class MangleContext {
107107
virtual bool shouldMangleCXXName(const NamedDecl *D) = 0;
108108
virtual bool shouldMangleStringLiteral(const StringLiteral *SL) = 0;
109109

110+
virtual bool isDeviceMangleContext() const { return false; }
111+
virtual void setDeviceMangleContext(bool) {}
112+
110113
// FIXME: consider replacing raw_ostream & with something like SmallString &.
111114
void mangleName(GlobalDecl GD, raw_ostream &);
112115
virtual void mangleCXXName(GlobalDecl GD, raw_ostream &) = 0;

clang/include/clang/AST/MangleNumberingContext.h

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class MangleNumberingContext {
5252
/// this context.
5353
virtual unsigned getManglingNumber(const TagDecl *TD,
5454
unsigned MSLocalManglingNumber) = 0;
55+
56+
/// Retrieve the mangling number of a new lambda expression with the
57+
/// given call operator within the device context. No device number is
58+
/// assigned if there's no device numbering context is associated.
59+
virtual unsigned getDeviceManglingNumber(const CXXMethodDecl *) { return 0; }
5560
};
5661

5762
} // end namespace clang

clang/include/clang/ASTMatchers/ASTMatchFinder.h

+11
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ class MatchFinder {
110110
/// This id is used, for example, for the profiling output.
111111
/// It defaults to "<unknown>".
112112
virtual StringRef getID() const;
113+
114+
/// TraversalKind to use while matching and processing
115+
/// the result nodes. This API is temporary to facilitate
116+
/// third parties porting existing code to the default
117+
/// behavior of clang-tidy.
118+
virtual llvm::Optional<TraversalKind> getCheckTraversalKind() const;
113119
};
114120

115121
/// Called when parsing is finished. Intended for testing only.
@@ -280,6 +286,11 @@ class CollectMatchesCallback : public MatchFinder::MatchCallback {
280286
void run(const MatchFinder::MatchResult &Result) override {
281287
Nodes.push_back(Result.Nodes);
282288
}
289+
290+
llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
291+
return llvm::None;
292+
}
293+
283294
SmallVector<BoundNodes, 1> Nodes;
284295
};
285296
}

clang/include/clang/Basic/OpenCLExtensions.def

+13-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ OPENCL_OPTIONALCOREFEATURE(cl_khr_fp64, 100, OCL_C_12P)
6464
OPENCL_EXTENSION(cl_khr_fp16, 100)
6565
OPENCL_EXTENSION(cl_khr_int64_base_atomics, 100)
6666
OPENCL_EXTENSION(cl_khr_int64_extended_atomics, 100)
67-
OPENCL_GENERIC_EXTENSION(cl_khr_3d_image_writes, 100, OCL_C_20, OCL_C_30)
67+
OPENCL_COREFEATURE(cl_khr_3d_image_writes, 100, OCL_C_20)
6868

6969
// EMBEDDED_PROFILE
7070
OPENCL_EXTENSION(cles_khr_int64, 110)
@@ -99,6 +99,18 @@ OPENCL_EXTENSION(cl_intel_subgroups, 120)
9999
OPENCL_EXTENSION(cl_intel_subgroups_short, 120)
100100
OPENCL_EXTENSION(cl_intel_device_side_avc_motion_estimation, 120)
101101

102+
// OpenCL C 3.0 features (6.2.1. Features)
103+
OPENCL_OPTIONALCOREFEATURE(__opencl_c_pipes, 300, OCL_C_30)
104+
OPENCL_OPTIONALCOREFEATURE(__opencl_c_generic_address_space, 300, OCL_C_30)
105+
OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_order_acq_rel, 300, OCL_C_30)
106+
OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_order_seq_cst, 300, OCL_C_30)
107+
OPENCL_OPTIONALCOREFEATURE(__opencl_c_subgroups, 300, OCL_C_30)
108+
OPENCL_OPTIONALCOREFEATURE(__opencl_c_3d_image_writes, 300, OCL_C_30)
109+
OPENCL_OPTIONALCOREFEATURE(__opencl_c_device_enqueue, 300, OCL_C_30)
110+
OPENCL_OPTIONALCOREFEATURE(__opencl_c_read_write_images, 300, OCL_C_30)
111+
OPENCL_OPTIONALCOREFEATURE(__opencl_c_program_scope_global_variables, 300, OCL_C_30)
112+
OPENCL_OPTIONALCOREFEATURE(__opencl_c_fp64, 300, OCL_C_30)
113+
OPENCL_OPTIONALCOREFEATURE(__opencl_c_images, 300, OCL_C_30)
102114

103115
#undef OPENCL_OPTIONALCOREFEATURE
104116
#undef OPENCL_COREFEATURE

clang/include/clang/Sema/Sema.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6728,7 +6728,7 @@ class Sema final {
67286728
/// Number lambda for linkage purposes if necessary.
67296729
void handleLambdaNumbering(
67306730
CXXRecordDecl *Class, CXXMethodDecl *Method,
6731-
Optional<std::tuple<unsigned, bool, Decl *>> Mangling = None);
6731+
Optional<std::tuple<bool, unsigned, unsigned, Decl *>> Mangling = None);
67326732

67336733
/// Endow the lambda scope info with the relevant properties.
67346734
void buildLambdaScope(sema::LambdaScopeInfo *LSI,

clang/lib/AST/ASTImporter.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,8 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
28542854
return CDeclOrErr.takeError();
28552855
D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr,
28562856
DCXX->hasKnownLambdaInternalLinkage());
2857+
D2CXX->setDeviceLambdaManglingNumber(
2858+
DCXX->getDeviceLambdaManglingNumber());
28572859
} else if (DCXX->isInjectedClassName()) {
28582860
// We have to be careful to do a similar dance to the one in
28592861
// Sema::ActOnStartCXXMemberDeclarations

clang/lib/AST/CXXABI.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ class ASTContext;
2222
class CXXConstructorDecl;
2323
class DeclaratorDecl;
2424
class Expr;
25-
class MemberPointerType;
25+
class MangleContext;
2626
class MangleNumberingContext;
27+
class MemberPointerType;
2728

2829
/// Implements C++ ABI-specific semantic analysis functions.
2930
class CXXABI {
@@ -75,6 +76,8 @@ class CXXABI {
7576
/// Creates an instance of a C++ ABI class.
7677
CXXABI *CreateItaniumCXXABI(ASTContext &Ctx);
7778
CXXABI *CreateMicrosoftCXXABI(ASTContext &Ctx);
79+
std::unique_ptr<MangleNumberingContext>
80+
createItaniumNumberingContext(MangleContext *);
7881
}
7982

8083
#endif

0 commit comments

Comments
 (0)