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

Scott Manley llvmlistbot at llvm.org
Tue Sep 16 11:38:02 PDT 2025


https://github.com/rscottmanley created https://github.com/llvm/llvm-project/pull/159148

Similar to #158095, check that the operand of acc::DataOp is not a BlockArgument before trying to get its defining operation so it will not segfault and instead produce a clean error.

>From aa002b43ba3d3807690088ff1e395c6e7f64c249 Mon Sep 17 00:00:00 2001
From: Scott Manley <scmanley at nvidia.com>
Date: Tue, 16 Sep 2025 11:34:19 -0700
Subject: [PATCH] [OpenACC] verify acc:DataOp operand not BlockArgument

Similar to #158095, check that the operand of acc::DataOp
is not a BlockArgument before trying to get its defining
operation so it will not segfault and instead produce a
clean error.
---
 mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp | 3 ++-
 mlir/test/Dialect/OpenACC/invalid.mlir  | 8 ++++++++
 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 b82ad20d8e194..70cbde7071551 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -3144,7 +3144,8 @@ LogicalResult acc::DataOp::verify() {
                      "must appear on the data operation");
 
   for (mlir::Value operand : getDataClauseOperands())
-    if (!mlir::isa<acc::AttachOp, acc::CopyinOp, acc::CopyoutOp, acc::CreateOp,
+    if (isa<BlockArgument>(operand) ||
+        !mlir::isa<acc::AttachOp, acc::CopyinOp, acc::CopyoutOp, acc::CreateOp,
                    acc::DeleteOp, acc::DetachOp, acc::DevicePtrOp,
                    acc::GetDevicePtrOp, acc::NoCreateOp, acc::PresentOp>(
             operand.getDefiningOp()))
diff --git a/mlir/test/Dialect/OpenACC/invalid.mlir b/mlir/test/Dialect/OpenACC/invalid.mlir
index 24ce9784393b0..26b63fbe182ea 100644
--- a/mlir/test/Dialect/OpenACC/invalid.mlir
+++ b/mlir/test/Dialect/OpenACC/invalid.mlir
@@ -840,3 +840,11 @@ func.func @verify_declare_enter(%arg0 : memref<i32>) {
   acc.declare_exit token(%0) dataOperands(%arg0 : memref<i32>)
   return
 }
+
+func.func @verify_data(%arg0 : memref<i32>) {
+// expected-error @below {{expect data entry/exit operation or acc.getdeviceptr as defining op}}
+  acc.data dataOperands(%arg0 : memref<i32>) {
+    acc.terminator
+  }
+  return
+}



More information about the Mlir-commits mailing list