Skip to content

Commit 8ecece4

Browse files
committed
Merge branch 'main' into scf_for_distr_bug_fix
2 parents 537ca0e + 1431f8f commit 8ecece4

File tree

752 files changed

+23291
-10724
lines changed

Some content is hidden

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

752 files changed

+23291
-10724
lines changed

clang-tools-extra/clang-tidy/ClangTidy.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ namespace clang::tidy {
5555

5656
namespace {
5757
#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
58+
#define ANALYZER_CHECK_NAME_PREFIX "clang-analyzer-"
5859
static constexpr llvm::StringLiteral AnalyzerCheckNamePrefix =
59-
"clang-analyzer-";
60+
ANALYZER_CHECK_NAME_PREFIX;
6061

6162
class AnalyzerDiagnosticConsumer : public ento::PathDiagnosticConsumer {
6263
public:
@@ -669,18 +670,19 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) {
669670
Buffer.append(AnalyzerCheck);
670671
Result.Checks.insert(Buffer);
671672
}
672-
for (std::string OptionName : {
673+
674+
static constexpr llvm::StringLiteral OptionNames[] = {
673675
#define GET_CHECKER_OPTIONS
674676
#define CHECKER_OPTION(TYPE, CHECKER, OPTION_NAME, DESCRIPTION, DEFAULT, \
675677
RELEASE, HIDDEN) \
676-
Twine(AnalyzerCheckNamePrefix).concat(CHECKER ":" OPTION_NAME).str(),
678+
ANALYZER_CHECK_NAME_PREFIX CHECKER ":" OPTION_NAME,
677679

678680
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
679681
#undef CHECKER_OPTION
680682
#undef GET_CHECKER_OPTIONS
681-
}) {
682-
Result.Options.insert(OptionName);
683-
}
683+
};
684+
685+
Result.Options.insert_range(OptionNames);
684686
#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER
685687

686688
Context.setOptionsCollector(&Result.Options);

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

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,21 @@ using namespace llvm;
2020

2121
namespace clang::tidy::modernize {
2222

23+
static bool isFirstFriendOfSecond(const CXXRecordDecl *Friend,
24+
const CXXRecordDecl *Class) {
25+
return llvm::any_of(
26+
Class->friends(), [Friend](FriendDecl *FriendDecl) -> bool {
27+
if (TypeSourceInfo *FriendTypeSource = FriendDecl->getFriendType()) {
28+
const QualType FriendType = FriendTypeSource->getType();
29+
return FriendType->getAsCXXRecordDecl() == Friend;
30+
}
31+
return false;
32+
});
33+
}
34+
2335
namespace {
24-
/// Matches move-constructible classes.
36+
/// Matches move-constructible classes whose constructor can be called inside
37+
/// a CXXRecordDecl with a bound ID.
2538
///
2639
/// Given
2740
/// \code
@@ -32,15 +45,33 @@ namespace {
3245
/// Bar(Bar &&) = deleted;
3346
/// int a;
3447
/// };
48+
///
49+
/// class Buz {
50+
/// Buz(Buz &&);
51+
/// int a;
52+
/// friend class Outer;
53+
/// };
54+
///
55+
/// class Outer {
56+
/// };
3557
/// \endcode
36-
/// recordDecl(isMoveConstructible())
37-
/// matches "Foo".
38-
AST_MATCHER(CXXRecordDecl, isMoveConstructible) {
39-
for (const CXXConstructorDecl *Ctor : Node.ctors()) {
40-
if (Ctor->isMoveConstructor() && !Ctor->isDeleted())
41-
return true;
42-
}
43-
return false;
58+
/// recordDecl(isMoveConstructibleInBoundCXXRecordDecl("Outer"))
59+
/// matches "Foo", "Buz".
60+
AST_MATCHER_P(CXXRecordDecl, isMoveConstructibleInBoundCXXRecordDecl, StringRef,
61+
RecordDeclID) {
62+
return Builder->removeBindings(
63+
[this,
64+
&Node](const ast_matchers::internal::BoundNodesMap &Nodes) -> bool {
65+
const auto *BoundClass =
66+
Nodes.getNode(this->RecordDeclID).get<CXXRecordDecl>();
67+
for (const CXXConstructorDecl *Ctor : Node.ctors()) {
68+
if (Ctor->isMoveConstructor() && !Ctor->isDeleted() &&
69+
(Ctor->getAccess() == AS_public ||
70+
(BoundClass && isFirstFriendOfSecond(BoundClass, &Node))))
71+
return false;
72+
}
73+
return true;
74+
});
4475
}
4576
} // namespace
4677

@@ -202,6 +233,7 @@ void PassByValueCheck::registerMatchers(MatchFinder *Finder) {
202233
traverse(
203234
TK_AsIs,
204235
cxxConstructorDecl(
236+
ofClass(cxxRecordDecl().bind("outer")),
205237
forEachConstructorInitializer(
206238
cxxCtorInitializer(
207239
unless(isBaseInitializer()),
@@ -225,8 +257,9 @@ void PassByValueCheck::registerMatchers(MatchFinder *Finder) {
225257
.bind("Param"))))),
226258
hasDeclaration(cxxConstructorDecl(
227259
isCopyConstructor(), unless(isDeleted()),
228-
hasDeclContext(
229-
cxxRecordDecl(isMoveConstructible())))))))
260+
hasDeclContext(cxxRecordDecl(
261+
isMoveConstructibleInBoundCXXRecordDecl(
262+
"outer"))))))))
230263
.bind("Initializer")))
231264
.bind("Ctor")),
232265
this);

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ using namespace clang::ast_matchers;
1515

