Skip to content

Commit 6c7bb7f

Browse files
committed
Merge commit '6cd62ad08c97' from llvm.org/main into next
Conflicts: clang/lib/CodeGen/CGPointerAuth.cpp clang/lib/CodeGen/ItaniumCXXABI.cpp rdar://147536848
2 parents b1e0384 + 6cd62ad commit 6c7bb7f

File tree

69 files changed

+423
-1039
lines changed

Some content is hidden

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

69 files changed

+423
-1039
lines changed

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

+2-1
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

+1-3
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

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

+1-1
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

-1
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

+4-3
Original file line numberDiff line numberDiff line change
@@ -1653,9 +1653,10 @@ class ASTContext : public RefCountedBase<ASTContext> {
16531653
QualType getRValueReferenceType(QualType T) const;
16541654

16551655
/// Return the uniqued reference to the type for a member pointer to
1656-
/// the specified type in the specified nested name.
1657-
QualType getMemberPointerType(QualType T, NestedNameSpecifier *Qualifier,
1658-
const CXXRecordDecl *Cls) const;
1656+
/// the specified type in the specified class.
1657+
///
1658+
/// The class \p Cls is a \c Type because it could be a dependent name.
1659+
QualType getMemberPointerType(QualType T, const Type *Cls) const;
16591660

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

clang/include/clang/AST/ASTNodeTraverser.h

+2-5
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +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)
456+
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const Type *, getClass)
457457
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const CXXRecordDecl *,
458458
getMostRecentCXXRecordDecl)
459459
};

clang/include/clang/AST/RecursiveASTVisitor.h

+4-5
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

@@ -1280,10 +1279,10 @@ DEF_TRAVERSE_TYPELOC(RValueReferenceType,
12801279
// We traverse this in the type case as well, but how is it not reached through
12811280
// the pointee type?
12821281
DEF_TRAVERSE_TYPELOC(MemberPointerType, {
1283-
if (NestedNameSpecifierLoc QL = TL.getQualifierLoc())
1284-
TRY_TO(TraverseNestedNameSpecifierLoc(QL));
1282+
if (auto *TSI = TL.getClassTInfo())
1283+
TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
12851284
else
1286-
TRY_TO(TraverseNestedNameSpecifier(TL.getTypePtr()->getQualifier()));
1285+
TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
12871286
TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
12881287
})
12891288

clang/include/clang/AST/Type.h

+13-15
Original file line numberDiff line numberDiff line change
@@ -3984,16 +3984,14 @@ class MemberPointerType : public Type, public llvm::FoldingSetNode {
39843984
QualType PointeeType;
39853985

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

3990-
MemberPointerType(QualType Pointee, NestedNameSpecifier *Qualifier,
3991-
QualType CanonicalPtr)
3990+
MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr)
39923991
: Type(MemberPointer, CanonicalPtr,
3993-
(toTypeDependence(Qualifier->getDependence()) &
3994-
~TypeDependence::VariablyModified) |
3992+
(Cls->getDependence() & ~TypeDependence::VariablyModified) |
39953993
Pointee->getDependence()),
3996-
PointeeType(Pointee), Qualifier(Qualifier) {}
3994+
PointeeType(Pointee), Class(Cls) {}
39973995

39983996
public:
39993997
QualType getPointeeType() const { return PointeeType; }
@@ -4010,21 +4008,21 @@ class MemberPointerType : public Type, public llvm::FoldingSetNode {
40104008
return !PointeeType->isFunctionProtoType();
40114009
}
40124010

4013-
NestedNameSpecifier *getQualifier() const { return Qualifier; }
4011+
const Type *getClass() const { return Class; }
40144012
CXXRecordDecl *getMostRecentCXXRecordDecl() const;
40154013

4016-
bool isSugared() const;
4017-
QualType desugar() const {
4018-
return isSugared() ? getCanonicalTypeInternal() : QualType(this, 0);
4019-
}
4014+
bool isSugared() const { return false; }
4015+
QualType desugar() const { return QualType(this, 0); }
40204016

40214017
void Profile(llvm::FoldingSetNodeID &ID) {
4022-
Profile(ID, getPointeeType(), getQualifier(), getMostRecentCXXRecordDecl());
4018+
Profile(ID, getPointeeType(), getClass());
40234019
}
40244020

40254021
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
4026-
const NestedNameSpecifier *Qualifier,
4027-
const CXXRecordDecl *Cls);
4022+
const Type *Class) {
4023+
ID.AddPointer(Pointee.getAsOpaquePtr());
4024+
ID.AddPointer(Class);
4025+
}
40284026

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

