[clang] [CIR] Add initial support for dynamic cast (PR #162337)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 9 13:48:11 PDT 2025


================
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare %s -o %t.cir 2> %t.before.log
+// RUN: FileCheck %s --input-file=%t.before.log -check-prefix=CIR-BEFORE
+
+struct Base {
+  virtual ~Base();
+};
+
+struct Derived : Base {};
+
+// CIR-BEFORE-DAG: !rec_Base = !cir.record
+// CIR-BEFORE-DAG: !rec_Derived = !cir.record
+// CIR-BEFORE-DAG: #dyn_cast_info__ZTI4Base__ZTI7Derived = #cir.dyn_cast_info<src_rtti = #cir.global_view<@_ZTI4Base> : !cir.ptr<!u8i>, dest_rtti = #cir.global_view<@_ZTI7Derived> : !cir.ptr<!u8i>, runtime_func = @__dynamic_cast, bad_cast_func = @__cxa_bad_cast, offset_hint = #cir.int<0> : !s64i>
----------------
andykaylor wrote:

@bcardosolopes I started looking at this, and the problem is that during LoweringPrepare, we extract this value from the attribute and pass it to a call to `__dynamic_cast`. I think it makes sense to leave it as a `#cir.int`.

https://github.com/llvm/llvm-project/pull/162337


More information about the cfe-commits mailing list