1616
namespace clang::tidy::modernize {
1717

18+
// FIXME: Add chrono::treat_as_floating_point_v and chrono::is_clock_v.
19+
// This will require restructuring the code to handle type traits not
20+
// defined directly in std.
1821
static const llvm::StringSet<> ValueTraits = {
1922
"alignment_of",
2023
"conjunction",
@@ -28,6 +31,7 @@ static const llvm::StringSet<> ValueTraits = {
2831
"is_array",
2932
"is_assignable",
3033
"is_base_of",
34+
"is_bind_expression",
3135
"is_bounded_array",
3236
"is_class",
3337
"is_compound",
@@ -40,10 +44,14 @@ static const llvm::StringSet<> ValueTraits = {
4044
"is_destructible",
4145
"is_empty",
4246
"is_enum",
47+
"is_error_code_enum",
48+
"is_error_condition_enum",
49+
"is_execution_policy",
4350
"is_final",
4451
"is_floating_point",
4552
"is_function",
4653
"is_fundamental",
54+
"is_implicit_lifetime",
4755
"is_integral",
4856
"is_invocable",
4957
"is_invocable_r",
@@ -65,14 +73,17 @@ static const llvm::StringSet<> ValueTraits = {
6573
"is_nothrow_invocable_r",
6674
"is_nothrow_move_assignable",
6775
"is_nothrow_move_constructible",
76+
"is_nothrow_relocatable",
6877
"is_nothrow_swappable",
6978
"is_nothrow_swappable_with",
7079
"is_null_pointer",
7180
"is_object",
81+
"is_placeholder",
7282
"is_pointer",
7383
"is_pointer_interconvertible_base_of",
7484
"is_polymorphic",
7585
"is_reference",
86+
"is_replaceable",
7687
"is_rvalue_reference",
7788
"is_same",
7889
"is_scalar",
@@ -91,15 +102,26 @@ static const llvm::StringSet<> ValueTraits = {
91102
"is_trivially_destructible",
92103
"is_trivially_move_assignable",
93104
"is_trivially_move_constructible",
105+
"is_trivially_relocatable",
94106
"is_unbounded_array",
95107
"is_union",
96108
"is_unsigned",
109+
"is_virtual_base_of",
97110
"is_void",
98111
"is_volatile",
99112
"negation",
100113
"rank",
114+
"ratio_equal",
115+
"ratio_greater_equal",
116+
"ratio_greater",
117+
"ratio_less_equal",
118+
"ratio_less",
119+
"ratio_not_equal",
101120
"reference_constructs_from_temporary",
102121
"reference_converts_from_temporary",
122+
"tuple_size",
123+
"uses_allocator",
124+
"variant_size",
103125
};
104126

105127
static const llvm::StringSet<> TypeTraits = {
@@ -130,6 +152,12 @@ static const llvm::StringSet<> TypeTraits = {
130152
"result_of",
131153
"invoke_result",
132154
"type_identity",
155+
"compare_three_way_result",
156+
"common_comparison_category",
157+
"unwrap_ref_decay",
158+
"unwrap_reference",
159+
"tuple_element",
160+
"variant_alternative",
133161
};
134162

135163
static DeclarationName getName(const DependentScopeDeclRefExpr &D) {

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ Changes in existing checks
281281
excluding variables with ``thread_local`` storage class specifier from being
282282
matched.
283283

284+
- Improved :doc:`modernize-pass-by-value
285+
<clang-tidy/checks/modernize/pass-by-value>` check by fixing false positives
286+
when class passed by const-reference had a private move constructor.
287+
288+
- Improved :doc:`modernize-type-traits
289+
<clang-tidy/checks/modernize/type-traits>` check by detecting more type traits.
290+
284291
- Improved :doc:`modernize-use-default-member-init
285292
<clang-tidy/checks/modernize/use-default-member-init>` check by matching
286293
arithmetic operations, ``constexpr`` and ``static`` values, and detecting

clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,10 @@ Options
3838
#define IS_SIGNED(T) std::is_signed<T>::value
3939

4040
Defaults to `false`.
41+
42+
Limitations
43+
-----------
44+
45+
Does not currently diagnose uses of type traits with nested name
46+
specifiers (e.g. ``std::chrono::is_clock``,
47+
``std::chrono::treat_as_floating_point``).

clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,62 @@ struct W3 {
252252
W3(W1 &&, Movable &&M);
253253
Movable M;
254254
};
255+
256+
struct ProtectedMovable {
257+
ProtectedMovable() = default;
258+
ProtectedMovable(const ProtectedMovable &) {}
259+
protected:
260+
ProtectedMovable(ProtectedMovable &&) {}
261+
};
262+
263+
struct PrivateMovable {
264+
PrivateMovable() = default;
265+
PrivateMovable(const PrivateMovable &) {}
266+
private:
267+
PrivateMovable(PrivateMovable &&) {}
268+
269+
friend struct X5;
270+
};
271+
272+
struct InheritedProtectedMovable : ProtectedMovable {
273+
InheritedProtectedMovable() = default;
274+
InheritedProtectedMovable(const InheritedProtectedMovable &) {}
275+
InheritedProtectedMovable(InheritedProtectedMovable &&) {}
276+
};
277+
278+
struct InheritedPrivateMovable : PrivateMovable {
279+
InheritedPrivateMovable() = default;
280+
InheritedPrivateMovable(const InheritedPrivateMovable &) {}
281+
InheritedPrivateMovable(InheritedPrivateMovable &&) {}
282+
};
283+
284+
struct X1 {
285+
X1(const ProtectedMovable &M) : M(M) {}
286+
ProtectedMovable M;
287+
};
288+
289+
struct X2 {
290+
X2(const PrivateMovable &M) : M(M) {}
291+
PrivateMovable M;
292+
};
293+
294+
struct X3 {
295+
X3(const InheritedProtectedMovable &M) : M(M) {}
296+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: pass by value and use std::move
297+
// CHECK-FIXES: X3(InheritedProtectedMovable M) : M(std::move(M)) {}
298+
InheritedProtectedMovable M;
299+
};
300+
301+
struct X4 {
302+
X4(const InheritedPrivateMovable &M) : M(M) {}
303+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: pass by value and use std::move
304+
// CHECK-FIXES: X4(InheritedPrivateMovable M) : M(std::move(M)) {}
305+
InheritedPrivateMovable M;
306+
};
307+
308+
struct X5 {
309+
X5(const PrivateMovable &M) : M(M) {}
310+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: pass by value and use std::move
311+
// CHECK-FIXES: X5(PrivateMovable M) : M(std::move(M)) {}
312+
PrivateMovable M;
313+
};

clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %check_clang_tidy -std=c++14 %s modernize-type-traits %t -check-suffixes=',MACRO'
22
// RUN: %check_clang_tidy -std=c++14 %s modernize-type-traits %t -- \
33
// RUN: -config='{CheckOptions: {modernize-type-traits.IgnoreMacros: true}}'
4-
// RUN: %check_clang_tidy -std=c++17 %s modernize-type-traits %t -check-suffixes=',CXX17,MACRO,CXX17MACRO'
4+
// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-type-traits %t -check-suffixes=',CXX17,MACRO,CXX17MACRO'
55

66
namespace std {
77
template <typename>
@@ -19,6 +19,11 @@ namespace std {
1919
using type = T;
2020
};
2121

22+
template <typename...>
23+
struct common_type {
24+
using type = int;
25+
};
26+
2227
inline namespace __std_lib_version1 {
2328
template<typename T>
2429
struct add_const {
@@ -66,6 +71,10 @@ using UsingNoTypename = std::enable_if<true>::type;
6671
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use c++14 style type templates
6772
// CHECK-FIXES: using UsingNoTypename = std::enable_if_t<true>;
6873

74+
using VariadicTrait = std::common_type<int, long, bool>::type;
75+
// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: use c++14 style type templates
76+
// CHECK-FIXES: using VariadicTrait = std::common_type_t<int, long, bool>;
77+
6978
using UsingSpace = std::enable_if <true>::type;
7079
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use c++14 style type templates
7180
// CHECK-FIXES: using UsingSpace = std::enable_if_t <true>;

clang/Maintainers.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Clang MLIR generation
5959
| Bruno Cardoso Lopes
6060
| bruno.cardoso\@gmail.com (email), sonicsprawl (Discord), bcardosolopes (GitHub)
6161
62+
| Henrich Lauko
63+
| henrich.lau\@gmail.com (email), henrich.lauko (Discord), xlauko (GitHub)
6264
6365
Analysis & CFG
6466
~~~~~~~~~~~~~~

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,11 @@ Bug Fixes in This Version
767767
flag and diagnostic because the macro injection was used to emit this warning.
768768
Unfortunately there is no other good way to diagnose usage of ``static_assert``
769769
macro without inclusion of ``<assert.h>``.
770+
- In C23, something like ``[[/*possible attributes*/]];`` is an attribute
771+
declaration, not a statement. So it is not allowed by the syntax in places
772+
where a statement is required, specifically as the secondary block of a
773+
selection or iteration statement. This differs from C++, since C++ allows
774+
declaration statements. Clang now emits a warning for these patterns. (#GH141659)
770775

771776
Bug Fixes to Compiler Builtins
772777
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)