Skip to content

Commit 29b6433

Browse files
authored
[OpenACC] verify acc::DeclareEnterOp operand not BlockArgument (#158095)
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.
1 parent 641ed9f commit 29b6433

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3513,7 +3513,8 @@ checkDeclareOperands(Op &op, const mlir::ValueRange &operands,
35133513
"at least one operand must appear on the declare operation");
35143514

35153515
for (mlir::Value operand : operands) {
3516-
if (!mlir::isa<acc::CopyinOp, acc::CopyoutOp, acc::CreateOp,
3516+
if (isa<BlockArgument>(operand) ||
3517+
!mlir::isa<acc::CopyinOp, acc::CopyoutOp, acc::CreateOp,
35173518
acc::DevicePtrOp, acc::GetDevicePtrOp, acc::PresentOp,
35183519
acc::DeclareDeviceResidentOp, acc::DeclareLinkOp>(
35193520
operand.getDefiningOp()))

mlir/test/Dialect/OpenACC/invalid.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,3 +831,12 @@ func.func @acc_loop_container() {
831831
%value = memref.alloc() : memref<f32>
832832
// expected-error @below {{invalid data clause modifiers: readonly}}
833833
%0 = acc.create varPtr(%value : memref<f32>) -> memref<f32> {modifiers = #acc<data_clause_modifier readonly,zero,capture,always>}
834+
835+
// -----
836+
837+
func.func @verify_declare_enter(%arg0 : memref<i32>) {
838+
// expected-error @below {{expect valid declare data entry operation or acc.getdeviceptr as defining op}}
839+
%0 = acc.declare_enter dataOperands(%arg0 : memref<i32>)
840+
acc.declare_exit token(%0) dataOperands(%arg0 : memref<i32>)
841+
return
842+
}

0 commit comments

Comments
 (0)