[Mlir-commits] [mlir] [OpenACC] verify acc::DeclareEnterOp operand not BlockArgument (PR #158095)

Scott Manley llvmlistbot at llvm.org
Thu Sep 11 08:17:08 PDT 2025


https://github.com/rscottmanley updated https://github.com/llvm/llvm-project/pull/158095

>From 8f5cb423a54f3a3c6a802b2bb3b8c0b660601599 Mon Sep 17 00:00:00 2001
From: Scott Manley <scmanley at nvidia.com>
Date: Thu, 11 Sep 2025 08:08:00 -0700
Subject: [PATCH 1/2] [OpenACC] verify acc::DeclareEnterOp operand not
 BlockArgument

Check that the operand of acc::DeclareEnterOp is a BlockArgument before
trying to get its defining operation so it will not segfault and instead
produce a clean error. Add test case.
---
 mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp | 2 +-
 mlir/test/Dialect/OpenACC/invalid.mlir  | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
index ded4c7ab27274..ece7a243e1732 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -3513,7 +3513,7 @@ checkDeclareOperands(Op &op, const mlir::ValueRange &operands,
         "at least one operand must appear on the declare operation");
 
   for (mlir::Value operand : operands) {
-    if (!mlir::isa<acc::CopyinOp, acc::CopyoutOp, acc::CreateOp,
+    if (isa<BlockArgument>(operand) || !mlir::isa<acc::CopyinOp, acc::CopyoutOp, acc::CreateOp,
                    acc::DevicePtrOp, acc::GetDevicePtrOp, acc::PresentOp,
                    acc::DeclareDeviceResidentOp, acc::DeclareLinkOp>(
             operand.getDefiningOp()))
diff --git a/mlir/test/Dialect/OpenACC/invalid.mlir b/mlir/test/Dialect/OpenACC/invalid.mlir
index 68afd9fccba79..24ce9784393b0 100644
--- a/mlir/test/Dialect/OpenACC/invalid.mlir
+++ b/mlir/test/Dialect/OpenACC/invalid.mlir
@@ -831,3 +831,12 @@ func.func @acc_loop_container() {
 %value = memref.alloc() : memref<f32>
 // expected-error @below {{invalid data clause modifiers: readonly}}
 %0 = acc.create varPtr(%value : memref<f32>) -> memref<f32> {modifiers = #acc<data_clause_modifier readonly,zero,capture,always>}
+
+// -----
+
+func.func @verify_declare_enter(%arg0 : memref<i32>) {
+// expected-error @below {{expect valid declare data entry operation or acc.getdeviceptr as defining op}}
+  %0 = acc.declare_enter dataOperands(%arg0 : memref<i32>)
+  acc.declare_exit token(%0) dataOperands(%arg0 : memref<i32>)
+  return
+}

>From 2e0204cc87637755e0146a7e3f6b281506850f5f Mon Sep 17 00:00:00 2001
From: Scott Manley <scmanley at nvidia.com>
Date: Thu, 11 Sep 2025 08:16:45 -0700
Subject: [PATCH 2/2] format

---
 mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
index ece7a243e1732..b82ad20d8e194 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -3513,7 +3513,8 @@ checkDeclareOperands(Op &op, const mlir::ValueRange &operands,
         "at least one operand must appear on the declare operation");
 
   for (mlir::Value operand : operands) {
-    if (isa<BlockArgument>(operand) || !mlir::isa<acc::CopyinOp, acc::CopyoutOp, acc::CreateOp,
+    if (isa<BlockArgument>(operand) ||
+        !mlir::isa<acc::CopyinOp, acc::CopyoutOp, acc::CreateOp,
                    acc::DevicePtrOp, acc::GetDevicePtrOp, acc::PresentOp,
                    acc::DeclareDeviceResidentOp, acc::DeclareLinkOp>(
             operand.getDefiningOp()))



More information about the Mlir-commits mailing list