diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp --- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp +++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp @@ -1048,6 +1048,12 @@ return diag; } + if (!topLevelOp) { + InFlightDiagnostic diag = emitOpError() + << "expects at least one non-pattern op"; + return diag; + } + return success(); } diff --git a/mlir/test/Dialect/Transform/ops-invalid.mlir b/mlir/test/Dialect/Transform/ops-invalid.mlir --- a/mlir/test/Dialect/Transform/ops-invalid.mlir +++ b/mlir/test/Dialect/Transform/ops-invalid.mlir @@ -124,6 +124,28 @@ } } +// ----- + +// expected-error @below {{op expects at least one non-pattern op}} +transform.with_pdl_patterns { +^bb0(%arg0: !pdl.operation): + pdl.pattern @some : benefit(1) { + %0 = pdl.operation "test.foo" + pdl.rewrite %0 with "transform.dialect" + } +} + +// ----- + +transform.sequence failures(propagate) { +^bb0(%arg0: !pdl.operation): + // expected-error @below {{op expects at least one non-pattern op}} + with_pdl_patterns %arg0 : !pdl.operation { + ^bb1(%arg1: !pdl.operation): + } +} + + // ----- // expected-error @below {{expects at least one region}} diff --git a/mlir/test/Dialect/Transform/ops.mlir b/mlir/test/Dialect/Transform/ops.mlir --- a/mlir/test/Dialect/Transform/ops.mlir +++ b/mlir/test/Dialect/Transform/ops.mlir @@ -21,16 +21,6 @@ } } -// CHECK: transform.sequence -// CHECK: ^{{.+}}(%[[ARG:.+]]: !pdl.operation): -transform.sequence failures(propagate) { -^bb0(%arg0: !pdl.operation): - // CHECK: with_pdl_patterns %[[ARG]] : !pdl.operation - with_pdl_patterns %arg0 : !pdl.operation { - ^bb1(%arg1: !pdl.operation): - } -} - // Using the same value multiple times without consuming it is fine. // CHECK: transform.sequence // CHECK: %[[V:.+]] = sequence %{{.*}} : !pdl.operation -> !pdl.operation