Skip to content

Commit ca47986

Browse files
committed
__is_trivially_relocatable is true for c++26 relocatable types
1 parent d66d437 commit ca47986

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,12 +1825,13 @@ The following type trait primitives are supported by Clang. Those traits marked
18251825
* ``__is_trivially_relocatable`` (Clang): Returns true if moving an object
18261826
of the given type, and then destroying the source object, is known to be
18271827
functionally equivalent to copying the underlying bytes and then dropping the
1828-
source object on the floor. This is true of trivial types and types which
1828+
source object on the floor. This is true of trivial types,
1829+
C++26 relocatable types, and types which
18291830
were made trivially relocatable via the ``clang::trivial_abi`` attribute.
18301831
* ``__builtin_is_cpp_trivially_relocatable`` (C++): Returns true if an object
18311832
is trivially relocatable, as defined by the C++26 standard [meta.unary.prop].
1832-
Note that the caller code should ensure that if the object is polymorphic,
1833-
the dynamic type is of the most derived type.
1833+
Note that when relocating the caller code should ensure that if the object is polymorphic,
1834+
the dynamic type is of the most derived type. Padding bytes should not be copied.
18341835
* ``__builtin_is_replaceable`` (C++): Returns true if an object
18351836
is replaceable, as defined by the C++26 standard [meta.unary.prop].
18361837
* ``__is_trivially_equality_comparable`` (Clang): Returns true if comparing two

clang/lib/AST/Type.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,7 +2848,7 @@ bool QualType::isTriviallyRelocatableType(const ASTContext &Context) const {
28482848
return false;
28492849
} else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
28502850
return RD->canPassInRegisters();
2851-
} else if (BaseElementType.isTriviallyCopyableType(Context)) {
2851+
} else if (BaseElementType.isCppTriviallyRelocatableType(Context)) {
28522852
return true;
28532853
} else {
28542854
switch (isNonTrivialToPrimitiveDestructiveMove()) {
@@ -2864,10 +2864,16 @@ bool QualType::isTriviallyRelocatableType(const ASTContext &Context) const {
28642864

28652865
bool QualType::isCppTriviallyRelocatableType(const ASTContext &Context) const {
28662866
QualType BaseElementType = Context.getBaseElementType(*this);
2867+
2868+
if (hasNonTrivialObjCLifetime())
2869+
return false;
2870+
28672871
if (BaseElementType->isIncompleteType())
28682872
return false;
2869-
if (BaseElementType->isScalarType())
2873+
2874+
if (BaseElementType->isScalarType() || BaseElementType->isVectorType())
28702875
return true;
2876+
28712877
if (const auto *RD = BaseElementType->getAsCXXRecordDecl())
28722878
return RD->isTriviallyRelocatable();
28732879
return false;

0 commit comments

Comments
 (0)