[Mlir-commits] [mlir] [mlir][gpu] Fix verifier crash on unterminated warp_execute_on_lane_0 body (PR #205495)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jun 24 00:39:40 PDT 2026
https://github.com/Chennesxu created https://github.com/llvm/llvm-project/pull/205495
WarpExecuteOnLane0Op::verify() called getBody()->getTerminator() directly. For malformed IR parsed in generic form, the region's block can have no terminator, and getTerminator() asserts mightHaveTerminator(). Guard the call so the verifier emits "expected body to be terminated with 'gpu.yield'" instead of crashing.
Fixes #205239
>From 9f8cbe7965833d52c9c69a40dd33d45909d6dab0 Mon Sep 17 00:00:00 2001
From: Chennes Xu <xuchen359 at gmail.com>
Date: Wed, 24 Jun 2026 16:35:48 +0900
Subject: [PATCH] [mlir][gpu] Fix verifier crash on unterminated
warp_execute_on_lane_0 body
WarpExecuteOnLane0Op::verify() called getBody()->getTerminator() directly. For
malformed IR parsed in generic form, the region's block can have no terminator,
and getTerminator() asserts `mightHaveTerminator()`. Guard the call so the
verifier emits "expected body to be terminated with 'gpu.yield'" instead of
crashing.
Fixes #205239
---
mlir/lib/Dialect/GPU/IR/GPUDialect.cpp | 6 +++++-
mlir/test/Dialect/GPU/invalid.mlir | 12 ++++++++++++
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 a178bb453d86b..4a349ca58c583 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -2597,7 +2597,11 @@ LogicalResult WarpExecuteOnLane0Op::verify() {
if (getArgs().size() != getWarpRegion().getNumArguments())
return emitOpError(
"expected same number op arguments and block arguments.");
- auto yield = dyn_cast<gpu::YieldOp>(getBody()->getTerminator());
+ Block *body = getBody();
+ // Malformed parsed IR may leave the body unterminated; guard getTerminator().
+ auto yield = body->mightHaveTerminator()
+ ? dyn_cast<gpu::YieldOp>(body->getTerminator())
+ : nullptr;
if (!yield)
return emitOpError("expected body to be terminated with 'gpu.yield'");
if (yield.getNumOperands() != getNumResults())
diff --git a/mlir/test/Dialect/GPU/invalid.mlir b/mlir/test/Dialect/GPU/invalid.mlir
index e3a981c1c7afe..bb4215d52e0eb 100644
--- a/mlir/test/Dialect/GPU/invalid.mlir
+++ b/mlir/test/Dialect/GPU/invalid.mlir
@@ -1061,6 +1061,18 @@ func.func @warp_wrong_num_outputs(%laneid: index) {
// -----
+// A body left unterminated by malformed (generic-form) IR must be diagnosed,
+// not crash getTerminator().
+func.func @warp_unterminated_body(%laneid: index) {
+ // expected-error at +1 {{'gpu.warp_execute_on_lane_0' op expected body to be terminated with 'gpu.yield'}}
+ "gpu.warp_execute_on_lane_0"(%laneid) <{warp_size = 32 : i64}> ({
+ %0 = "arith.constant"() <{value = 1 : index}> : () -> index
+ }) : (index) -> ()
+ return
+}
+
+// -----
+
func.func @warp_wrong_num_inputs(%laneid: index) {
// expected-error at +1 {{'gpu.warp_execute_on_lane_0' op expected same number op arguments and block arguments.}}
gpu.warp_execute_on_lane_0(%laneid)[64] {
More information about the Mlir-commits
mailing list