Skip to content

Commit 6a4fa08

Browse files
authored
Revert "[Clang] Deprecate __is_trivially_relocatable (#138835)"
This reverts commit 43c514b.
1 parent 215dbcb commit 6a4fa08

File tree

7 files changed

+53
-140
lines changed

7 files changed

+53
-140
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,18 +1859,12 @@ The following type trait primitives are supported by Clang. Those traits marked
18591859
* ``__is_trivially_constructible`` (C++, GNU, Microsoft)
18601860
* ``__is_trivially_copyable`` (C++, GNU, Microsoft)
18611861
* ``__is_trivially_destructible`` (C++, MSVC 2013)
1862-
* ``__is_trivially_relocatable`` (Clang) (Deprecated,
1863-
use ``__builtin_is_cpp_trivially_relocatable`` instead).
1864-
Returns true if moving an object
1862+
* ``__is_trivially_relocatable`` (Clang): Returns true if moving an object
18651863
of the given type, and then destroying the source object, is known to be
18661864
functionally equivalent to copying the underlying bytes and then dropping the
18671865
source object on the floor. This is true of trivial types,
18681866
C++26 relocatable types, and types which
18691867
were made trivially relocatable via the ``clang::trivial_abi`` attribute.
1870-
This trait is deprecated and should be replaced by
1871-
``__builtin_is_cpp_trivially_relocatable``. Note however that it is generally
1872-
unsafe to relocate a C++-relocatable type with ``memcpy`` or ``memmove``;
1873-
use ``__builtin_trivially_relocate``.
18741868
* ``__builtin_is_cpp_trivially_relocatable`` (C++): Returns true if an object
18751869
is trivially relocatable, as defined by the C++26 standard [meta.unary.prop].
18761870
Note that when relocating the caller code should ensure that if the object is polymorphic,

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -579,15 +579,6 @@ Bug Fixes to Compiler Builtins
579579
- ``__has_unique_object_representations(Incomplete[])`` is no longer accepted, per
580580
`LWG4113 <https://cplusplus.github.io/LWG/issue4113>`_.
581581

582-
- ``__builtin_is_cpp_trivially_relocatable``, ``__builtin_is_replaceable`` and
583-
``__builtin_trivially_relocate`` have been added to support standard C++26 relocation.
584-
585-
- ``__is_trivially_relocatable`` has been deprecated, and uses should be replaced by
586-
``__builtin_is_cpp_trivially_relocatable``.
587-
Note that, it is generally unsafe to ``memcpy`` non-trivially copyable types that
588-
are ``__builtin_is_cpp_trivially_relocatable``. It is recommended to use
589-
``__builtin_trivially_relocate`` instead.
590-
591582
Bug Fixes to Attribute Support
592583
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
593584
- Fixed crash when a parameter to the ``clang::annotate`` attribute evaluates to ``void``. See #GH119125

