Skip to content

Commit 5fd399c

Browse files
committed
'merge main into amd-staging
2 parents 100879e + 1f67b94 commit 5fd399c

File tree

201 files changed

+119931
-1040
lines changed

Some content is hidden

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

201 files changed

+119931
-1040
lines changed

.github/workflows/pr-code-format.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ jobs:
5252
echo "Formatting files:"
5353
echo "$CHANGED_FILES"
5454
55+
# The clang format version should always be upgraded to the first version
56+
# of a release cycle (x.1.0) or the last version of a release cycle, or
57+
# if there have been relevant clang-format backports.
5558
- name: Install clang-format
5659
uses: aminya/setup-cpp@17c11551771948abc5752bbf3183482567c7caf0 # v1.1.1
5760
with:
58-
clangformat: 20.1.8
61+
clangformat: 21.1.0
5962

6063
- name: Setup Python env
6164
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0

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

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,25 @@ AST_MATCHER_P(UserDefinedLiteral, hasLiteral,
110110
return false;
111111
}
112112

113+
AST_MATCHER_P(CXXMethodDecl, hasCanonicalDecl,
114+
clang::ast_matchers::internal::Matcher<CXXMethodDecl>,
115+
InnerMatcher) {
116+
return InnerMatcher.matches(*Node.getCanonicalDecl(), Finder, Builder);
117+
}
118+
119+
AST_POLYMORPHIC_MATCHER_P(
120+
matchMemberName,
121+
AST_POLYMORPHIC_SUPPORTED_TYPES(MemberExpr, CXXDependentScopeMemberExpr),
122+
std::string, MemberName) {
123+
if (const auto *E = dyn_cast<MemberExpr>(&Node))
124+
return E->getMemberDecl()->getName() == MemberName;
125+
126+
if (const auto *E = dyn_cast<CXXDependentScopeMemberExpr>(&Node))
127+
return E->getMember().getAsString() == MemberName;
128+
129+
return false;
130+
}
131+
113132
} // namespace
114133

115134
using utils::isBinaryOrTernary;
@@ -140,9 +159,10 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
140159
const auto ValidContainerNonTemplateType =
141160
qualType(hasUnqualifiedDesugaredType(
142161
recordType(hasDeclaration(ValidContainerRecord))));
143-
const auto ValidContainerTemplateType =
144-
qualType(hasUnqualifiedDesugaredType(templateSpecializationType(
145-
hasDeclaration(classTemplateDecl(has(ValidContainerRecord))))));
162+
const auto ValidContainerTemplateType = qualType(hasUnqualifiedDesugaredType(
163+
anyOf(templateSpecializationType(
164+
hasDeclaration(classTemplateDecl(has(ValidContainerRecord)))),
165+
injectedClassNameType(hasDeclaration(ValidContainerRecord)))));
146166

147167
const auto ValidContainer = qualType(
148168
anyOf(ValidContainerNonTemplateType, ValidContainerTemplateType));
@@ -155,6 +175,9 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
155175
.bind("SizeBinaryOp")),
156176
usedInBooleanContext());
157177

178+
const auto NotInEmptyMethodOfContainer = unless(
179+
forCallable(cxxMethodDecl(hasCanonicalDecl(equalsBoundNode("empty")))));
180+
158181
Finder->addMatcher(
159182
cxxMemberCallExpr(
160183
argumentCountIs(0),
@@ -164,25 +187,23 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
164187
.bind("MemberCallObject")),
165188
callee(
166189
cxxMethodDecl(hasAnyName("size", "length")).bind("SizeMethod")),
167-
WrongUse,
168-
unless(hasAncestor(
169-
cxxMethodDecl(ofClass(equalsBoundNode("container"))))))
190+
WrongUse, NotInEmptyMethodOfContainer)
170191
.bind("SizeCallExpr"),
171192
this);
172193

