Skip to content

Commit fd7f464

Browse files
authored
[clang] Polymorphic Cleanup type is moved despite not being POD types (#156607)
Clang as a number of Cleanup types used in exception handling, these are presumed to be POD types that can be memmoved as needed, however this is not correct by default on platforms with pointer authentication that make vtable pointers address discriminated. This PR mitigates this problem by introducing a LLVM_MOVABLE_POLYMORPHIC_TYPE macro that can be used to annotate polymorphic types that are required to be movable, to override the use of address discrimination of the vtable pointer.
1 parent e46942a commit fd7f464

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

clang/lib/CIR/CodeGen/EHScopeStack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class EHScopeStack {
9090
///
9191
/// Cleanup implementations should generally be declared in an
9292
/// anonymous namespace.
93-
class Cleanup {
93+
class LLVM_MOVABLE_POLYMORPHIC_TYPE Cleanup {
9494
// Anchor the construction vtable.
9595
virtual void anchor();
9696

clang/lib/CodeGen/EHScopeStack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class EHScopeStack {
143143
///
144144
/// Cleanup implementations should generally be declared in an
145145
/// anonymous namespace.
146-
class alignas(uint64_t) Cleanup {
146+
class LLVM_MOVABLE_POLYMORPHIC_TYPE alignas(uint64_t) Cleanup {
147147
// Anchor the construction vtable.
148148
virtual void anchor();
149149

llvm/include/llvm/Support/Compiler.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,15 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
706706
#define LLVM_PREFERRED_TYPE(T)
707707
#endif
708708

709+
#if LLVM_HAS_CPP_ATTRIBUTE(clang::ptrauth_vtable_pointer) && \
710+
(defined(__PTRAUTH__) || __has_feature(ptrauth_calls))
711+
#define LLVM_MOVABLE_POLYMORPHIC_TYPE \
712+
[[clang::ptrauth_vtable_pointer(default_key, no_address_discrimination, \
713+
default_extra_discrimination)]]
714+
#else
715+
#define LLVM_MOVABLE_POLYMORPHIC_TYPE
716+
#endif
717+
709718
/// \macro LLVM_VIRTUAL_ANCHOR_FUNCTION
710719
/// This macro is used to adhere to LLVM's policy that each class with a vtable
711720
/// must have at least one out-of-line virtual function. This macro allows us

0 commit comments

Comments
 (0)