Skip to content

Commit 0f23b05

Browse files
Merge branch 'llvm:main' into main
2 parents 1c09daa + 335a461 commit 0f23b05

File tree

82 files changed

+538
-1157
lines changed

Some content is hidden

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

82 files changed

+538
-1157
lines changed

clang-tools-extra/clang-tidy/bugprone/ComparePointerToMemberVirtualFunctionCheck.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ void ComparePointerToMemberVirtualFunctionCheck::check(
7070
// compare with variable which type is pointer to member function.
7171
llvm::SmallVector<SourceLocation, 12U> SameSignatureVirtualMethods{};
7272
const auto *MPT = cast<MemberPointerType>(DRE->getType().getCanonicalType());
73-
const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
73+
const Type *T = MPT->getClass();
74+
if (T == nullptr)
75+
return;
76+
const CXXRecordDecl *RD = T->getAsCXXRecordDecl();
7477
if (RD == nullptr)
7578
return;
7679

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ UseNullptrCheck::UseNullptrCheck(StringRef Name, ClangTidyContext *Context)
493493
: ClangTidyCheck(Name, Context),
494494
NullMacrosStr(Options.get("NullMacros", "NULL")),
495495
IgnoredTypes(utils::options::parseStringList(Options.get(
496-
"IgnoredTypes", "_CmpUnspecifiedParam;^std::__cmp_cat::__unspec"))) {
496+
"IgnoredTypes",
497+
"std::_CmpUnspecifiedParam::;^std::__cmp_cat::__unspec"))) {
497498
StringRef(NullMacrosStr).split(NullMacros, ",");
498499
}
499500

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ bool isFunctionPointerConvertible(QualType From, QualType To) {
178178

179179
// Note: converting Derived::* to Base::* is a different kind of conversion,
180180
// called Pointer-to-member conversion.
181-
return FromMember->getQualifier() == ToMember->getQualifier() &&
182-
FromMember->getMostRecentCXXRecordDecl() ==
183-
ToMember->getMostRecentCXXRecordDecl() &&
181+
return FromMember->getClass() == ToMember->getClass() &&
184182
FromMember->getPointeeType() == ToMember->getPointeeType();
185183
}
186184

@@ -221,8 +219,8 @@ bool isQualificationConvertiblePointer(QualType From, QualType To,
221219

222220
if (P1->isMemberPointerType())
223221
return P2->isMemberPointerType() &&
224-
P1->getAs<MemberPointerType>()->getMostRecentCXXRecordDecl() ==
225-
P2->getAs<MemberPointerType>()->getMostRecentCXXRecordDecl();
222+
P1->getAs<MemberPointerType>()->getClass() ==
223+
P2->getAs<MemberPointerType>()->getClass();
226224

227225
if (P1->isConstantArrayType())
228226
return P2->isConstantArrayType() &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ TEST_F(FindExplicitReferencesTest, AllRefsInFoo) {
14891489
"4: targets = {a}\n"
14901490
"5: targets = {a::b}, qualifier = 'a::'\n"
14911491
"6: targets = {a::b::S}\n"
1492-
"7: targets = {a::b::S::type}, qualifier = 'S::'\n"
1492+
"7: targets = {a::b::S::type}, qualifier = 'struct S::'\n"
14931493
"8: targets = {y}, decl\n"},
14941494
{R"cpp(
14951495
void foo() {

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ Improvements to Clang's diagnostics
267267
under the subgroup ``-Wunsafe-buffer-usage-in-libc-call``.
268268
- Diagnostics on chained comparisons (``a < b < c``) are now an error by default. This can be disabled with
269269
``-Wno-error=parentheses``.
270-
- Clang now better preserves the sugared types of pointers to member.
271270
- The ``-Wshift-bool`` warning has been added to warn about shifting a boolean. (#GH28334)
272271
- Fixed diagnostics adding a trailing ``::`` when printing some source code
273272
constructs, like base classes.

clang/include/clang/AST/ASTContext.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,9 +1558,10 @@ class ASTContext : public RefCountedBase<ASTContext> {
15581558
QualType getRValueReferenceType(QualType T) const;
15591559

15601560
/// Return the uniqued reference to the type for a member pointer to
1561-
/// the specified type in the specified nested name.
1562-
QualType getMemberPointerType(QualType T, NestedNameSpecifier *Qualifier,
1563-
const CXXRecordDecl *Cls) const;
1561+
/// the specified type in the specified class.
1562+
///
1563+
/// The class \p Cls is a \c Type because it could be a dependent name.
1564+
QualType getMemberPointerType(QualType T, const Type *Cls) const;
15641565

15651566
/// Return a non-unique reference to the type for a variable array of
15661567
/// the specified element type.

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,7 @@ class ASTNodeTraverser
393393
Visit(T->getPointeeType());
394394
}
395395
void VisitMemberPointerType(const MemberPointerType *T) {
396-
// FIXME: Provide a NestedNameSpecifier visitor.
397-
Visit(T->getQualifier()->getAsType());
398-
Visit(T->getMostRecentCXXRecordDecl());
396+
Visit(T->getClass());
399397
Visit(T->getPointeeType());
400398
}
401399
void VisitArrayType(const ArrayType *T) { Visit(T->getElementType()); }
@@ -487,8 +485,7 @@ class ASTNodeTraverser
487485
}
488486
}
489487
void VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
490-
// FIXME: Provide NestedNamespecifierLoc visitor.
491-
Visit(TL.getQualifierLoc().getTypeLoc());
488+
Visit(TL.getClassTInfo()->getTypeLoc());
492489
}
493490
void VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) {
494491
Visit(TL.getSizeExpr());

clang/include/clang/AST/CanonicalType.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,7 @@ template<>
453453
struct CanProxyAdaptor<MemberPointerType>
454454
: public CanProxyBase<MemberPointerType> {
455455
LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
456-
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(NestedNameSpecifier *, getQualifier)
457-
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const CXXRecordDecl *,
458-
getMostRecentCXXRecordDecl)
456+
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const Type *, getClass)
459457
};
460458

