Skip to content

Commit ba1e441

Browse files
author
git apple-llvm automerger
committed
Merge commit '27f0e6e579b7' from llvm.org/release/21.x into stable/21.x
2 parents b1e9dbb + 27f0e6e commit ba1e441

File tree

9 files changed

+440
-9
lines changed

9 files changed

+440
-9
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
675675
bool containsNonRelocatablePointerAuth(QualType T) {
676676
if (!isPointerAuthenticationAvailable())
677677
return false;
678-
return findPointerAuthContent(T) ==
679-
PointerAuthContent::AddressDiscriminatedData;
678+
return findPointerAuthContent(T) != PointerAuthContent::None;
680679
}
681680

682681
private:

clang/lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3151,7 +3151,7 @@ bool ASTContext::hasUniqueObjectRepresentations(
31513151
return true;
31523152
}
31533153

3154-
// All other pointers (except __ptrauth pointers) are unique.
3154+
// All other pointers are unique.
31553155
if (Ty->isPointerType())
31563156
return !Ty.hasAddressDiscriminatedPointerAuth();
31573157

clang/lib/AST/DeclCXX.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,13 @@ void CXXRecordDecl::addedMember(Decl *D) {
14481448
data().StructuralIfLiteral = false;
14491449
}
14501450

1451+
// If this type contains any address discriminated values we should
1452+
// have already indicated that the only special member functions that
1453+
// can possibly be trivial are the default constructor and destructor.
1454+
if (T.hasAddressDiscriminatedPointerAuth())
1455+
data().HasTrivialSpecialMembers &=
1456+
SMF_DefaultConstructor | SMF_Destructor;
1457+
14511458
// C++14 [meta.unary.prop]p4:
14521459
// T is a class type [...] with [...] no non-static data members other
14531460
// than subobjects of zero size

clang/lib/AST/Type.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,6 +2821,11 @@ bool QualType::isCXX98PODType(const ASTContext &Context) const {
28212821
return false;
28222822

28232823
QualType CanonicalType = getTypePtr()->CanonicalType;
2824+
2825+
// Any type that is, or contains, address discriminated data is never POD.
2826+
if (const_cast<ASTContext&>(Context).containsAddressDiscriminatedPointerAuth(CanonicalType))
2827+
return false;
2828+
28242829
switch (CanonicalType->getTypeClass()) {
28252830
// Everything not explicitly mentioned is not POD.
28262831
default: return false;
@@ -2878,6 +2883,11 @@ bool QualType::isTrivialType(const ASTContext &Context) const {
28782883
if (CanonicalType->isDependentType())
28792884
return false;
28802885

2886+
// Any type that is, or contains, address discriminated data is never a
2887+
// trivial type.
2888+
if (const_cast<ASTContext&>(Context).containsAddressDiscriminatedPointerAuth(CanonicalType))
2889+
return false;
2890+
28812891
// C++0x [basic.types]p9:
28822892
// Scalar types, trivial class types, arrays of such types, and
28832893
// cv-qualified versions of these types are collectively called trivial
@@ -2975,6 +2985,12 @@ bool QualType::isBitwiseCloneableType(const ASTContext &Context) const {
29752985

29762986
if (CanonicalType->isIncompleteType())
29772987
return false;
2988+
2989+
// Any type that is, or contains, address discriminated data is never
2990+
// bitwise clonable.
2991+
if (const_cast<ASTContext&>(Context).containsAddressDiscriminatedPointerAuth(CanonicalType))
2992+
return false;
2993+
29782994
const auto *RD = CanonicalType->getAsRecordDecl(); // struct/union/class
29792995
if (!RD)
29802996
return true;
@@ -3218,6 +3234,10 @@ bool QualType::isCXX11PODType(const ASTContext &Context) const {
32183234
if (BaseTy->isIncompleteType())
32193235
return false;
32203236

3237+
// Any type that is, or contains, address discriminated data is non-POD.
3238+
if (const_cast<ASTContext&>(Context).containsAddressDiscriminatedPointerAuth(*this))
3239+
return false;
3240+
32213241
// As an extension, Clang treats vector types as Scalar types.
32223242
if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true;
32233243
if (const auto *RT = BaseTy->getAs<RecordType>()) {

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20792,6 +20792,7 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
2079220792
Q && Q.isAddressDiscriminated()) {
2079320793
Record->setArgPassingRestrictions(
2079420794
RecordArgPassingKind::CanNeverPassInRegs);
20795+
Record->setNonTrivialToPrimitiveCopy(true);
2079520796
}
2079620797
}
2079720798

clang/lib/Sema/SemaTypeTraits.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,10 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT,
17681768
// Objective-C lifetime, this is a non-trivial assignment.
17691769
if (LhsT.getNonReferenceType().hasNonTrivialObjCLifetime())
17701770
return false;
1771-
1771+
ASTContext &Context = Self.getASTContext();
1772+
if (Context.containsAddressDiscriminatedPointerAuth(LhsT) ||
1773+
Context.containsAddressDiscriminatedPointerAuth(RhsT))
1774+
return false;
17721775
return !Result.get()->hasNonTrivialCall(Self.Context);
17731776
}
17741777

clang/test/SemaCXX/ptrauth-triviality.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static_assert(__is_trivially_destructible(S3));
7474
static_assert(!__is_trivially_copyable(S3));
7575
static_assert(!__is_trivially_relocatable(S3)); // expected-warning{{deprecated}}
7676
//FIXME
77-
static_assert(__builtin_is_cpp_trivially_relocatable(S3));
77+
static_assert(!__builtin_is_cpp_trivially_relocatable(S3));
7878
static_assert(!__is_trivially_equality_comparable(S3));
7979

8080

@@ -84,7 +84,7 @@ static_assert(!__is_trivially_assignable(Holder<S3>, const Holder<S3>&));
8484
static_assert(__is_trivially_destructible(Holder<S3>));
8585
static_assert(!__is_trivially_copyable(Holder<S3>));
8686
static_assert(!__is_trivially_relocatable(Holder<S3>)); // expected-warning{{deprecated}}
87-
static_assert(__builtin_is_cpp_trivially_relocatable(Holder<S3>));
87+
static_assert(!__builtin_is_cpp_trivially_relocatable(Holder<S3>));
8888
static_assert(!__is_trivially_equality_comparable(Holder<S3>));
8989

9090
struct IA S4 {
@@ -207,7 +207,7 @@ template <class T> struct UnionWrapper trivially_relocatable_if_eligible {
207207
} u;
208208
};
209209

210-
static_assert(test_is_trivially_relocatable_v<AddressDiscriminatedPolymorphicBase>);
210+
static_assert(!test_is_trivially_relocatable_v<AddressDiscriminatedPolymorphicBase>);
211211
static_assert(test_is_trivially_relocatable_v<NoAddressDiscriminatedPolymorphicBase>);
212212
static_assert(inheritance_relocatability_matches_bases_v<AddressDiscriminatedPolymorphicBase, NoAddressDiscriminatedPolymorphicBase>);
213213
static_assert(inheritance_relocatability_matches_bases_v<NoAddressDiscriminatedPolymorphicBase, AddressDiscriminatedPolymorphicBase>);

0 commit comments

Comments
 (0)