From c96168975b25e58d72f03de4929255a5b499df42 Mon Sep 17 00:00:00 2001 From: Rahul Joshi Date: Fri, 6 Nov 2020 16:24:35 -0800 Subject: [PATCH] [MLIR] Flag no-terminator error on the last operation of non-empty blocks - When a block is not empty and does not end with a terminator, flag the error on the last operation of the block instead of the start of the block. Differential Revision: https://reviews.llvm.org/D90988 --- mlir/lib/IR/Verifier.cpp | 2 +- mlir/test/IR/invalid.mlir | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mlir/lib/IR/Verifier.cpp b/mlir/lib/IR/Verifier.cpp index 4caf9891383c..e214a654dbee 100644 --- a/mlir/lib/IR/Verifier.cpp +++ b/mlir/lib/IR/Verifier.cpp @@ -148,7 +148,7 @@ LogicalResult OperationVerifier::verifyBlock(Block &block) { if (failed(verifyOperation(block.back()))) return failure(); if (block.back().isKnownNonTerminator()) - return emitError(block, "block with no terminator"); + return block.back().emitError("block with no terminator"); // Verify that this block is not branching to a block of a different // region. diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir index c8ed517434b2..4dfbfa7133c1 100644 --- a/mlir/test/IR/invalid.mlir +++ b/mlir/test/IR/invalid.mlir @@ -170,7 +170,8 @@ func @block_first_has_predecessor() { // ----- func @no_return() { - %x = constant 0 : i32 // expected-error {{block with no terminator}} + %x = constant 0 : i32 + %y = constant 1 : i32 // expected-error {{block with no terminator}} } // -----