Author: Erich Keane Date: 2026-04-07T11:02:56-07:00 New Revision: 1d6ad6e951411ee1153147accde2f6dd7fcb6128
URL: https://github.com/llvm/llvm-project/commit/1d6ad6e951411ee1153147accde2f6dd7fcb6128 DIFF: https://github.com/llvm/llvm-project/commit/1d6ad6e951411ee1153147accde2f6dd7fcb6128.diff LOG: [CIR] Implement 'zero attr' creation of method (#190819) This appears quite a bit in some benchmarks, and is seemingly something we missed at one point. This patch just implements a 'zero-init' of a pmf. Added: Modified: clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h clang/test/CIR/CodeGen/pointer-to-member-func.cpp Removed: ################################################################################ diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h index a370622ec0022..f7cbd5d4ce7b7 100644 --- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h +++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h @@ -125,6 +125,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { return cir::ZeroAttr::get(recordTy); if (auto dataMemberTy = mlir::dyn_cast<cir::DataMemberType>(ty)) return getNullDataMemberAttr(dataMemberTy); + if (auto methodTy = mlir::dyn_cast<cir::MethodType>(ty)) + return getNullMethodAttr(methodTy); if (mlir::isa<cir::BoolType>(ty)) { return getFalseAttr(); } diff --git a/clang/test/CIR/CodeGen/pointer-to-member-func.cpp b/clang/test/CIR/CodeGen/pointer-to-member-func.cpp index 540ecd93674bd..a7bf04519575f 100644 --- a/clang/test/CIR/CodeGen/pointer-to-member-func.cpp +++ b/clang/test/CIR/CodeGen/pointer-to-member-func.cpp @@ -34,6 +34,13 @@ void (Foo::*m2_ptr)(int) = &Foo::m2; // LLVM-DAG: @m2_ptr = global { i64, i64 } { i64 1, i64 0 } // OGCG: @m2_ptr = global { i64, i64 } { i64 1, i64 0 } +// Self-referencing PMF causes a null method. +long (Foo::*pmf1)(int) = pmf1; +// CIR-BEFORE: @pmf1 = ctor : !cir.method<!cir.func<(!cir.ptr<!rec_Foo>, !s32i) -> !s64i> in !rec_Foo> { +// CIR-AFTER: cir.global external @pmf1 = #cir.const_record<{#cir.int<0> : !s64i, #cir.int<0> : !s64i}> +// LLVM: @pmf1 = global { i64, i64 } zeroinitializer, align 8 +// OGCG: @pmf1 = global { i64, i64 } zeroinitializer, align 8 + auto make_non_virtual() -> void (Foo::*)(int) { return &Foo::m1; } @@ -198,3 +205,4 @@ void call(Foo *obj, void (Foo::*func)(int), int arg) { // OGCG: %[[ARG:.*]] = load i32, ptr %{{.+}} // OGCG: call void %[[CALLEE_PTR]](ptr {{.*}} %[[ADJUSTED_THIS]], i32 {{.*}} %[[ARG]]) // OGCG: } + _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
