[Mlir-commits] [mlir] Use static function to replace lamda function (PR #127333)

Leon Lu llvmlistbot at llvm.org
Sat Feb 15 07:32:23 PST 2025


https://github.com/gfvvz created https://github.com/llvm/llvm-project/pull/127333

Use static function to replace lamda function due to the lamda function's lifetime issue, which may be report an compilation error when use this template.

>From eb165a12784dda2fc0e525b3c0831e00fb54033e Mon Sep 17 00:00:00 2001
From: Leon Lu <gfvvz at 163.com>
Date: Sat, 15 Feb 2025 23:27:46 +0800
Subject: [PATCH] Use static function to replace lamda function

Use static function to replace lamda function due to the lamda function's lifetime issue, which may be report an compilation error when use this template.
---
 mlir/include/mlir/IR/OperationSupport.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index d4035d14ab746..6bb38eb0246f0 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -997,13 +997,14 @@ struct OperationState {
     if (!properties) {
       T *p = new T{};
       properties = p;
-      propertiesDeleter = [](OpaqueProperties prop) {
+      static auto deleter = [](OpaqueProperties prop) {
         delete prop.as<const T *>();
       };
-      propertiesSetter = [](OpaqueProperties new_prop,
-                            const OpaqueProperties prop) {
+      propertiesDeleter = deleter;
+      static auto setter = [](OpaqueProperties new_prop, const OpaqueProperties prop) {
         *new_prop.as<T *>() = *prop.as<const T *>();
       };
+      propertiesSetter = setter;
       propertiesId = TypeID::get<T>();
     }
     assert(propertiesId == TypeID::get<T>() && "Inconsistent properties");



More information about the Mlir-commits mailing list