173194
Finder->addMatcher(
174-
callExpr(argumentCountIs(0),
175-
has(cxxDependentScopeMemberExpr(
176-
hasObjectExpression(
177-
expr(anyOf(hasType(ValidContainer),
178-
hasType(pointsTo(ValidContainer)),
179-
hasType(references(ValidContainer))))
180-
.bind("MemberCallObject")),
181-
anyOf(hasMemberName("size"), hasMemberName("length")))
182-
.bind("DependentExpr")),
183-
WrongUse,
184-
unless(hasAncestor(
185-
cxxMethodDecl(ofClass(equalsBoundNode("container"))))))
195+
callExpr(
196+
argumentCountIs(0),
197+
has(mapAnyOf(memberExpr, cxxDependentScopeMemberExpr)
198+
.with(
199+
hasObjectExpression(
200+
expr(anyOf(hasType(ValidContainer),
201+
hasType(pointsTo(ValidContainer)),
202+
hasType(references(ValidContainer))))
203+
.bind("MemberCallObject")),
204+
anyOf(matchMemberName("size"), matchMemberName("length")))
205+
.bind("MemberExpr")),
206+
WrongUse, NotInEmptyMethodOfContainer)
186207
.bind("SizeCallExpr"),
187208
this);
188209

@@ -217,8 +238,7 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
217238
hasAnyOperatorName("==", "!="), hasOperands(WrongComparend, STLArg),
218239
unless(allOf(hasLHS(hasType(ExcludedComparisonTypesMatcher)),
219240
hasRHS(hasType(SameExcludedComparisonTypesMatcher)))),
220-
unless(hasAncestor(
221-
cxxMethodDecl(ofClass(equalsBoundNode("container"))))))
241+
NotInEmptyMethodOfContainer)
222242
.bind("BinCmp"),
223243
this);
224244
}
@@ -382,9 +402,12 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
382402
Diag << SizeMethod;
383403
else if (const auto *DependentExpr =
384404
Result.Nodes.getNodeAs<CXXDependentScopeMemberExpr>(
385-
"DependentExpr"))
405+
"MemberExpr"))
386406
Diag << DependentExpr->getMember();
387-
else
407+
else if (const auto *ME =
408+
Result.Nodes.getNodeAs<MemberExpr>("MemberExpr")) {
409+
Diag << ME->getMemberNameInfo().getName();
410+
} else
388411
Diag << "unknown method";
389412
Diag << Hint;
390413
} else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4807,7 +4807,7 @@ TEST(Hover, HoverMacroContentsLimit) {
48074807

48084808
EXPECT_EQ(H->Definition, Case.ExpectedDefinition);
48094809
}
4810-
};
4810+
}
48114811

