diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp index 033a94e3f8fce..a388c1243d4ed 100644 --- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp +++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp @@ -1048,8 +1048,13 @@ ParseResult LaunchOp::parse(OpAsmParser &parser, OperationState &result) { parser.resolveOperands(asyncDependencies, asyncTokenType, result.operands)) return failure(); - if (parser.getNumResults() > 0) + if (parser.getNumResults() > 0) { + if (!asyncTokenType) + return parser.emitError( + parser.getNameLoc(), + "gpu.launch requires 'async' keyword to return a value"); result.types.push_back(asyncTokenType); + } bool hasCluster = false; if (succeeded( diff --git a/mlir/test/Dialect/GPU/invalid.mlir b/mlir/test/Dialect/GPU/invalid.mlir index 5e9c25c36aa79..ad6ad7338ff38 100644 --- a/mlir/test/Dialect/GPU/invalid.mlir +++ b/mlir/test/Dialect/GPU/invalid.mlir @@ -35,6 +35,17 @@ func.func @launch_requires_gpu_return(%sz : index) { // ----- +func.func @launch_result_no_async() { + %c1 = arith.constant 1 : index + // expected-error@+1 {{gpu.launch requires 'async' keyword to return a value}} + %0 = gpu.launch blocks(%bx, %by, %bz) in (%gx = %c1, %gy = %c1, %gz = %c1) threads(%tx, %ty, %tz) in (%lx = %c1, %ly = %c1, %lz = %c1) { + gpu.terminator + } + return +} + +// ----- + func.func @launch_func_too_few_operands(%sz : index) { // expected-error@+1 {{expected 6 or more operands}} "gpu.launch_func"(%sz, %sz, %sz, %sz, %sz)