Skip to content

Commit 79adbbe

Browse files
authored
Merge branch 'main' into fix/111854
2 parents ad1ed80 + ea3534b commit 79adbbe

File tree

1,787 files changed

+224939
-11663
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,787 files changed

+224939
-11663
lines changed

bolt/lib/Core/DIEBuilder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ void DIEBuilder::buildTypeUnits(DebugStrOffsetsWriter *StrOffsetWriter,
281281
for (auto &Row : TUIndex.getRows()) {
282282
uint64_t Signature = Row.getSignature();
283283
// manually populate TypeUnit to UnitVector
284-
DwarfContext->getTypeUnitForHash(DwarfContext->getMaxVersion(), Signature,
285-
true);
284+
DwarfContext->getTypeUnitForHash(Signature, true);
286285
}
287286
}
288287
const unsigned int CUNum = getCUNum(DwarfContext, isDWO());

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ clang_target_link_libraries(clangTidy
3535
clangFrontend
3636
clangLex
3737
clangRewrite
38-
clangSema
3938
clangSerialization
4039
clangTooling
4140
clangToolingCore

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ class ClangTidyASTConsumer : public MultiplexConsumer {
336336
std::unique_ptr<ClangTidyProfiling> Profiling;
337337
std::unique_ptr<ast_matchers::MatchFinder> Finder;
338338
std::vector<std::unique_ptr<ClangTidyCheck>> Checks;
339+
void anchor() override {};
339340
};
340341

341342
} // namespace

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ void ProTypeUnionAccessCheck::registerMatchers(MatchFinder *Finder) {
2323

2424
void ProTypeUnionAccessCheck::check(const MatchFinder::MatchResult &Result) {
2525
const auto *Matched = Result.Nodes.getNodeAs<MemberExpr>("expr");
26-
diag(Matched->getMemberLoc(),
27-
"do not access members of unions; use (boost::)variant instead");
26+
SourceLocation Loc = Matched->getMemberLoc();
27+
if (Loc.isInvalid())
28+
Loc = Matched->getBeginLoc();
29+
diag(Loc, "do not access members of unions; consider using (boost::)variant "
30+
"instead");
2831
}
2932

3033
} // namespace clang::tidy::cppcoreguidelines

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,25 +172,25 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
172172

173173
using namespace utils::fixit;
174174
if (VC == VariableCategory::Value && TransformValues) {
175-
Diag << addQualifierToVarDecl(*Variable, *Result.Context,
176-
DeclSpec::TQ_const, QualifierTarget::Value,
175+
Diag << addQualifierToVarDecl(*Variable, *Result.Context, Qualifiers::Const,
176+
QualifierTarget::Value,
177177
QualifierPolicy::Right);
178178
// FIXME: Add '{}' for default initialization if no user-defined default
179179
// constructor exists and there is no initializer.
180180
return;
181181
}
182182

183183
if (VC == VariableCategory::Reference && TransformReferences) {
184-
Diag << addQualifierToVarDecl(*Variable, *Result.Context,
185-
DeclSpec::TQ_const, QualifierTarget::Value,
184+
Diag << addQualifierToVarDecl(*Variable, *Result.Context, Qualifiers::Const,
185+
QualifierTarget::Value,
186186
QualifierPolicy::Right);
187187
return;
188188
}
189189

190190
if (VC == VariableCategory::Pointer) {
191191
if (WarnPointersAsValues && TransformPointersAsValues) {
192192
Diag << addQualifierToVarDecl(*Variable, *Result.Context,
193-
DeclSpec::TQ_const, QualifierTarget::Value,
193+
Qualifiers::Const, QualifierTarget::Value,
194194
QualifierPolicy::Right);
195195
}
196196
return;

clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ bool ForRangeCopyCheck::handleConstValueCopy(const VarDecl &LoopVar,
9191
<< utils::fixit::changeVarDeclToReference(LoopVar, Context);
9292
if (!LoopVar.getType().isConstQualified()) {
9393
if (std::optional<FixItHint> Fix = utils::fixit::addQualifierToVarDecl(
94-
LoopVar, Context, DeclSpec::TQ::TQ_const))
94+
LoopVar, Context, Qualifiers::Const))
9595
Diagnostic << *Fix;
9696
}
9797
return true;
@@ -129,7 +129,7 @@ bool ForRangeCopyCheck::handleCopyIsOnlyConstReferenced(
129129
"making it a const reference");
130130

131131
if (std::optional<FixItHint> Fix = utils::fixit::addQualifierToVarDecl(
132-
LoopVar, Context, DeclSpec::TQ::TQ_const))
132+
LoopVar, Context, Qualifiers::Const))
133133
Diag << *Fix << utils::fixit::changeVarDeclToReference(LoopVar, Context);
134134

