[Mlir-commits] [mlir] [mlir][emitc] Fix bug in dereference translation (PR #171028)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Dec 7 03:12:46 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Gil Rapaport (aniragil)
<details>
<summary>Changes</summary>
The op was not added to `hasDeferredEmission()` when introduced by f17abc280c70, causing incorrect translation.
---
Full diff: https://github.com/llvm/llvm-project/pull/171028.diff
2 Files Affected:
- (modified) mlir/lib/Target/Cpp/TranslateToCpp.cpp (+2-1)
- (modified) mlir/test/Target/Cpp/common-cpp.mlir (+1-1)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/171028
More information about the Mlir-commits
mailing list