clang/include/clang/AST/TypeLoc.h

+14-19
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ class TypeLoc {
139139
}
140140

141141
/// Get the pointer where source information is stored.
142-
// FIXME: This should provide a type-safe interface.
143142
void *getOpaqueData() const {
144143
return Data;
145144
}
@@ -1394,7 +1393,7 @@ class BlockPointerTypeLoc : public PointerLikeTypeLoc<BlockPointerTypeLoc,
13941393
};
13951394

13961395
struct MemberPointerLocInfo : public PointerLikeLocInfo {
1397-
void *QualifierData = nullptr;
1396+
TypeSourceInfo *ClassTInfo;
13981397
};
13991398

14001399
/// Wrapper for source info for member pointers.
@@ -1410,32 +1409,28 @@ class MemberPointerTypeLoc : public PointerLikeTypeLoc<MemberPointerTypeLoc,
14101409
setSigilLoc(Loc);
14111410
}
14121411

1413-
NestedNameSpecifierLoc getQualifierLoc() const {
1414-
return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
1415-
getLocalData()->QualifierData);
1412+
const Type *getClass() const {
1413+
return getTypePtr()->getClass();
14161414
}
14171415

1418-
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
1419-
assert(QualifierLoc.getNestedNameSpecifier() ==
1420-
getTypePtr()->getQualifier() &&
1421-
"Inconsistent nested-name-specifier pointer");
1422-
getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
1416+
TypeSourceInfo *getClassTInfo() const {
1417+
return getLocalData()->ClassTInfo;
1418+
}
1419+
1420+
void setClassTInfo(TypeSourceInfo* TI) {
1421+
getLocalData()->ClassTInfo = TI;
14231422
}
14241423

14251424
void initializeLocal(ASTContext &Context, SourceLocation Loc) {
14261425
setSigilLoc(Loc);
1427-
if (auto *Qualifier = getTypePtr()->getQualifier()) {
1428-
NestedNameSpecifierLocBuilder Builder;
1429-
Builder.MakeTrivial(Context, Qualifier, Loc);
1430-
setQualifierLoc(Builder.getWithLocInContext(Context));
1431-
} else
1432-
getLocalData()->QualifierData = nullptr;
1426+
setClassTInfo(nullptr);
14331427
}
14341428

14351429
SourceRange getLocalSourceRange() const {
1436-
if (NestedNameSpecifierLoc QL = getQualifierLoc())
1437-
return SourceRange(QL.getBeginLoc(), getStarLoc());
1438-
return SourceRange(getStarLoc());
1430+
if (TypeSourceInfo *TI = getClassTInfo())
1431+
return SourceRange(TI->getTypeLoc().getBeginLoc(), getStarLoc());
1432+
else
1433+
return SourceRange(getStarLoc());
14391434
}
14401435
};
14411436

clang/include/clang/AST/TypeProperties.td

