[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:40:30 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-mlir-gpu
Author: Chennes (Chennesxu)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/205495.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/GPU/IR/GPUDialect.cpp (+5-1)
- (modified) mlir/test/Dialect/GPU/invalid.mlir (+12)
``````````diff
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] {
``````````
</details>
https://github.com/llvm/llvm-project/pull/205495
More information about the Mlir-commits
mailing list