[Mlir-commits] [mlir] [mlir][gpu] Enforce async keyword when parsing gpu.launch with results (PR #176570)
Akimasa Watanuki
llvmlistbot at llvm.org
Sat Jan 17 06:50:10 PST 2026
https://github.com/Men-cotton created https://github.com/llvm/llvm-project/pull/176570
The `gpu.launch` parser attempts to add a null `asyncTokenType` to the results list if a result is requested but the `async` keyword is missing, leading to an assertion failure.
Explicitly verify that `asyncTokenType` is valid when `parser.getNumResults() > 0`. Emit a diagnostic error if the `async` keyword is missing instead of crashing.
Add a regression test to `mlir/test/Dialect/GPU/invalid.mlir`.
Fix: https://github.com/llvm/llvm-project/issues/176530
>From 17e44ea38ed61f0020c3375c9c79aac85275b631 Mon Sep 17 00:00:00 2001
From: mencotton <mencotton0410 at gmail.com>
Date: Sat, 17 Jan 2026 23:21:35 +0900
Subject: [PATCH] [mlir][gpu] Enforce async keyword when parsing gpu.launch
with results
---
mlir/lib/Dialect/GPU/IR/GPUDialect.cpp | 7 ++++++-
mlir/test/Dialect/GPU/invalid.mlir | 11 +++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
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 at +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 at +1 {{expected 6 or more operands}}
"gpu.launch_func"(%sz, %sz, %sz, %sz, %sz)
More information about the Mlir-commits
mailing list