[llvm] [orc-rt] Prevent RTTIExtends from being used for errors. (PR #172250)

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 14 21:23:18 PST 2025


https://github.com/lhames updated https://github.com/llvm/llvm-project/pull/172250

>From bc6d2008cae66ccdd1f2b22ac9b05265000b9b69 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Mon, 15 Dec 2025 16:12:43 +1100
Subject: [PATCH 1/2] [orc-rt] Prevent RTTIExtends from being used for errors.

Custom error types (ErrorInfoBase subclasses) should use ErrorExtends as of
8f51da369e6. Adding a static_assert allows us to enforce that at compile-time.
---
 orc-rt/include/orc-rt/RTTI.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/orc-rt/include/orc-rt/RTTI.h b/orc-rt/include/orc-rt/RTTI.h
index 734205200cc6e..e56520db9a4b7 100644
--- a/orc-rt/include/orc-rt/RTTI.h
+++ b/orc-rt/include/orc-rt/RTTI.h
@@ -52,8 +52,12 @@
 #ifndef ORC_RT_RTTI_H
 #define ORC_RT_RTTI_H
 
+#include <type_traits>
+
 namespace orc_rt {
 
+class ErrorInfoBase;
+
 template <typename ThisT, typename ParentT> class RTTIExtends;
 
 /// Base class for the extensible RTTI hierarchy.
@@ -107,6 +111,11 @@ class RTTIRoot {
 ///
 template <typename ThisT, typename ParentT> class RTTIExtends : public ParentT {
 public:
+
+  static_assert(!std::is_base_of_v<ErrorInfoBase, ParentT>,
+                "RTTIExtends should not be used to define orc_rt custom error "
+                "types, use ErrorExtends instead");
+
   // Inherit constructors and isA methods from ParentT.
   using ParentT::isA;
   using ParentT::ParentT;

>From 1fc4a62de5487da5392d2c18559e6db4cf8a71c7 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Mon, 15 Dec 2025 16:23:04 +1100
Subject: [PATCH 2/2] clang-format

---
 orc-rt/include/orc-rt/RTTI.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/orc-rt/include/orc-rt/RTTI.h b/orc-rt/include/orc-rt/RTTI.h
index e56520db9a4b7..8ac96d1aaf4dd 100644
--- a/orc-rt/include/orc-rt/RTTI.h
+++ b/orc-rt/include/orc-rt/RTTI.h
@@ -111,7 +111,6 @@ class RTTIRoot {
 ///
 template <typename ThisT, typename ParentT> class RTTIExtends : public ParentT {
 public:
-
   static_assert(!std::is_base_of_v<ErrorInfoBase, ParentT>,
                 "RTTIExtends should not be used to define orc_rt custom error "
                 "types, use ErrorExtends instead");



More information about the llvm-commits mailing list