https://github.com/ojhunt created 
https://github.com/llvm/llvm-project/pull/156607

…types

Clang has 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.

>From 76ec5a58f3e63b192f490d691ee236800f14ee16 Mon Sep 17 00:00:00 2001
From: Oliver Hunt <[email protected]>
Date: Wed, 3 Sep 2025 00:13:09 -0700
Subject: [PATCH] [clang] Polymorphic Cleanup type is moved despite not being
 true POD types

Clang has 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.
---
 clang/lib/CIR/CodeGen/EHScopeStack.h | 2 +-
 clang/lib/CodeGen/EHScopeStack.h     | 2 +-
 llvm/include/llvm/Support/Compiler.h | 9 +++++++++
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/EHScopeStack.h 
b/clang/lib/CIR/CodeGen/EHScopeStack.h
index 47478f6cf4bb3..c87a6ef9660ad 100644
--- a/clang/lib/CIR/CodeGen/EHScopeStack.h
+++ b/clang/lib/CIR/CodeGen/EHScopeStack.h
@@ -90,7 +90,7 @@ class EHScopeStack {
   ///
   /// Cleanup implementations should generally be declared in an
   /// anonymous namespace.
-  class Cleanup {
+  class LLVM_MOVABLE_POLYMORPHIC_TYPE Cleanup {
     // Anchor the construction vtable.
     virtual void anchor();
 
diff --git a/clang/lib/CodeGen/EHScopeStack.h b/clang/lib/CodeGen/EHScopeStack.h
index 54f6ceaa52b95..2dcb75556c4e5 100644
--- a/clang/lib/CodeGen/EHScopeStack.h
+++ b/clang/lib/CodeGen/EHScopeStack.h
@@ -143,7 +143,7 @@ class EHScopeStack {
   ///
   /// Cleanup implementations should generally be declared in an
   /// anonymous namespace.
-  class alignas(uint64_t) Cleanup {
+  class LLVM_MOVABLE_POLYMORPHIC_TYPE alignas(uint64_t) Cleanup {
     // Anchor the construction vtable.
     virtual void anchor();
 
diff --git a/llvm/include/llvm/Support/Compiler.h 
b/llvm/include/llvm/Support/Compiler.h
index 297d3e9b04095..56f498a36ae52 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -706,6 +706,15 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
 #define LLVM_PREFERRED_TYPE(T)
 #endif
 
+#if LLVM_HAS_CPP_ATTRIBUTE(clang::ptrauth_vtable_pointer) &&                   
\
+    (defined(__PTRAUTH__) || __has_feature(ptrauth_calls))
+#define LLVM_MOVABLE_POLYMORPHIC_TYPE                                          
\
+  [[clang::ptrauth_vtable_pointer(default_key, no_address_discrimination,      
\
+                                  default_extra_discrimination)]]
+#else
+#define LLVM_MOVABLE_POLYMORPHIC_TYPE
+#endif
+
 /// \macro LLVM_VIRTUAL_ANCHOR_FUNCTION
 /// This macro is used to adhere to LLVM's policy that each class with a vtable
 /// must have at least one out-of-line virtual function. This macro allows us

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to