+3-6
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,12 @@ let Class = MemberPointerType in {
140140
def : Property<"pointeeType", QualType> {
141141
let Read = [{ node->getPointeeType() }];
142142
}
143-
def : Property<"Qualifier", NestedNameSpecifier> {
144-
let Read = [{ node->getQualifier() }];
145-
}
146-
def : Property<"Cls", DeclRef> {
147-
let Read = [{ node->getMostRecentCXXRecordDecl() }];
143+
def : Property<"baseType", QualType> {
144+
let Read = [{ QualType(node->getClass(), 0) }];
148145
}
149146

150147
def : Creator<[{
151-
return ctx.getMemberPointerType(pointeeType, Qualifier, cast_or_null<CXXRecordDecl>(Cls));
148+
return ctx.getMemberPointerType(pointeeType, baseType.getTypePtr());
152149
}]>;
153150
}
154151

clang/include/clang/Basic/DiagnosticSemaKinds.td

+4-2
Original file line numberDiff line numberDiff line change
@@ -7141,8 +7141,10 @@ def err_illegal_decl_mempointer_to_reference : Error<
71417141
"'%0' declared as a member pointer to a reference of type %1">;
71427142
def err_illegal_decl_mempointer_to_void : Error<
71437143
"'%0' declared as a member pointer to void">;
7144-
def err_illegal_decl_mempointer_in_nonclass
7145-
: Error<"'%0' does not point into a class">;
7144+
def err_illegal_decl_mempointer_in_nonclass : Error<
7145+
"'%0' does not point into a class">;
7146+
def err_mempointer_in_nonclass_type : Error<
7147+
"member pointer refers into non-class type %0">;
71467148
def err_reference_to_void : Error<"cannot form a reference to 'void'">;
71477149
def err_nonfunction_block_type : Error<
71487150
"block pointer to non-function type is invalid">;

clang/include/clang/Sema/Sema.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -1491,12 +1491,6 @@ class Sema final : public SemaBase {
14911491
unsigned DiagID, bool ForceCheck = false,
14921492
bool ForceUnprivileged = false);
14931493

1494-
AccessResult CheckBaseClassAccess(
1495-
SourceLocation AccessLoc, CXXRecordDecl *Base, CXXRecordDecl *Derived,
1496-
const CXXBasePath &Path, unsigned DiagID,
1497-
llvm::function_ref<void(PartialDiagnostic &PD)> SetupPDiag,
1498-
bool ForceCheck = false, bool ForceUnprivileged = false);
1499-
15001494
/// Checks access to all the declarations in the given result set.
15011495
void CheckLookupAccess(const LookupResult &R);
15021496

@@ -15460,9 +15454,8 @@ class Sema final : public SemaBase {
1546015454
///
1546115455
/// \returns a member pointer type, if successful, or a NULL type if there was
1546215456
/// an error.
15463-
QualType BuildMemberPointerType(QualType T, NestedNameSpecifier *Qualifier,
15464-
CXXRecordDecl *Cls, SourceLocation Loc,
15465-
DeclarationName Entity);
15457+
QualType BuildMemberPointerType(QualType T, QualType Class,
15458+
SourceLocation Loc, DeclarationName Entity);
1546615459

1546715460
/// Build a block pointer type.
1546815461
///

clang/lib/AST/ASTContext.cpp

+21-47
Original file line numberDiff line numberDiff line change
@@ -3433,8 +3433,7 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,
34333433
case Type::MemberPointer: {
34343434
OS << "M";
34353435
const auto *MPT = T->castAs<MemberPointerType>();
3436-
encodeTypeForFunctionPointerAuth(
3437-
Ctx, OS, QualType(MPT->getQualifier()->getAsType(), 0));
3436+
encodeTypeForFunctionPointerAuth(Ctx, OS, QualType(MPT->getClass(), 0));
34383437
encodeTypeForFunctionPointerAuth(Ctx, OS, MPT->getPointeeType());
34393438
return;
34403439
}
@@ -3622,8 +3621,7 @@ uint16_t ASTContext::getPointerAuthTypeDiscriminator(QualType T) {
36223621
if (PointeeType->castAs<FunctionProtoType>()->getExceptionSpecType() !=
36233622
EST_None) {
36243623
QualType FT = getFunctionTypeWithExceptionSpec(PointeeType, EST_None);
3625-
T = getMemberPointerType(FT, MPT->getQualifier(),
3626-
MPT->getMostRecentCXXRecordDecl());
3624+
T = getMemberPointerType(FT, MPT->getClass());
36273625
}
36283626
}
36293627
std::unique_ptr<MangleContext> MC(createMangleContext());
@@ -4624,50 +4622,32 @@ QualType ASTContext::getRValueReferenceType(QualType T) const {
46244622
return QualType(New, 0);
46254623
}
46264624

4627-
QualType ASTContext::getMemberPointerType(QualType T,
4628-
NestedNameSpecifier *Qualifier,
4629-
const CXXRecordDecl *Cls) const {
4630-
if (!Qualifier) {
4631-
assert(Cls && "At least one of Qualifier or Cls must be provided");
4632-
Qualifier = NestedNameSpecifier::Create(*this, /*Prefix=*/nullptr,
4633-
/*Template=*/false,
4634-
getTypeDeclType(Cls).getTypePtr());
4635-
} else if (!Cls) {
4636-
Cls = Qualifier->getAsRecordDecl();
4637-
}
4625+
/// getMemberPointerType - Return the uniqued reference to the type for a
4626+
/// member pointer to the specified type, in the specified class.
4627+
QualType ASTContext::getMemberPointerType(QualType T, const Type *Cls) const {
46384628
// Unique pointers, to guarantee there is only one pointer of a particular
46394629
// structure.
46404630
llvm::FoldingSetNodeID ID;
4641-
MemberPointerType::Profile(ID, T, Qualifier, Cls);
4631+
MemberPointerType::Profile(ID, T, Cls);
46424632

46434633
void *InsertPos = nullptr;
46444634
if (MemberPointerType *PT =
46454635
MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos))
46464636
return QualType(PT, 0);
46474637

4648-
NestedNameSpecifier *CanonicalQualifier = [&] {
4649-
if (!Cls)
4650-
return getCanonicalNestedNameSpecifier(Qualifier);
4651-
NestedNameSpecifier *R = NestedNameSpecifier::Create(
4652-
*this, /*Prefix=*/nullptr, /*Template=*/false,
4653-
Cls->getCanonicalDecl()->getTypeForDecl());
4654-
assert(R == getCanonicalNestedNameSpecifier(R));
4655-
return R;
4656-
}();
46574638
// If the pointee or class type isn't canonical, this won't be a canonical
46584639
// type either, so fill in the canonical type field.
46594640
QualType Canonical;
4660-
if (!T.isCanonical() || Qualifier != CanonicalQualifier) {
4661-
Canonical =
4662-
getMemberPointerType(getCanonicalType(T), CanonicalQualifier, Cls);
4663-
assert(!cast<MemberPointerType>(Canonical)->isSugared());
4641+
if (!T.isCanonical() || !Cls->isCanonicalUnqualified()) {
4642+
Canonical = getMemberPointerType(getCanonicalType(T),getCanonicalType(Cls));
4643+
46644644
// Get the new insert position for the node we care about.
4665-
[[maybe_unused]] MemberPointerType *NewIP =
4666-
MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos);
4667-
assert(!NewIP && "Shouldn't be in the map!");
4645+
MemberPointerType *NewIP =
4646+
MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos);
4647+
assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP;
46684648
}
46694649
auto *New = new (*this, alignof(MemberPointerType))
4670-
MemberPointerType(T, Qualifier, Canonical);
4650+
MemberPointerType(T, Cls, Canonical);
46714651
Types.push_back(New);
46724652
MemberPointerTypes.InsertNode(New, InsertPos);
46734653
return QualType(New, 0);
@@ -7427,16 +7407,11 @@ bool ASTContext::UnwrapSimilarTypes(QualType &T1, QualType &T2,
74277407
return true;
74287408
}
74297409

7430-
if (const auto *T1MPType = T1->getAs<MemberPointerType>(),
7431-
*T2MPType = T2->getAs<MemberPointerType>();
7432-
T1MPType && T2MPType) {
7433-
if (auto *RD1 = T1MPType->getMostRecentCXXRecordDecl(),
7434-
*RD2 = T2MPType->getMostRecentCXXRecordDecl();
7435-
RD1 != RD2 && RD1->getCanonicalDecl() != RD2->getCanonicalDecl())
7436-
return false;
7437-
if (getCanonicalNestedNameSpecifier(T1MPType->getQualifier()) !=
7438-
getCanonicalNestedNameSpecifier(T2MPType->getQualifier()))
7439-
return false;
7410+
const auto *T1MPType = T1->getAs<MemberPointerType>();
7411+
const auto *T2MPType = T2->getAs<MemberPointerType>();
7412+
if (T1MPType && T2MPType &&
7413+
hasSameUnqualifiedType(QualType(T1MPType->getClass(), 0),
7414+
QualType(T2MPType->getClass(), 0))) {
74407415
T1 = T1MPType->getPointeeType();
74417416
T2 = T2MPType->getPointeeType();
74427417
return true;
@@ -14690,12 +14665,11 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,
1469014665
case Type::MemberPointer: {
1469114666
const auto *PX = cast<MemberPointerType>(X),
1469214667
*PY = cast<MemberPointerType>(Y);
14693-
assert(declaresSameEntity(PX->getMostRecentCXXRecordDecl(),
14694-
PY->getMostRecentCXXRecordDecl()));
1469514668
return Ctx.getMemberPointerType(
1469614669
getCommonPointeeType(Ctx, PX, PY),
14697-
getCommonQualifier(Ctx, PX, PY, /*IsSame=*/true),
14698-
PX->getMostRecentCXXRecordDecl());
14670+
Ctx.getCommonSugaredType(QualType(PX->getClass(), 0),
14671+
QualType(PY->getClass(), 0))
14672+
.getTypePtr());
1469914673
}
1470014674
case Type::LValueReference: {
1470114675
const auto *PX = cast<LValueReferenceType>(X),

0 commit comments

Comments
 (0)