135135
return true;

clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void recordFixes(const VarDecl &Var, ASTContext &Context,
3636
Diagnostic << utils::fixit::changeVarDeclToReference(Var, Context);
3737
if (!Var.getType().isLocalConstQualified()) {
3838
if (std::optional<FixItHint> Fix = utils::fixit::addQualifierToVarDecl(
39-
Var, Context, DeclSpec::TQ::TQ_const))
39+
Var, Context, Qualifiers::Const))
4040
Diagnostic << *Fix;
4141
}
4242
}

clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void UnnecessaryValueParamCheck::handleConstRefFix(const FunctionDecl &Function,
172172
// declaration.
173173
if (!CurrentParam.getType().getCanonicalType().isConstQualified()) {
174174
if (std::optional<FixItHint> Fix = utils::fixit::addQualifierToVarDecl(
175-
CurrentParam, Context, DeclSpec::TQ::TQ_const))
175+
CurrentParam, Context, Qualifiers::Const))
176176
Diag << *Fix;
177177
}
178178
}

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,44 +62,44 @@ void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
6262
.bind("positiveComparison"),
6363
this);
6464
AddSimpleMatcher(
65-
binaryOperator(hasOperatorName("!="), hasOperands(CountCall, Literal0))
65+
binaryOperation(hasOperatorName("!="), hasOperands(CountCall, Literal0))
6666
.bind("positiveComparison"));
6767
AddSimpleMatcher(
68-
binaryOperator(hasLHS(CountCall), hasOperatorName(">"), hasRHS(Literal0))
68+
binaryOperation(hasLHS(CountCall), hasOperatorName(">"), hasRHS(Literal0))
6969
.bind("positiveComparison"));
7070
AddSimpleMatcher(
71-
binaryOperator(hasLHS(Literal0), hasOperatorName("<"), hasRHS(CountCall))
72-
.bind("positiveComparison"));
73-
AddSimpleMatcher(
74-
binaryOperator(hasLHS(CountCall), hasOperatorName(">="), hasRHS(Literal1))
75-
.bind("positiveComparison"));
76-
AddSimpleMatcher(
77-
binaryOperator(hasLHS(Literal1), hasOperatorName("<="), hasRHS(CountCall))
71+
binaryOperation(hasLHS(Literal0), hasOperatorName("<"), hasRHS(CountCall))
7872
.bind("positiveComparison"));
73+
AddSimpleMatcher(binaryOperation(hasLHS(CountCall), hasOperatorName(">="),
74+
hasRHS(Literal1))
75+
.bind("positiveComparison"));
76+
AddSimpleMatcher(binaryOperation(hasLHS(Literal1), hasOperatorName("<="),
77+
hasRHS(CountCall))
78+
.bind("positiveComparison"));
7979

8080
// Find inverted membership tests which use `count()`.
8181
AddSimpleMatcher(
82-
binaryOperator(hasOperatorName("=="), hasOperands(CountCall, Literal0))
83-
.bind("negativeComparison"));
84-
AddSimpleMatcher(
85-
binaryOperator(hasLHS(CountCall), hasOperatorName("<="), hasRHS(Literal0))
86-
.bind("negativeComparison"));
87-
AddSimpleMatcher(
88-
binaryOperator(hasLHS(Literal0), hasOperatorName(">="), hasRHS(CountCall))
82+
binaryOperation(hasOperatorName("=="), hasOperands(CountCall, Literal0))
8983
.bind("negativeComparison"));
84+
AddSimpleMatcher(binaryOperation(hasLHS(CountCall), hasOperatorName("<="),
85+
hasRHS(Literal0))
86+
.bind("negativeComparison"));
87+
AddSimpleMatcher(binaryOperation(hasLHS(Literal0), hasOperatorName(">="),
88+
hasRHS(CountCall))
89+
.bind("negativeComparison"));
9090
AddSimpleMatcher(
91-
binaryOperator(hasLHS(CountCall), hasOperatorName("<"), hasRHS(Literal1))
91+
binaryOperation(hasLHS(CountCall), hasOperatorName("<"), hasRHS(Literal1))
9292
.bind("negativeComparison"));
9393
AddSimpleMatcher(
94-
binaryOperator(hasLHS(Literal1), hasOperatorName(">"), hasRHS(CountCall))
94+
binaryOperation(hasLHS(Literal1), hasOperatorName(">"), hasRHS(CountCall))
9595
.bind("negativeComparison"));
9696

