https://github.com/y-Adrian updated https://github.com/llvm/llvm-project/pull/163839
>From 7aed3bac0c69b768a13d34125a4608c7b94a7553 Mon Sep 17 00:00:00 2001 From: Adrian <[email protected]> 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 | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp index 88fedf1acc6a1..841d4898d1d7e 100644 --- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp @@ -957,8 +957,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: return "_ZTVN10__cxxabiv116__enum_type_infoE"; diff --git a/clang/test/CIR/CodeGen/throws.cpp b/clang/test/CIR/CodeGen/throws.cpp index 53af1efc22cd4..8d56f772e28a5 100644 --- a/clang/test/CIR/CodeGen/throws.cpp +++ b/clang/test/CIR/CodeGen/throws.cpp @@ -244,3 +244,55 @@ void throw_enum_class_expr() { // OGCG: store i32 0, ptr %[[EXCEPTION_ADDR]], align 16 // OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIZ21throw_enum_class_exprvE4Test, ptr null) // OGCG: unreachable + +void throw_func_prototype_type() { + typedef int FuncProto(int, double); + FuncProto* fptr; + throw fptr; +} + +// CIR: %[[F_ADDR:.*]] = cir.alloca !cir.ptr{{.*}}, ["fptr"] +// CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 8 -> !cir.ptr{{.*}} +// CIR: %[[TMP_F:.*]] = cir.load{{.*}} %[[F_ADDR]] : !cir.ptr{{.*}}, !cir.ptr{{.*}} +// CIR: cir.store{{.*}} %[[TMP_F]], %[[EXCEPTION_ADDR]] : !cir.ptr{{.*}}, !cir.ptr{{.*}} +// CIR: cir.throw %[[EXCEPTION_ADDR]] : !cir.ptr{{.*}}, @_ZTI{{.*}} +// CIR: cir.unreachable + +// LLVM: %[[F_ADDR:.*]] = alloca ptr, i64 1, align 8 +// LLVM: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 8) +// LLVM: %[[TMP_F:.*]] = load ptr, ptr %[[F_ADDR]], align 8 +// LLVM: store ptr %[[TMP_F]], ptr %[[EXCEPTION_ADDR]], align 16 +// LLVM: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTI{{.*}}, ptr null) + +// OGCG: %[[F_ADDR:.*]] = alloca ptr, align 8 +// OGCG: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 8) +// OGCG: %[[TMP_F:.*]] = load ptr, ptr %[[F_ADDR]], align 8 +// OGCG: store ptr %[[TMP_F]], ptr %[[EXCEPTION_ADDR]], align 16 +// OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTI{{.*}}, ptr null) +// OGCG: unreachable + +void throw_func_no_prototype_type() { + typedef void FuncNoProto(); + FuncNoProto* fptr; + throw fptr; +} + +// CIR: %[[FNP_ADDR:.*]] = cir.alloca !cir.ptr{{.*}}, ["fptr"] +// CIR: %[[EXCEPTION_ADDR_FN:.*]] = cir.alloc.exception 8 -> !cir.ptr{{.*}} +// CIR: %[[TMP_FNP:.*]] = cir.load{{.*}} %[[FNP_ADDR]] : !cir.ptr{{.*}}, !cir.ptr{{.*}} +// CIR: cir.store{{.*}} %[[TMP_FNP]], %[[EXCEPTION_ADDR_FN]] : !cir.ptr{{.*}}, !cir.ptr{{.*}} +// CIR: cir.throw %[[EXCEPTION_ADDR_FN]] : !cir.ptr{{.*}}, @_ZTI{{.*}} +// CIR: cir.unreachable + +// LLVM: %[[FNP_ADDR:.*]] = alloca ptr, i64 1, align 8 +// LLVM: %[[EXCEPTION_ADDR_FN:.*]] = call ptr @__cxa_allocate_exception(i64 8) +// LLVM: %[[TMP_FNP:.*]] = load ptr, ptr %[[FNP_ADDR]], align 8 +// LLVM: store ptr %[[TMP_FNP]], ptr %[[EXCEPTION_ADDR_FN]], align 16 +// LLVM: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR_FN]], ptr @_ZTI{{.*}}, ptr null) + +// OGCG: %[[FNP_ADDR:.*]] = alloca ptr, align 8 +// OGCG: %[[EXCEPTION_ADDR_FN:.*]] = call ptr @__cxa_allocate_exception(i64 8) +// OGCG: %[[TMP_FNP:.*]] = load ptr, ptr %[[FNP_ADDR]], align 8 +// OGCG: store ptr %[[TMP_FNP]], ptr %[[EXCEPTION_ADDR_FN]], align 16 +// OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR_FN]], ptr @_ZTI{{.*}}, ptr null) +// OGCG: unreachable \ No newline at end of file _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
