Skip to content

Commit dc8257b

Browse files
committed
Merge from 'master' to 'sycl-web' (#1)
2 parents 26f5fb4 + 876bb86 commit dc8257b

File tree

1,937 files changed

+93758
-8062
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,937 files changed

+93758
-8062
lines changed

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

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ SpecialMemberFunctionsCheck::SpecialMemberFunctionsCheck(
2525
StringRef Name, ClangTidyContext *Context)
2626
: ClangTidyCheck(Name, Context),
2727
AllowMissingMoveFunctions(Options.get("AllowMissingMoveFunctions", 0)),
28-
AllowSoleDefaultDtor(Options.get("AllowSoleDefaultDtor", 0)) {}
28+
AllowSoleDefaultDtor(Options.get("AllowSoleDefaultDtor", 0)),
29+
AllowMissingMoveFunctionsWhenCopyIsDeleted(
30+
Options.get("AllowMissingMoveFunctionsWhenCopyIsDeleted", 0)) {}
2931

3032
void SpecialMemberFunctionsCheck::storeOptions(
3133
ClangTidyOptions::OptionMap &Opts) {
3234
Options.store(Opts, "AllowMissingMoveFunctions", AllowMissingMoveFunctions);
3335
Options.store(Opts, "AllowSoleDefaultDtor", AllowSoleDefaultDtor);
36+
Options.store(Opts, "AllowMissingMoveFunctionsWhenCopyIsDeleted",
37+
AllowMissingMoveFunctionsWhenCopyIsDeleted);
3438
}
3539

3640
void SpecialMemberFunctionsCheck::registerMatchers(MatchFinder *Finder) {
@@ -103,17 +107,18 @@ void SpecialMemberFunctionsCheck::check(
103107

104108
ClassDefId ID(MatchedDecl->getLocation(), std::string(MatchedDecl->getName()));
105109

106-
auto StoreMember = [this, &ID](SpecialMemberFunctionKind Kind) {
107-
llvm::SmallVectorImpl<SpecialMemberFunctionKind> &Members =
110+
auto StoreMember = [this, &ID](SpecialMemberFunctionData data) {
111+
llvm::SmallVectorImpl<SpecialMemberFunctionData> &Members =
108112
ClassWithSpecialMembers[ID];
109-
if (!llvm::is_contained(Members, Kind))
110-
Members.push_back(Kind);
113+
if (!llvm::is_contained(Members, data))
114+
Members.push_back(std::move(data));
111115
};
112116

113117
if (const auto *Dtor = Result.Nodes.getNodeAs<CXXMethodDecl>("dtor")) {
114-
StoreMember(Dtor->isDefaulted()
115-
? SpecialMemberFunctionKind::DefaultDestructor
116-
: SpecialMemberFunctionKind::NonDefaultDestructor);
118+
StoreMember({Dtor->isDefaulted()
119+
? SpecialMemberFunctionKind::DefaultDestructor
120+
: SpecialMemberFunctionKind::NonDefaultDestructor,
121+
Dtor->isDeleted()});
117122
}
118123

119124
std::initializer_list<std::pair<std::string, SpecialMemberFunctionKind>>
@@ -123,8 +128,9 @@ void SpecialMemberFunctionsCheck::check(
123128
{"move-assign", SpecialMemberFunctionKind::MoveAssignment}};
124129

125130
for (const auto &KV : Matchers)
126-
if (Result.Nodes.getNodeAs<CXXMethodDecl>(KV.first)) {
127-
StoreMember(KV.second);
131+
if (const auto *MethodDecl =
132+
Result.Nodes.getNodeAs<CXXMethodDecl>(KV.first)) {
133+
StoreMember({KV.second, MethodDecl->isDeleted()});
128134
}
129135
}
130136

@@ -136,11 +142,19 @@ void SpecialMemberFunctionsCheck::onEndOfTranslationUnit() {
136142

137143
void SpecialMemberFunctionsCheck::checkForMissingMembers(
138144
const ClassDefId &ID,
139-
llvm::ArrayRef<SpecialMemberFunctionKind> DefinedMembers) {
145+
llvm::ArrayRef<SpecialMemberFunctionData> DefinedMembers) {
140146
llvm::SmallVector<SpecialMemberFunctionKind, 5> MissingMembers;
141147

142148
auto HasMember = [&](SpecialMemberFunctionKind Kind) {
143-
return llvm::is_contained(DefinedMembers, Kind);
149+
return llvm::any_of(DefinedMembers, [Kind](const auto &data) {
150+
return data.FunctionKind == Kind;
151+
});
152+
};
153+
154+
auto IsDeleted = [&](SpecialMemberFunctionKind Kind) {
155+
return llvm::any_of(DefinedMembers, [Kind](const auto &data) {
156+
return data.FunctionKind == Kind && data.IsDeleted;
157+
});
144158
};
145159

146160
auto RequireMember = [&](SpecialMemberFunctionKind Kind) {
@@ -171,16 +185,23 @@ void SpecialMemberFunctionsCheck::checkForMissingMembers(
171185
RequireMember(SpecialMemberFunctionKind::CopyAssignment);
172186
}
173187

174-
if (RequireFive) {
188+
if (RequireFive &&
189+
!(AllowMissingMoveFunctionsWhenCopyIsDeleted &&
190+
(IsDeleted(SpecialMemberFunctionKind::CopyConstructor) &&
191+
IsDeleted(SpecialMemberFunctionKind::CopyAssignment)))) {
175192
assert(RequireThree);
176193
RequireMember(SpecialMemberFunctionKind::MoveConstructor);
177194
RequireMember(SpecialMemberFunctionKind::MoveAssignment);
178195
}
179196

180-
if (!MissingMembers.empty())
197+
if (!MissingMembers.empty()) {
198+
llvm::SmallVector<SpecialMemberFunctionKind, 5> DefinedMemberKinds;
199+
llvm::transform(DefinedMembers, std::back_inserter(DefinedMemberKinds),
200+
[](const auto &data) { return data.FunctionKind; });
181201
diag(ID.first, "class '%0' defines %1 but does not define %2")
182-
<< ID.second << cppcoreguidelines::join(DefinedMembers, " and ")
202+
<< ID.second << cppcoreguidelines::join(DefinedMemberKinds, " and ")
183203
<< cppcoreguidelines::join(MissingMembers, " or ");
204+
}
184205
}
185206

186207
} // namespace cppcoreguidelines

clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,30 @@ class SpecialMemberFunctionsCheck : public ClangTidyCheck {
4343
MoveAssignment
4444
};
4545

46+
struct SpecialMemberFunctionData {
47+
SpecialMemberFunctionKind FunctionKind;
48+
bool IsDeleted;
49+
50+
bool operator==(const SpecialMemberFunctionData &Other) {
51+
return (Other.FunctionKind == FunctionKind) &&
52+
(Other.IsDeleted == IsDeleted);
53+
}
54+
};
55+
4656
using ClassDefId = std::pair<SourceLocation, std::string>;
4757

4858
using ClassDefiningSpecialMembersMap =
4959
llvm::DenseMap<ClassDefId,
50-
llvm::SmallVector<SpecialMemberFunctionKind, 5>>;
60+
llvm::SmallVector<SpecialMemberFunctionData, 5>>;
5161

5262
private:
5363
void checkForMissingMembers(
5464
const ClassDefId &ID,
55-
llvm::ArrayRef<SpecialMemberFunctionKind> DefinedSpecialMembers);
65+
llvm::ArrayRef<SpecialMemberFunctionData> DefinedSpecialMembers);
5666

5767
const bool AllowMissingMoveFunctions;
5868
const bool AllowSoleDefaultDtor;
69+
const bool AllowMissingMoveFunctionsWhenCopyIsDeleted;
5970
ClassDefiningSpecialMembersMap ClassWithSpecialMembers;
6071
};
6172

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,14 @@ StringRef LoopConvertCheck::getContainerString(ASTContext *Context,
649649
const ForStmt *Loop,
650650
const Expr *ContainerExpr) {
651651
StringRef ContainerString;
652-
if (isa<CXXThisExpr>(ContainerExpr->IgnoreParenImpCasts())) {
652+
ContainerExpr = ContainerExpr->IgnoreParenImpCasts();
653+
if (isa<CXXThisExpr>(ContainerExpr)) {
653654
ContainerString = "this";
654655
} else {
656+
// For CXXOperatorCallExpr (e.g. vector_ptr->size()), its first argument is
657+
// the class object (vector_ptr) we are targeting.
658+
if (const auto* E = dyn_cast<CXXOperatorCallExpr>(ContainerExpr))
659+
ContainerExpr = E->getArg(0);
655660
ContainerString =
656661
getStringFromRange(Context->getSourceManager(), Context->getLangOpts(),
657662
ContainerExpr->getSourceRange());

clang-tools-extra/clangd/unittests/SelectionTests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,14 @@ TEST(SelectionTest, CommonAncestor) {
380380
{"struct foo { [[^~foo()]]; };", "CXXDestructorDecl"},
381381
// FIXME: The following to should be class itself instead.
382382
{"struct foo { [[fo^o(){}]] };", "CXXConstructorDecl"},
383+
384+
{R"cpp(
385+
struct S1 { void f(); };
386+
struct S2 { S1 * operator->(); };
387+
void test(S2 s2) {
388+
s2[[-^>]]f();
389+
}
390+
)cpp", "DeclRefExpr"} // DeclRefExpr to the "operator->" method.
383391
};
384392
for (const Case &C : Cases) {
385393
Annotations Test(C.Code);

clang-tools-extra/clangd/unittests/XRefsTests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,14 @@ TEST(LocateSymbol, All) {
452452
}
453453
)cpp",
454454

455+
R"cpp(
456+
struct S1 { void f(); };
457+
struct S2 { S1 * $decl[[operator]]->(); };
458+
void test(S2 s2) {
459+
s2-^>f();
460+
}
461+
)cpp",
462+
455463
R"cpp(// Declaration of explicit template specialization
456464
template <typename T>
457465
struct $decl[[Foo]] {};

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-special-member-functions.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,19 @@ Options
4646
A(const A&);
4747
A& operator=(const A&);
4848
~A();
49-
}
49+
};
50+
51+
.. option:: AllowMissingMoveFunctionsWhenCopyIsDeleted
52+
53+
When set to `1` (default is `0`), this check doesn't flag classes which define deleted copy
54+
operations but don't define move operations. This flags is related to Google C++ Style Guide
55+
https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types. With this option enabled, the
56+
following class won't be flagged:
57+
58+
.. code-block:: c++
59+
60+
struct A {
61+
A(const A&) = delete;
62+
A& operator=(const A&) = delete;
63+
~A();
64+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: %check_clang_tidy %s cppcoreguidelines-special-member-functions %t -- -config="{CheckOptions: [{key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted, value: 1}]}" --
2+
3+
class DefinesEverything {
4+
DefinesEverything(const DefinesEverything &);
5+
DefinesEverything(DefinesEverything &&);
6+
DefinesEverything &operator=(const DefinesEverything &);
7+
DefinesEverything &operator=(DefinesEverything &&);
8+
~DefinesEverything();
9+
};
10+
11+
class DefinesNothing {
12+
};
13+
14+
class DeletedCopyCtorAndOperator {
15+
~DeletedCopyCtorAndOperator() = default;
16+
DeletedCopyCtorAndOperator(const DeletedCopyCtorAndOperator &) = delete;
17+
DeletedCopyCtorAndOperator &operator=(const DeletedCopyCtorAndOperator &) = delete;
18+
};
19+
20+
// CHECK-MESSAGES: [[@LINE+1]]:7: warning: class 'DefaultedCopyCtorAndOperator' defines a default destructor, a copy constructor and a copy assignment operator but does not define a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
21+
class DefaultedCopyCtorAndOperator {
22+
~DefaultedCopyCtorAndOperator() = default;
23+
DefaultedCopyCtorAndOperator(const DefaultedCopyCtorAndOperator &) = default;
24+
DefaultedCopyCtorAndOperator &operator=(const DefaultedCopyCtorAndOperator &) = default;
25+
};
26+
27+
// CHECK-MESSAGES: [[@LINE+1]]:7: warning: class 'DefinedCopyCtorAndOperator' defines a default destructor, a copy constructor and a copy assignment operator but does not define a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
28+
class DefinedCopyCtorAndOperator {
29+
~DefinedCopyCtorAndOperator() = default;
30+
DefinedCopyCtorAndOperator(const DefinedCopyCtorAndOperator &);
31+
DefinedCopyCtorAndOperator &operator=(const DefinedCopyCtorAndOperator &);
32+
};
33+
34+
// CHECK-MESSAGES: [[@LINE+1]]:7: warning: class 'MissingCopyCtor' defines a default destructor and a copy assignment operator but does not define a copy constructor, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
35+
class MissingCopyCtor {
36+
~MissingCopyCtor() = default;
37+
MissingCopyCtor &operator=(const MissingCopyCtor &) = delete;
38+
};
39+
40+
// CHECK-MESSAGES: [[@LINE+1]]:7: warning: class 'MissingCopyOperator' defines a default destructor and a copy constructor but does not define a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
41+
class MissingCopyOperator {
42+
~MissingCopyOperator() = default;
43+
MissingCopyOperator(const MissingCopyOperator &) = delete;
44+
};
45+
46+
// CHECK-MESSAGES: [[@LINE+1]]:7: warning: class 'MissingAll' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
47+
class MissingAll {
48+
~MissingAll() = default;
49+
};

clang/include/clang/AST/ASTContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,12 @@ class ASTContext : public RefCountedBase<ASTContext> {
12751275
/// Returns a vla type where known sizes are replaced with [*].
12761276
QualType getVariableArrayDecayedType(QualType Ty) const;
12771277

1278+
/// Return the unique reference to a scalable vector type of the specified
1279+
/// element type and scalable number of elements.
1280+
///
1281+
/// \pre \p EltTy must be a built-in type.
1282+
QualType getScalableVectorType(QualType EltTy, unsigned NumElts) const;
1283+
12781284
/// Return the unique reference to a vector type of the specified
12791285
/// element type and size.
12801286
///

0 commit comments

Comments
 (0)