48124812
TEST(Hover, FunctionParameters) {
48134813
struct {

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ Changes in existing checks
232232

233233
- Improved :doc:`readability-container-size-empty
234234
<clang-tidy/checks/readability/container-size-empty>` check by correctly
235-
generating fix-it hints when size method is called from implicit ``this``.
235+
generating fix-it hints when size method is called from implicit ``this``
236+
and adding detection in container's method except ``empty``.
236237

237238
- Improved :doc:`readability-identifier-naming
238239
<clang-tidy/checks/readability/identifier-naming>` check by ignoring

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,3 +908,46 @@ class foo : public std::string{
908908
};
909909

910910
}
911+
912+
class ReportInContainerNonEmptyMethod {
913+
public:
914+
int size() const;
915+
bool empty() const;
916+
917+
void doit() {
918+
if (!size()) {
919+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used to check for emptiness instead of 'size'
920+
// CHECK-FIXES: if (empty())
921+
}
922+
}
923+
};
924+
925+
template <typename T>
926+
class ReportInTemplateContainerNonEmptyMethod {
927+
public:
928+
int size() const;
929+
bool empty() const;
930+
931+
void doit() {
932+
if (!size()) {
933+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used to check for emptiness instead of 'size'
934+
// CHECK-FIXES: if (empty()) {
935+
}
936+
}
937+
};
938+
939+
940+
941+
class ReportInContainerNonEmptyMethodCompare {
942+
public:
943+
bool operator==(const ReportInContainerNonEmptyMethodCompare& other) const;
944+
int size() const;
945+
bool empty() const;
946+
947+
void doit() {
948+
if (*this == ReportInContainerNonEmptyMethodCompare()) {
949+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: the 'empty' method should be used to check for emptiness instead of comparing to an empty object
950+
// CHECK-FIXES: if (this->empty()) {
951+
}
952+
}
953+
};

clang/include/clang/AST/APNumericStorage.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ class APNumericStorage {
2828
uint64_t VAL; ///< Used to store the <= 64 bits integer value.
2929
uint64_t *pVal; ///< Used to store the >64 bits integer value.
3030
};
31-
unsigned BitWidth;
3231

3332
bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
3433

3534
APNumericStorage(const APNumericStorage &) = delete;
3635
void operator=(const APNumericStorage &) = delete;
3736

3837
protected:
38+
unsigned BitWidth;
3939
APNumericStorage() : VAL(0), BitWidth(0) {}
4040

4141
llvm::APInt getIntValue() const {
@@ -51,6 +51,7 @@ class APNumericStorage {
5151
class APIntStorage : private APNumericStorage {
5252
public:
5353
llvm::APInt getValue() const { return getIntValue(); }
54+
unsigned getBitWidth() const { return BitWidth; }
5455
void setValue(const ASTContext &C, const llvm::APInt &Val) {
5556
setIntValue(C, Val);
5657
}

clang/include/clang/AST/Expr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5113,9 +5113,9 @@ class EmbedExpr final : public Expr {
51135113
"trying to dereference an invalid iterator");
51145114
IntegerLiteral *N = EExpr->FakeChildNode;
51155115
N->setValue(*EExpr->Ctx,
5116-
llvm::APInt(N->getValue().getBitWidth(),
5116+
llvm::APInt(N->getBitWidth(),
51175117
EExpr->Data->BinaryData->getCodeUnit(CurOffset),
5118-
N->getType()->isSignedIntegerType()));
5118+
/*Signed=*/true));
51195119
// We want to return a reference to the fake child node in the
51205120
// EmbedExpr, not the local variable N.
51215121
return const_cast<typename BaseTy::reference>(EExpr->FakeChildNode);

clang/include/clang/Basic/arm_sve.td

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,17 +1828,17 @@ let SVETargetGuard = "sve2,lut", SMETargetGuard = "sme2,lut" in {
18281828
////////////////////////////////////////////////////////////////////////////////
18291829
// SVE2 - Optional
18301830

1831-
let SVETargetGuard = "sve2,sve-aes", SMETargetGuard = InvalidMode in {
1832-
def SVAESD : SInst<"svaesd[_{d}]", "ddd", "Uc", MergeNone, "aarch64_sve_aesd", [IsOverloadNone]>;
1833-
def SVAESIMC : SInst<"svaesimc[_{d}]", "dd", "Uc", MergeNone, "aarch64_sve_aesimc", [IsOverloadNone]>;
1834-
def SVAESE : SInst<"svaese[_{d}]", "ddd", "Uc", MergeNone, "aarch64_sve_aese", [IsOverloadNone]>;
1835-
def SVAESMC : SInst<"svaesmc[_{d}]", "dd", "Uc", MergeNone, "aarch64_sve_aesmc", [IsOverloadNone]>;
1831+
let SVETargetGuard = "sve2,sve-aes", SMETargetGuard = "ssve-aes" in {
1832+
def SVAESD : SInst<"svaesd[_{d}]", "ddd", "Uc", MergeNone, "aarch64_sve_aesd", [IsOverloadNone, VerifyRuntimeMode]>;
1833+
def SVAESIMC : SInst<"svaesimc[_{d}]", "dd", "Uc", MergeNone, "aarch64_sve_aesimc", [IsOverloadNone, VerifyRuntimeMode]>;
1834+
def SVAESE : SInst<"svaese[_{d}]", "ddd", "Uc", MergeNone, "aarch64_sve_aese", [IsOverloadNone, VerifyRuntimeMode]>;
1835+
def SVAESMC : SInst<"svaesmc[_{d}]", "dd", "Uc", MergeNone, "aarch64_sve_aesmc", [IsOverloadNone, VerifyRuntimeMode]>;
18361836

1837-
def SVPMULLB_PAIR_U64 : SInst<"svpmullb_pair[_{d}]", "ddd", "Ul", MergeNone, "aarch64_sve_pmullb_pair">;
1838-
def SVPMULLB_PAIR_N_U64 : SInst<"svpmullb_pair[_n_{d}]", "dda", "Ul", MergeNone, "aarch64_sve_pmullb_pair">;
1837+
def SVPMULLB_PAIR_U64 : SInst<"svpmullb_pair[_{d}]", "ddd", "Ul", MergeNone, "aarch64_sve_pmullb_pair", [VerifyRuntimeMode]>;
1838+
def SVPMULLB_PAIR_N_U64 : SInst<"svpmullb_pair[_n_{d}]", "dda", "Ul", MergeNone, "aarch64_sve_pmullb_pair", [VerifyRuntimeMode]>;
18391839

1840-
def SVPMULLT_PAIR_U64 : SInst<"svpmullt_pair[_{d}]", "ddd", "Ul", MergeNone, "aarch64_sve_pmullt_pair">;
1841-
def SVPMULLT_PAIR_N_U64 : SInst<"svpmullt_pair[_n_{d}]", "dda", "Ul", MergeNone, "aarch64_sve_pmullt_pair">;
1840+
def SVPMULLT_PAIR_U64 : SInst<"svpmullt_pair[_{d}]", "ddd", "Ul", MergeNone, "aarch64_sve_pmullt_pair", [VerifyRuntimeMode]>;
1841+
def SVPMULLT_PAIR_N_U64 : SInst<"svpmullt_pair[_n_{d}]", "dda", "Ul", MergeNone, "aarch64_sve_pmullt_pair", [VerifyRuntimeMode]>;
18421842
}
18431843

18441844
let SVETargetGuard = "sve-sha3", SMETargetGuard = "sve-sha3,sme2p1" in {

clang/lib/AST/ByteCode/Context.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) {
9191
#endif
9292
}
9393

94-
Result = Res.toAPValue();
94+
Result = Res.stealAPValue();
9595

9696
return true;
9797
}
@@ -121,7 +121,7 @@ bool Context::evaluate(State &Parent, const Expr *E, APValue &Result,
121121
#endif
122122
}
123123

124-
Result = Res.toAPValue();
124+
Result = Res.stealAPValue();
125125
return true;
126126
}
127127

@@ -153,7 +153,7 @@ bool Context::evaluateAsInitializer(State &Parent, const VarDecl *VD,
153153
#endif
154154
}
155155

156-
Result = Res.toAPValue();
156+
Result = Res.stealAPValue();
157157
return true;
158158
}
159159

clang/lib/AST/ByteCode/Disasm.cpp

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -549,39 +549,17 @@ LLVM_DUMP_METHOD void Block::dump(llvm::raw_ostream &OS) const {
549549
}
550550

551551
LLVM_DUMP_METHOD void EvaluationResult::dump() const {
552-
assert(Ctx);
553552
auto &OS = llvm::errs();
554-
const ASTContext &ASTCtx = Ctx->getASTContext();
555553

556-
switch (Kind) {
557-
case Empty:
554+
if (empty()) {
558555
OS << "Empty\n";
559-
break;
560-
case RValue:
561-
OS << "RValue: ";
562-
std::get<APValue>(Value).dump(OS, ASTCtx);
563-
break;
564-
case LValue: {
565-
assert(Source);
566-
QualType SourceType;
567-
if (const auto *D = dyn_cast<const Decl *>(Source)) {
568-
if (const auto *VD = dyn_cast<ValueDecl>(D))
569-
SourceType = VD->getType();
570-
} else if (const auto *E = dyn_cast<const Expr *>(Source)) {
571-
SourceType = E->getType();
572-
}
573-
574-
OS << "LValue: ";
575-
if (const auto *P = std::get_if<Pointer>(&Value))
576-
P->toAPValue(ASTCtx).printPretty(OS, ASTCtx, SourceType);
577-
OS << "\n";
578-
break;
579-
}
580-
case Invalid:
556+
} else if (isInvalid()) {
581557
OS << "Invalid\n";
582-
break;
583-
case Valid:
584-
OS << "Valid\n";
585-
break;
558+
} else {
559+
OS << "Value: ";
560+
#ifndef NDEBUG
561+
assert(Ctx);
562+
Value.dump(OS, Ctx->getASTContext());
563+
#endif
586564
}
587565
}

0 commit comments

Comments
 (0)