https://github.com/erichkeane created https://github.com/llvm/llvm-project/pull/190655
This patch ends up being pretty trivial to reproduce, and the implementation is just to call an already implemented function, however this shows up a few times in various test suites. So I've implemented it. >From 92bd725a7615b78de90658483b01aee4f5a2346d Mon Sep 17 00:00:00 2001 From: erichkeane <[email protected]> Date: Mon, 6 Apr 2026 12:15:04 -0700 Subject: [PATCH] [CIR] Implement lowering for member-expr of function decl type This patch ends up being pretty trivial to reproduce, and the implementation is just to call an already implemented function, however this shows up a few times in various test suites. So I've implemented it. --- clang/lib/CIR/CodeGen/CIRGenExpr.cpp | 6 ++---- clang/test/CIR/CodeGen/mem-expr-fn.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 clang/test/CIR/CodeGen/mem-expr-fn.cpp diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp index 91de4581cc8a8..81737aeb4c847 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp @@ -1654,10 +1654,8 @@ LValue CIRGenFunction::emitMemberExpr(const MemberExpr *e) { return lv; } - if (isa<FunctionDecl>(nd)) { - cgm.errorNYI(e->getSourceRange(), "emitMemberExpr: FunctionDecl"); - return LValue(); - } + if (const auto *fd = dyn_cast<FunctionDecl>(nd)) + return emitFunctionDeclLValue(*this, e, fd); llvm_unreachable("Unhandled member declaration!"); } diff --git a/clang/test/CIR/CodeGen/mem-expr-fn.cpp b/clang/test/CIR/CodeGen/mem-expr-fn.cpp new file mode 100644 index 0000000000000..c63fbd848236b --- /dev/null +++ b/clang/test/CIR/CodeGen/mem-expr-fn.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll +// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM + +struct WithStaticMem { + static void StaticMem(); +}; + +extern "C" void use(WithStaticMem m) { + // CIR-LABEL: use( + auto x = m.StaticMem; + // CIR: %[[ARG_ALLOCA:.*]] = cir.alloca !rec_WithStaticMem, !cir.ptr<!rec_WithStaticMem>, ["m", init] + // CIR: %[[X_ALLOCA:.*]] = cir.alloca !cir.ptr<!cir.func<()>>, !cir.ptr<!cir.ptr<!cir.func<()>>>, ["x", init] + // CIR: cir.store %{{.*}}, %[[ARG_ALLOCA]] : !rec_WithStaticMem, !cir.ptr<!rec_WithStaticMem> + // CIR: %[[GET_STATIC_FUNC:.*]] = cir.get_global @_ZN13WithStaticMem9StaticMemEv : !cir.ptr<!cir.func<()>> + // CIR: cir.store {{.*}}%[[GET_STATIC_FUNC]], %[[X_ALLOCA]] : !cir.ptr<!cir.func<()>>, !cir.ptr<!cir.ptr<!cir.func<()>>> + + // LLVM-LABEL: use( + // LLVM: %[[ARG_ALLOCA:.*]] = alloca %struct.WithStaticMem + // LLVM: %[[X_ALLOCA:.*]] = alloca ptr + // LLVM: store ptr @_ZN13WithStaticMem9StaticMemEv, ptr %[[X_ALLOCA]] +} + _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