9797
// Find membership tests based on `find() == end()`.
9898
AddSimpleMatcher(
99-
binaryOperator(hasOperatorName("!="), hasOperands(FindCall, EndCall))
99+
binaryOperation(hasOperatorName("!="), hasOperands(FindCall, EndCall))
100100
.bind("positiveComparison"));
101101
AddSimpleMatcher(
102-
binaryOperator(hasOperatorName("=="), hasOperands(FindCall, EndCall))
102+
binaryOperation(hasOperatorName("=="), hasOperands(FindCall, EndCall))
103103
.bind("negativeComparison"));
104104
}
105105

clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "clang/AST/ASTContext.h"
1212
#include "clang/AST/ExprCXX.h"
1313
#include "clang/AST/Type.h"
14+
#include "clang/Sema/DeclSpec.h"
1415
#include "clang/Tooling/FixIt.h"
1516
#include <optional>
1617

@@ -71,15 +72,17 @@ static std::optional<FixItHint> fixIfNotDangerous(SourceLocation Loc,
7172

7273
// Build a string that can be emitted as FixIt with either a space in before
7374
// or after the qualifier, either ' const' or 'const '.
74-
static std::string buildQualifier(DeclSpec::TQ Qualifier,
75+
static std::string buildQualifier(Qualifiers::TQ Qualifier,
7576
bool WhitespaceBefore = false) {
7677
if (WhitespaceBefore)
77-
return (llvm::Twine(' ') + DeclSpec::getSpecifierName(Qualifier)).str();
78-
return (llvm::Twine(DeclSpec::getSpecifierName(Qualifier)) + " ").str();
78+
return (llvm::Twine(' ') + Qualifiers::fromCVRMask(Qualifier).getAsString())
79+
.str();
80+
return (llvm::Twine(Qualifiers::fromCVRMask(Qualifier).getAsString()) + " ")
81+
.str();
7982
}
8083

8184
static std::optional<FixItHint> changeValue(const VarDecl &Var,
82-
DeclSpec::TQ Qualifier,
85+
Qualifiers::TQ Qualifier,
8386
QualifierTarget QualTarget,
8487
QualifierPolicy QualPolicy,
8588
const ASTContext &Context) {
@@ -99,7 +102,7 @@ static std::optional<FixItHint> changeValue(const VarDecl &Var,
99102
}
100103

101104
static std::optional<FixItHint> changePointerItself(const VarDecl &Var,
102-
DeclSpec::TQ Qualifier,
105+
Qualifiers::TQ Qualifier,
103106
const ASTContext &Context) {
104107
if (locDangerous(Var.getLocation()))
105108
return std::nullopt;
@@ -112,7 +115,7 @@ static std::optional<FixItHint> changePointerItself(const VarDecl &Var,
112115
}
113116

114117
static std::optional<FixItHint>
115-
changePointer(const VarDecl &Var, DeclSpec::TQ Qualifier, const Type *Pointee,
118+
changePointer(const VarDecl &Var, Qualifiers::TQ Qualifier, const Type *Pointee,
116119
QualifierTarget QualTarget, QualifierPolicy QualPolicy,
117120
const ASTContext &Context) {
118121
// The pointer itself shall be marked as `const`. This is always to the right
@@ -163,7 +166,7 @@ changePointer(const VarDecl &Var, DeclSpec::TQ Qualifier, const Type *Pointee,
163166
}
164167

165168
static std::optional<FixItHint>
166-
changeReferencee(const VarDecl &Var, DeclSpec::TQ Qualifier, QualType Pointee,
169+
changeReferencee(const VarDecl &Var, Qualifiers::TQ Qualifier, QualType Pointee,
167170
QualifierTarget QualTarget, QualifierPolicy QualPolicy,
168171
const ASTContext &Context) {
169172
if (QualPolicy == QualifierPolicy::Left && isValueType(Pointee))
@@ -183,7 +186,7 @@ changeReferencee(const VarDecl &Var, DeclSpec::TQ Qualifier, QualType Pointee,
183186

184187
std::optional<FixItHint> addQualifierToVarDecl(const VarDecl &Var,
185188
const ASTContext &Context,
186-
DeclSpec::TQ Qualifier,
189+
Qualifiers::TQ Qualifier,
187190
QualifierTarget QualTarget,
188191
QualifierPolicy QualPolicy) {
189192
assert((QualPolicy == QualifierPolicy::Left ||

clang-tools-extra/clang-tidy/utils/FixItHintUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "clang/AST/ASTContext.h"
1313
#include "clang/AST/Decl.h"
14-
#include "clang/Sema/DeclSpec.h"
14+
#include "clang/AST/Type.h"
1515
#include <optional>
1616

1717
namespace clang::tidy::utils::fixit {
@@ -41,7 +41,7 @@ enum class QualifierTarget {
4141
/// Requires that `Var` is isolated in written code like in `int foo = 42;`.
4242
std::optional<FixItHint>
4343
addQualifierToVarDecl(const VarDecl &Var, const ASTContext &Context,
44-
DeclSpec::TQ Qualifier,
44+
Qualifiers::TQ Qualifier,
4545
QualifierTarget QualTarget = QualifierTarget::Pointee,
4646
QualifierPolicy QualPolicy = QualifierPolicy::Left);
4747

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ Changes in existing checks
180180
avoid false positive when member initialization depends on a structured
181181
binding variable.
182182

183+
- Fixed :doc:`cppcoreguidelines-pro-type-union-access
184+
<clang-tidy/checks/cppcoreguidelines/pro-type-union-access>` check to
185+
report a location even when the member location is not valid.
186+
183187
- Improved :doc:`misc-definitions-in-headers
184188
<clang-tidy/checks/misc/definitions-in-headers>` check by rewording the
185189
diagnostic note that suggests adding ``inline``.
@@ -234,7 +238,8 @@ Changes in existing checks
234238

235239
- Improved :doc:`readability-container-contains
236240
<clang-tidy/checks/readability/container-contains>` check to let it work on
237-
any class that has a ``contains`` method.
241+
any class that has a ``contains`` method. Fix some false negatives in the
242+
``find()`` case.
238243

239244
- Improved :doc:`readability-enum-initial-value
240245
<clang-tidy/checks/readability/enum-initial-value>` check by only issuing

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-union-access.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ union U {
55
char union_member2;
66
} u;
77

8+
union W {
9+
template <class TP> operator TP *() const;
10+
};
11+
812
struct S {
913
int non_union_member;
1014
union {
@@ -20,22 +24,25 @@ void f(char);
2024
void f2(U);
2125
void f3(U&);
2226
void f4(U*);
27+
W f5();
2328

2429
void check()
2530
{
2631
u.union_member1 = true;
27-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not access members of unions; use (boost::)variant instead [cppcoreguidelines-pro-type-union-access]
32+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not access members of unions; consider using (boost::)variant instead [cppcoreguidelines-pro-type-union-access]
2833
auto b = u.union_member2;
29-
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not access members of unions; use (boost::)variant instead
34+
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not access members of unions; consider using (boost::)variant instead
3035
auto a = &s.union_member;
31-
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not access members of unions; use (boost::)variant instead
36+
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not access members of unions; consider using (boost::)variant instead
3237
f(s.u.union_member2);
33-
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not access members of unions; use (boost::)variant instead
38+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not access members of unions; consider using (boost::)variant instead
3439

3540
s.non_union_member = 2; // OK
3641

3742
U u2 = u; // OK
3843
f2(u); // OK
3944
f3(u); // OK
4045
f4(&u); // OK
46+
void *ret = f5();
47+
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not access members of unions; consider using (boost::)variant instead
4148
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
// RUN: %check_clang_tidy -std=c++20-or-later %s readability-container-contains %t
1+
// RUN: %check_clang_tidy -std=c++11-or-later %s readability-container-contains %t
22

33
// Some *very* simplified versions of `map` etc.
44
namespace std {
55

66
template <class Key, class T>
77
struct map {
8+
struct iterator {
9+
bool operator==(const iterator &Other) const;
10+
bool operator!=(const iterator &Other) const;
11+
};
12+
813
unsigned count(const Key &K) const;
914
bool contains(const Key &K) const;
10-
void *find(const Key &K);
11-
void *end();
15+
iterator find(const Key &K);
16+
iterator end();
1217
};
1318

1419
template <class Key>

clang-tools-extra/unittests/clang-tidy/AddConstTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class ConstTransform : public ClangTidyCheck {
2727
void check(const MatchFinder::MatchResult &Result) override {
2828
const auto *D = Result.Nodes.getNodeAs<VarDecl>("var");
2929
using utils::fixit::addQualifierToVarDecl;
30-
std::optional<FixItHint> Fix = addQualifierToVarDecl(
31-
*D, *Result.Context, DeclSpec::TQ::TQ_const, CT, CP);
30+
std::optional<FixItHint> Fix =
31+
addQualifierToVarDecl(*D, *Result.Context, Qualifiers::Const, CT, CP);
3232
auto Diag = diag(D->getBeginLoc(), "doing const transformation");
3333
if (Fix)
3434
Diag << *Fix;

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4663,6 +4663,14 @@ the configuration (without a prefix: ``Auto``).
46634663
**KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`<KeepEmptyLinesAtTheStartOfBlocks>`
46644664
This option is deprecated. See ``AtStartOfBlock`` of ``KeepEmptyLines``.
46654665

4666+
.. _KeepFormFeed:
4667+
4668+
**KeepFormFeed** (``Boolean``) :versionbadge:`clang-format 20` :ref:`<KeepFormFeed>`
4669+
Keep the form feed character if it's immediately preceded and followed by
4670+
a newline. Multiple form feeds and newlines within a whitespace range are
4671+
replaced with a single newline and form feed followed by the remaining
4672+
newlines.
4673+
46664674
.. _LambdaBodyIndentation:
46674675

46684676
**LambdaBodyIndentation** (``LambdaBodyIndentationKind``) :versionbadge:`clang-format 13` :ref:`<LambdaBodyIndentation>`

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ Bug Fixes in This Version
442442
- Fixed a crash using ``__array_rank`` on 64-bit targets. (#GH113044).
443443
- The warning emitted for an unsupported register variable type now points to
444444
the unsupported type instead of the ``register`` keyword (#GH109776).
445+
- Fixed a crash when emit ctor for global variant with flexible array init (#GH113187).
445446

446447
Bug Fixes to Compiler Builtins
447448
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -544,6 +545,7 @@ Bug Fixes to C++ Support
544545
const-default-constructible even if a union member has a default member initializer.
545546
(#GH95854).
546547
- Fixed assertion failure in range calculations for conditional throw expressions (#GH111854)
548+
- Fixed an assertion failure when evaluating an invalid expression in an array initializer (#GH112140)
547549

548550
Bug Fixes to AST Handling
549551
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -710,6 +712,7 @@ clang-format
710712
multi-line comments without touching their contents, renames ``false`` to
711713
``Never``, and ``true`` to ``Always``.
712714
- Adds ``RemoveEmptyLinesInUnwrappedLines`` option.
715+
- Adds ``KeepFormFeed`` option and set it to ``true`` for ``GNU`` style.
713716

714717
libclang
715718
--------

clang/include/clang/AST/CommentSema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Sema {
8080
ArrayRef<T> copyArray(ArrayRef<T> Source) {
8181
if (!Source.empty())
8282
return Source.copy(Allocator);
83-
return std::nullopt;
83+
return {};
8484
}
8585

8686
ParagraphComment *actOnParagraphComment(

0 commit comments

Comments
 (0)