Skip to content

Commit 7aed3ba

Browse files
committed
[CIR]#163601:handle function type
1 parent 0b1ef8c commit 7aed3ba

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,7 @@ const char *vTableClassNameForType(const CIRGenModule &cgm, const Type *ty) {
957957

958958
case Type::FunctionNoProto:
959959
case Type::FunctionProto:
960-
cgm.errorNYI("VTableClassNameForType: __function_type_info");
961-
break;
960+
return "_ZTVN10__cxxabiv120__function_type_infoE";
962961

963962
case Type::Enum:
964963
return "_ZTVN10__cxxabiv116__enum_type_infoE";

clang/test/CIR/CodeGen/throws.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,55 @@ void throw_enum_class_expr() {
244244
// OGCG: store i32 0, ptr %[[EXCEPTION_ADDR]], align 16
245245
// OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIZ21throw_enum_class_exprvE4Test, ptr null)
246246
// OGCG: unreachable
247+
248+
void throw_func_prototype_type() {
249+
typedef int FuncProto(int, double);
250+
FuncProto* fptr;
251+
throw fptr;
252+
}
253+
254+
// CIR: %[[F_ADDR:.*]] = cir.alloca !cir.ptr{{.*}}, ["fptr"]
255+
// CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 8 -> !cir.ptr{{.*}}
256+
// CIR: %[[TMP_F:.*]] = cir.load{{.*}} %[[F_ADDR]] : !cir.ptr{{.*}}, !cir.ptr{{.*}}
257+
// CIR: cir.store{{.*}} %[[TMP_F]], %[[EXCEPTION_ADDR]] : !cir.ptr{{.*}}, !cir.ptr{{.*}}
258+
// CIR: cir.throw %[[EXCEPTION_ADDR]] : !cir.ptr{{.*}}, @_ZTI{{.*}}
259+
// CIR: cir.unreachable
260+
261+
// LLVM: %[[F_ADDR:.*]] = alloca ptr, i64 1, align 8
262+
// LLVM: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 8)
263+
// LLVM: %[[TMP_F:.*]] = load ptr, ptr %[[F_ADDR]], align 8
264+
// LLVM: store ptr %[[TMP_F]], ptr %[[EXCEPTION_ADDR]], align 16
265+
// LLVM: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTI{{.*}}, ptr null)
266+
267+
// OGCG: %[[F_ADDR:.*]] = alloca ptr, align 8
268+
// OGCG: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 8)
269+
// OGCG: %[[TMP_F:.*]] = load ptr, ptr %[[F_ADDR]], align 8
270+
// OGCG: store ptr %[[TMP_F]], ptr %[[EXCEPTION_ADDR]], align 16
271+
// OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTI{{.*}}, ptr null)
272+
// OGCG: unreachable
273+
274+
void throw_func_no_prototype_type() {
275+
typedef void FuncNoProto();
276+
FuncNoProto* fptr;
277+
throw fptr;
278+
}
279+
280+
// CIR: %[[FNP_ADDR:.*]] = cir.alloca !cir.ptr{{.*}}, ["fptr"]
281+
// CIR: %[[EXCEPTION_ADDR_FN:.*]] = cir.alloc.exception 8 -> !cir.ptr{{.*}}
282+
// CIR: %[[TMP_FNP:.*]] = cir.load{{.*}} %[[FNP_ADDR]] : !cir.ptr{{.*}}, !cir.ptr{{.*}}
283+
// CIR: cir.store{{.*}} %[[TMP_FNP]], %[[EXCEPTION_ADDR_FN]] : !cir.ptr{{.*}}, !cir.ptr{{.*}}
284+
// CIR: cir.throw %[[EXCEPTION_ADDR_FN]] : !cir.ptr{{.*}}, @_ZTI{{.*}}
285+
// CIR: cir.unreachable
286+
287+
// LLVM: %[[FNP_ADDR:.*]] = alloca ptr, i64 1, align 8
288+
// LLVM: %[[EXCEPTION_ADDR_FN:.*]] = call ptr @__cxa_allocate_exception(i64 8)
289+
// LLVM: %[[TMP_FNP:.*]] = load ptr, ptr %[[FNP_ADDR]], align 8
290+
// LLVM: store ptr %[[TMP_FNP]], ptr %[[EXCEPTION_ADDR_FN]], align 16
291+
// LLVM: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR_FN]], ptr @_ZTI{{.*}}, ptr null)
292+
293+
// OGCG: %[[FNP_ADDR:.*]] = alloca ptr, align 8
294+
// OGCG: %[[EXCEPTION_ADDR_FN:.*]] = call ptr @__cxa_allocate_exception(i64 8)
295+
// OGCG: %[[TMP_FNP:.*]] = load ptr, ptr %[[FNP_ADDR]], align 8
296+
// OGCG: store ptr %[[TMP_FNP]], ptr %[[EXCEPTION_ADDR_FN]], align 16
297+
// OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR_FN]], ptr @_ZTI{{.*}}, ptr null)
298+
// OGCG: unreachable

0 commit comments

Comments
 (0)