https://github.com/erichkeane created 
https://github.com/llvm/llvm-project/pull/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.

>From f1df3cb4b649758eb6bdd9c826f8e9059e3e3c09 Mon Sep 17 00:00:00 2001
From: erichkeane <[email protected]>
Date: Tue, 7 Apr 2026 09:51:46 -0700
Subject: [PATCH] [CIR] Implement 'zero attr' creation of method

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.
---
 clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h | 2 ++
 clang/test/CIR/CodeGen/pointer-to-member-func.cpp        | 8 ++++++++
 2 files changed, 10 insertions(+)

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

Reply via email to