[clang] [CIR]lAdd name for function type in vtable (PR #163839)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 28 08:52:06 PDT 2025


https://github.com/y-Adrian updated https://github.com/llvm/llvm-project/pull/163839

>From 1a70de22f665d928217ef77755633946e01ae720 Mon Sep 17 00:00:00 2001
From: Adrian <zhaoxu7263 at 163.com>
Date: Fri, 17 Oct 2025 01:56:33 +0800
Subject: [PATCH] [CIR]llvm#163601:handle function type

---
 clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp |  3 +--
 clang/test/CIR/CodeGen/throws.cpp             | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
index 1b85a530cbdd7..608a965235f26 100644
--- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
@@ -946,8 +946,7 @@ const char *vTableClassNameForType(const CIRGenModule &cgm, const Type *ty) {
 
   case Type::FunctionNoProto:
   case Type::FunctionProto:
-    cgm.errorNYI("VTableClassNameForType: __function_type_info");
-    break;
+    return "_ZTVN10__cxxabiv120__function_type_infoE";
 
   case Type::Enum:
     cgm.errorNYI("VTableClassNameForType: Enum");
diff --git a/clang/test/CIR/CodeGen/throws.cpp b/clang/test/CIR/CodeGen/throws.cpp
index 89cb0729c636c..57a6c147fbe0d 100644
--- a/clang/test/CIR/CodeGen/throws.cpp
+++ b/clang/test/CIR/CodeGen/throws.cpp
@@ -196,3 +196,21 @@ void throw_ext_vector_type() {
 // OGCG: store <4 x i32> %[[TMP_A]], ptr %[[EXCEPTION_ADDR]], align 16
 // OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIDv4_i, ptr null)
 // OGCG: unreachable
+
+// Make the compiler emit RTTI/type_info for function types; this should
+// exercise vTableClassNameForType's FunctionNoProto/FunctionProto cases.
+void throw_func_prototype_type() {
+  typedef int FuncProto(int, double);
+  FuncProto* fptr = nullptr;
+  throw fptr;
+}
+
+void throw_func_no_prototype_type() {
+  typedef void FuncNoProto();
+  FuncNoProto* fptr = nullptr;
+  throw fptr;
+}
+
+// CIR: @_ZTVN10__cxxabiv120__function_type_infoE
+// LLVM: @_ZTVN10__cxxabiv120__function_type_infoE
+// OGCG: @_ZTVN10__cxxabiv120__function_type_infoE
\ No newline at end of file



More information about the cfe-commits mailing list