[Mlir-commits] [mlir] [mlir][emitc] Fix bug in dereference translation (PR #171028)

Gil Rapaport llvmlistbot at llvm.org
Sun Dec 7 03:12:13 PST 2025


https://github.com/aniragil created https://github.com/llvm/llvm-project/pull/171028

The op was not added to `hasDeferredEmission()` when introduced by f17abc280c70, causing incorrect translation.

>From 97f326c0812dd863569f59b7e1f45e38851908b9 Mon Sep 17 00:00:00 2001
From: Gil Rapaport <gil.rapaport at mobileye.com>
Date: Sun, 7 Dec 2025 12:07:36 +0200
Subject: [PATCH] [mlir][emitc] Fix bug in dereference translation

The op was not added to `hasDeferredEmission()` when introduced by
f17abc280c70, causing incorrect translation.
---
 mlir/lib/Target/Cpp/TranslateToCpp.cpp | 3 ++-
 mlir/test/Target/Cpp/common-cpp.mlir   | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
index 55b9c3dc0a355..15c23c60d0b86 100644
--- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp
+++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
@@ -333,7 +333,8 @@ struct CppEmitter {
 
 /// Determine whether expression \p op should be emitted in a deferred way.
 static bool hasDeferredEmission(Operation *op) {
-  return isa_and_nonnull<emitc::GetGlobalOp, emitc::LiteralOp, emitc::MemberOp,
+  return isa_and_nonnull<emitc::DereferenceOp, emitc::GetGlobalOp,
+                         emitc::LiteralOp, emitc::MemberOp,
                          emitc::MemberOfPtrOp, emitc::SubscriptOp,
                          emitc::GetFieldOp>(op);
 }
diff --git a/mlir/test/Target/Cpp/common-cpp.mlir b/mlir/test/Target/Cpp/common-cpp.mlir
index abf85c8e9a359..f397a4ae9709f 100644
--- a/mlir/test/Target/Cpp/common-cpp.mlir
+++ b/mlir/test/Target/Cpp/common-cpp.mlir
@@ -118,7 +118,7 @@ func.func @address_of() {
 // CHECK-LABEL: void dereference
 // CHECK-SAME:                   (int32_t* [[ARG0:[^ ]*]]) {
 func.func @dereference(%arg0: !emitc.ptr<i32>) {
-  // CHECK: int32_t [[V1:[^ ]*]] = *[[ARG0]];
+  // CHECK-NEXT: int32_t [[V1:[^ ]*]] = *[[ARG0]];
   %2 = emitc.dereference %arg0 : !emitc.ptr<i32>
   emitc.load %2 : !emitc.lvalue<i32>
   return



More information about the Mlir-commits mailing list