From 8f5cb423a54f3a3c6a802b2bb3b8c0b660601599 Mon Sep 17 00:00:00 2001 From: Scott Manley 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(operand) || !mlir::isa( 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 // expected-error @below {{invalid data clause modifiers: readonly}} %0 = acc.create varPtr(%value : memref) -> memref {modifiers = #acc} + +// ----- + +func.func @verify_declare_enter(%arg0 : memref) { +// expected-error @below {{expect valid declare data entry operation or acc.getdeviceptr as defining op}} + %0 = acc.declare_enter dataOperands(%arg0 : memref) + acc.declare_exit token(%0) dataOperands(%arg0 : memref) + return +} From 2e0204cc87637755e0146a7e3f6b281506850f5f Mon Sep 17 00:00:00 2001 From: Scott Manley 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(operand) || !mlir::isa(operand) || + !mlir::isa( operand.getDefiningOp()))