461459
// CanProxyAdaptors for arrays are intentionally unimplemented because

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,7 @@ DEF_TRAVERSE_TYPE(RValueReferenceType,
10041004
{ TRY_TO(TraverseType(T->getPointeeType())); })
10051005

10061006
DEF_TRAVERSE_TYPE(MemberPointerType, {
1007-
TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1008-
TRY_TO(TraverseDecl(T->getMostRecentCXXRecordDecl()));
1007+
TRY_TO(TraverseType(QualType(T->getClass(), 0)));
10091008
TRY_TO(TraverseType(T->getPointeeType()));
10101009
})
10111010

@@ -1270,10 +1269,10 @@ DEF_TRAVERSE_TYPELOC(RValueReferenceType,
12701269
// We traverse this in the type case as well, but how is it not reached through
12711270
// the pointee type?
12721271
DEF_TRAVERSE_TYPELOC(MemberPointerType, {
1273-
if (NestedNameSpecifierLoc QL = TL.getQualifierLoc())
1274-
TRY_TO(TraverseNestedNameSpecifierLoc(QL));
1272+
if (auto *TSI = TL.getClassTInfo())
1273+
TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
12751274
else
1276-
TRY_TO(TraverseNestedNameSpecifier(TL.getTypePtr()->getQualifier()));
1275+
TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
12771276
TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
12781277
})
12791278

clang/include/clang/AST/Type.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3527,16 +3527,14 @@ class MemberPointerType : public Type, public llvm::FoldingSetNode {
35273527
QualType PointeeType;
35283528

35293529
/// The class of which the pointee is a member. Must ultimately be a
3530-
/// CXXRecordType, but could be a typedef or a template parameter too.
3531-
NestedNameSpecifier *Qualifier;
3530+
/// RecordType, but could be a typedef or a template parameter too.
3531+
const Type *Class;
35323532

3533-
MemberPointerType(QualType Pointee, NestedNameSpecifier *Qualifier,
3534-
QualType CanonicalPtr)
3533+
MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr)
35353534
: Type(MemberPointer, CanonicalPtr,
3536-
(toTypeDependence(Qualifier->getDependence()) &
3537-
~TypeDependence::VariablyModified) |
3535+
(Cls->getDependence() & ~TypeDependence::VariablyModified) |
35383536
Pointee->getDependence()),
3539-
PointeeType(Pointee), Qualifier(Qualifier) {}
3537+
PointeeType(Pointee), Class(Cls) {}
35403538

35413539
public:
35423540
QualType getPointeeType() const { return PointeeType; }
@@ -3553,21 +3551,21 @@ class MemberPointerType : public Type, public llvm::FoldingSetNode {
35533551
return !PointeeType->isFunctionProtoType();
35543552
}
35553553

3556-
NestedNameSpecifier *getQualifier() const { return Qualifier; }
3554+
const Type *getClass() const { return Class; }
35573555
CXXRecordDecl *getMostRecentCXXRecordDecl() const;
35583556

3559-
bool isSugared() const;
3560-
QualType desugar() const {
3561-
return isSugared() ? getCanonicalTypeInternal() : QualType(this, 0);
3562-
}
3557+
bool isSugared() const { return false; }
3558+
QualType desugar() const { return QualType(this, 0); }
35633559

35643560
void Profile(llvm::FoldingSetNodeID &ID) {
3565-
Profile(ID, getPointeeType(), getQualifier(), getMostRecentCXXRecordDecl());
3561+
Profile(ID, getPointeeType(), getClass());
35663562
}
35673563

35683564
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
3569-
const NestedNameSpecifier *Qualifier,
3570-
const CXXRecordDecl *Cls);
3565+
const Type *Class) {
3566+
ID.AddPointer(Pointee.getAsOpaquePtr());
3567+
ID.AddPointer(Class);
3568+
}
35713569

35723570
static bool classof(const Type *T) {
35733571
return T->getTypeClass() == MemberPointer;

0 commit comments

Comments
 (0)