clang/include/clang/Basic/TokenKinds.def

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ TYPE_TRAIT_2(__is_pointer_interconvertible_base_of, IsPointerInterconvertibleBas
544544
#include "clang/Basic/TransformTypeTraits.def"
545545

546546
// Clang-only C++ Type Traits
547+
TYPE_TRAIT_1(__is_trivially_relocatable, IsTriviallyRelocatable, KEYCXX)
547548
TYPE_TRAIT_1(__is_trivially_equality_comparable, IsTriviallyEqualityComparable, KEYCXX)
548549
TYPE_TRAIT_1(__is_bounded_array, IsBoundedArray, KEYCXX)
549550
TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
@@ -555,11 +556,8 @@ TYPE_TRAIT_2(__reference_converts_from_temporary, ReferenceConvertsFromTemporary
555556
// IsDeducible is only used internally by clang for CTAD implementation and
556557
// is not exposed to users.
557558
TYPE_TRAIT_2(/*EmptySpellingName*/, IsDeducible, KEYCXX)
558-
559-
// __is_trivially_relocatable is deprecated
560-
TYPE_TRAIT_1(__builtin_is_cpp_trivially_relocatable, IsCppTriviallyRelocatable, KEYCXX)
561-
TYPE_TRAIT_1(__is_trivially_relocatable, IsTriviallyRelocatable, KEYCXX)
562559
TYPE_TRAIT_1(__is_bitwise_cloneable, IsBitwiseCloneable, KEYALL)
560+
TYPE_TRAIT_1(__builtin_is_cpp_trivially_relocatable, IsCppTriviallyRelocatable, KEYCXX)
563561
TYPE_TRAIT_1(__builtin_is_replaceable, IsReplaceable, KEYCXX)
564562
TYPE_TRAIT_1(__builtin_structured_binding_size, StructuredBindingSize, KEYCXX)
565563

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6449,9 +6449,6 @@ void DiagnoseBuiltinDeprecation(Sema& S, TypeTrait Kind,
64496449
case UTT_HasTrivialDestructor:
64506450
Replacement = UTT_IsTriviallyDestructible;
64516451
break;
6452-
case UTT_IsTriviallyRelocatable:
6453-
Replacement = clang::UTT_IsCppTriviallyRelocatable;
6454-
break;
64556452
default:
64566453
return;
64576454
}
Lines changed: 33 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
2-
// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-windows-msvc -std=c++11
3-
42

53
void __attribute__((trivial_abi)) foo(); // expected-warning {{'trivial_abi' attribute only applies to classes}}
64

@@ -12,38 +10,30 @@ class __attribute__((trivial_abi)) a { a(a &&); };
1210
// (And it is only trivially relocatable, currently, if it is trivial for calls.)
1311
// In this case, it is suppressed by an explicitly defined move constructor.
1412
// Similar concerns apply to later tests that have #if defined(_WIN64) && !defined(__MINGW32__)
15-
static_assert(!__is_trivially_relocatable(a<int>), ""); // expected-warning{{deprecated}}
16-
static_assert(!__builtin_is_cpp_trivially_relocatable(a<int>), "");
13+
static_assert(!__is_trivially_relocatable(a<int>), "");
1714
#else
18-
static_assert(__is_trivially_relocatable(a<int>), ""); // expected-warning{{deprecated}}
19-
static_assert(!__builtin_is_cpp_trivially_relocatable(a<int>), "");
15+
static_assert(__is_trivially_relocatable(a<int>), "");
2016
#endif
2117

2218
struct [[clang::trivial_abi]] S0 {
2319
int a;
2420
};
25-
static_assert(__is_trivially_relocatable(S0), ""); // expected-warning{{deprecated}}
26-
static_assert(__builtin_is_cpp_trivially_relocatable(S0), "");
21+
static_assert(__is_trivially_relocatable(S0), "");
2722

2823
struct __attribute__((trivial_abi)) S1 {
2924
int a;
3025
};
31-
static_assert(__is_trivially_relocatable(S1), ""); // expected-warning{{deprecated}}
32-
static_assert(__builtin_is_cpp_trivially_relocatable(S1), "");
33-
26+
static_assert(__is_trivially_relocatable(S1), "");
3427

3528
struct __attribute__((trivial_abi)) S3 { // expected-warning {{'trivial_abi' cannot be applied to 'S3'}} expected-note {{is polymorphic}}
3629
virtual void m();
3730
};
38-
static_assert(!__is_trivially_relocatable(S3), ""); // expected-warning{{deprecated}}
39-
static_assert(__builtin_is_cpp_trivially_relocatable(S3), "");
40-
31+
static_assert(!__is_trivially_relocatable(S3), "");
4132

4233
struct S3_2 {
4334
virtual void m();
4435
} __attribute__((trivial_abi)); // expected-warning {{'trivial_abi' cannot be applied to 'S3_2'}} expected-note {{is polymorphic}}
45-
static_assert(!__is_trivially_relocatable(S3_2), ""); // expected-warning{{deprecated}}
46-
static_assert(__builtin_is_cpp_trivially_relocatable(S3_2), "");
36+
static_assert(!__is_trivially_relocatable(S3_2), "");
4737

4838
struct __attribute__((trivial_abi)) S3_3 { // expected-warning {{'trivial_abi' cannot be applied to 'S3_3'}} expected-note {{has a field of a non-trivial class type}}
4939
S3_3(S3_3 &&);
@@ -53,13 +43,9 @@ struct __attribute__((trivial_abi)) S3_3 { // expected-warning {{'trivial_abi' c
5343
// The ClangABI4OrPS4 calling convention kind passes classes in registers if the
5444
// copy constructor is trivial for calls *or deleted*, while other platforms do
5545
// not accept deleted constructors.
56-
static_assert(__is_trivially_relocatable(S3_3), ""); // expected-warning{{deprecated}}
57-
static_assert(__builtin_is_cpp_trivially_relocatable(S3_3), "");
58-
46+
static_assert(__is_trivially_relocatable(S3_3), "");
5947
#else
60-
static_assert(!__is_trivially_relocatable(S3_3), ""); // expected-warning{{deprecated}}
61-
static_assert(!__builtin_is_cpp_trivially_relocatable(S3_3), "");
62-
48+
static_assert(!__is_trivially_relocatable(S3_3), "");
6349
#endif
6450

6551
// Diagnose invalid trivial_abi even when the type is templated because it has a non-trivial field.
@@ -68,28 +54,20 @@ struct __attribute__((trivial_abi)) S3_4 { // expected-warning {{'trivial_abi' c
6854
S3_4(S3_4 &&);
6955
S3_2 s32;
7056
};
71-
static_assert(!__is_trivially_relocatable(S3_4<int>), ""); // expected-warning{{deprecated}}
72-
static_assert(!__builtin_is_cpp_trivially_relocatable(S3_4<int>), "");
73-
57+
static_assert(!__is_trivially_relocatable(S3_4<int>), "");
7458

7559
struct S4 {
7660
int a;
7761
};
78-
static_assert(__is_trivially_relocatable(S4), ""); // expected-warning{{deprecated}}
79-
static_assert(__builtin_is_cpp_trivially_relocatable(S4), "");
80-
62+
static_assert(__is_trivially_relocatable(S4), "");
8163

8264
struct __attribute__((trivial_abi)) S5 : public virtual S4 { // expected-warning {{'trivial_abi' cannot be applied to 'S5'}} expected-note {{has a virtual base}}
8365
};
84-
static_assert(!__is_trivially_relocatable(S5), ""); // expected-warning{{deprecated}}
85-
static_assert(!__builtin_is_cpp_trivially_relocatable(S5), "");
86-
66+
static_assert(!__is_trivially_relocatable(S5), "");
8767

8868
struct __attribute__((trivial_abi)) S9 : public S4 {
8969
};
90-
static_assert(__is_trivially_relocatable(S9), ""); // expected-warning{{deprecated}}
91-
static_assert(__builtin_is_cpp_trivially_relocatable(S9), "");
92-
70+
static_assert(__is_trivially_relocatable(S9), "");
9371

9472
struct __attribute__((trivial_abi(1))) S8 { // expected-error {{'trivial_abi' attribute takes no arguments}}
9573
int a;
@@ -102,12 +80,8 @@ struct __attribute__((trivial_abi)) S10 {
10280
};
10381

10482
S10<int *> p1;
105-
static_assert(__is_trivially_relocatable(S10<int>), ""); // expected-warning{{deprecated}}
106-
static_assert(__builtin_is_cpp_trivially_relocatable(S10<int>), "");
107-
108-
static_assert(__is_trivially_relocatable(S10<S3>), ""); // expected-warning{{deprecated}}
109-
static_assert(__builtin_is_cpp_trivially_relocatable(S10<S3>), "");
110-
83+
static_assert(__is_trivially_relocatable(S10<int>), "");
84+
static_assert(__is_trivially_relocatable(S10<S3>), "");
11185

11286
template <class T>
11387
struct S14 {
@@ -119,21 +93,15 @@ struct __attribute__((trivial_abi)) S15 : S14<T> {
11993
};
12094

12195
S15<int> s15;
122-
static_assert(__is_trivially_relocatable(S15<int>), ""); // expected-warning{{deprecated}}
123-
static_assert(__builtin_is_cpp_trivially_relocatable(S15<int>), "");
124-
125-
static_assert(__is_trivially_relocatable(S15<S3>), ""); // expected-warning{{deprecated}}
126-
static_assert(__builtin_is_cpp_trivially_relocatable(S15<S3>), "");
96+
static_assert(__is_trivially_relocatable(S15<int>), "");
97+
static_assert(__is_trivially_relocatable(S15<S3>), "");
12798

12899
template <class T>
129100
struct __attribute__((trivial_abi)) S16 {
130101
S14<T> a;
131102
};
132-
static_assert(__is_trivially_relocatable(S16<int>), ""); // expected-warning{{deprecated}}
133-
static_assert(__builtin_is_cpp_trivially_relocatable(S16<int>), "");
134-
135-
static_assert(__is_trivially_relocatable(S16<S3>), ""); // expected-warning{{deprecated}}
136-
static_assert(__builtin_is_cpp_trivially_relocatable(S16<S3>), "");
103+
static_assert(__is_trivially_relocatable(S16<int>), "");
104+
static_assert(__is_trivially_relocatable(S16<S3>), "");
137105

138106
S16<int> s16;
139107

@@ -142,80 +110,62 @@ struct __attribute__((trivial_abi)) S17 {
142110
};
143111

144112
S17<int> s17;
145-
static_assert(__is_trivially_relocatable(S17<int>), ""); // expected-warning{{deprecated}}
146-
static_assert(__builtin_is_cpp_trivially_relocatable(S17<int>), "");
147-
148-
static_assert(__is_trivially_relocatable(S17<S3>), ""); // expected-warning{{deprecated}}
149-
static_assert(__builtin_is_cpp_trivially_relocatable(S17<S3>), "");
150-
113+
static_assert(__is_trivially_relocatable(S17<int>), "");
114+
static_assert(__is_trivially_relocatable(S17<S3>), "");
151115

152116
namespace deletedCopyMoveConstructor {
153117
struct __attribute__((trivial_abi)) CopyMoveDeleted { // expected-warning {{'trivial_abi' cannot be applied to 'CopyMoveDeleted'}} expected-note {{copy constructors and move constructors are all deleted}}
154118
CopyMoveDeleted(const CopyMoveDeleted &) = delete;
155119
CopyMoveDeleted(CopyMoveDeleted &&) = delete;
156120
};
157121
#ifdef __ORBIS__
158-
static_assert(__is_trivially_relocatable(CopyMoveDeleted), ""); // expected-warning{{deprecated}}
159-
static_assert(__builtin_is_cpp_trivially_relocatable(CopyMoveDeleted), "");
160-
122+
static_assert(__is_trivially_relocatable(CopyMoveDeleted), "");
161123
#else
162-
static_assert(!__is_trivially_relocatable(CopyMoveDeleted), ""); // expected-warning{{deprecated}}
163-
static_assert(!__builtin_is_cpp_trivially_relocatable(CopyMoveDeleted), "");
164-
124+
static_assert(!__is_trivially_relocatable(CopyMoveDeleted), "");
165125
#endif
166126

167127
struct __attribute__((trivial_abi)) S18 { // expected-warning {{'trivial_abi' cannot be applied to 'S18'}} expected-note {{copy constructors and move constructors are all deleted}}
168128
CopyMoveDeleted a;
169129
};
170130
#ifdef __ORBIS__
171-
static_assert(__is_trivially_relocatable(S18), ""); // expected-warning{{deprecated}}
172-
static_assert(__builtin_is_cpp_trivially_relocatable(S18), "");
131+
static_assert(__is_trivially_relocatable(S18), "");
173132
#else
174-
static_assert(!__is_trivially_relocatable(S18), ""); // expected-warning{{deprecated}}
175-
static_assert(!__builtin_is_cpp_trivially_relocatable(S18), "");
133+
static_assert(!__is_trivially_relocatable(S18), "");
176134
#endif
177135

178136
struct __attribute__((trivial_abi)) CopyDeleted {
179137
CopyDeleted(const CopyDeleted &) = delete;
180138
CopyDeleted(CopyDeleted &&) = default;
181139
};
182140
#if defined(_WIN64) && !defined(__MINGW32__)
183-
static_assert(!__is_trivially_relocatable(CopyDeleted), ""); // expected-warning{{deprecated}}
184-
static_assert(!__builtin_is_cpp_trivially_relocatable(CopyDeleted), "");
185-
141+
static_assert(!__is_trivially_relocatable(CopyDeleted), "");
186142
#else
187-
static_assert(__is_trivially_relocatable(CopyDeleted), ""); // expected-warning{{deprecated}}
188-
static_assert(!__builtin_is_cpp_trivially_relocatable(CopyDeleted), "");
143+
static_assert(__is_trivially_relocatable(CopyDeleted), "");
189144
#endif
190145

191146
struct __attribute__((trivial_abi)) MoveDeleted {
192147
MoveDeleted(const MoveDeleted &) = default;
193148
MoveDeleted(MoveDeleted &&) = delete;
194149
};
195-
static_assert(__is_trivially_relocatable(MoveDeleted), ""); // expected-warning{{deprecated}}
196-
static_assert(!__builtin_is_cpp_trivially_relocatable(MoveDeleted), "");
150+
static_assert(__is_trivially_relocatable(MoveDeleted), "");
151+
197152
struct __attribute__((trivial_abi)) S19 { // expected-warning {{'trivial_abi' cannot be applied to 'S19'}} expected-note {{copy constructors and move constructors are all deleted}}
198153
CopyDeleted a;
199154
MoveDeleted b;
200155
};
201156
#ifdef __ORBIS__
202-
static_assert(__is_trivially_relocatable(S19), ""); // expected-warning{{deprecated}}
203-
static_assert(__builtin_is_cpp_trivially_relocatable(S19), "");
204-
static_assert(!__is_trivially_relocatable(S19), ""); // expected-warning{{deprecated}}
205-
static_assert(!__builtin_is_cpp_trivially_relocatable(S19), "");
157+
static_assert(__is_trivially_relocatable(S19), "");
158+
#else
159+
static_assert(!__is_trivially_relocatable(S19), "");
206160
#endif
207161

208162
// This is fine since the move constructor isn't deleted.
209163
struct __attribute__((trivial_abi)) S20 {
210164
int &&a; // a member of rvalue reference type deletes the copy constructor.
211165
};
212166
#if defined(_WIN64) && !defined(__MINGW32__)
213-
static_assert(!__is_trivially_relocatable(S20), ""); // expected-warning{{deprecated}}
214-
static_assert(!__builtin_is_cpp_trivially_relocatable(S20), "");
215-
167+
static_assert(!__is_trivially_relocatable(S20), "");
216168
#else
217-
static_assert(__is_trivially_relocatable(S20), ""); // expected-warning{{deprecated}}
218-
static_assert(!__builtin_is_cpp_trivially_relocatable(S20), "");
219-
169+
static_assert(__is_trivially_relocatable(S20), "");
220170
#endif
221171
} // namespace deletedCopyMoveConstructor

0 commit comments

Comments
 (0)