From: River Riddle Date: Sat, 22 Jun 2019 21:39:16 +0000 (-0700) Subject: Allow converting Diagnostic to LogicalResult::Failure. This matches the behavior... X-Git-Tag: llvmorg-11-init~1466^2~1359 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=650dc4bb657a50df037250404df93426d7b120c4;p=platform%2Fupstream%2Fllvm.git Allow converting Diagnostic to LogicalResult::Failure. This matches the behavior of InFlightDiagnostic and enables notes to be converted to failure. PiperOrigin-RevId: 254579098 --- diff --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h index 6038a23..090e96f 100644 --- a/mlir/include/mlir/IR/Diagnostics.h +++ b/mlir/include/mlir/IR/Diagnostics.h @@ -289,6 +289,9 @@ public: return {notes.begin(), notes.end()}; } + /// Allow a diagnostic to be converted to 'failure'. + operator LogicalResult() const; + private: Diagnostic(const Diagnostic &rhs) = delete; Diagnostic &operator=(const Diagnostic &rhs) = delete; diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h index 52aa617..4407ec9 100644 --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -48,6 +48,7 @@ public: // Allow diagnostics emitted during parsing to be converted to failure. ParseResult(const InFlightDiagnostic &) : LogicalResult(failure()) {} + ParseResult(const Diagnostic &) : LogicalResult(failure()) {} /// Failure is true in a boolean context. explicit operator bool() const { return failed(*this); } diff --git a/mlir/lib/AffineOps/AffineOps.cpp b/mlir/lib/AffineOps/AffineOps.cpp index 592519a..f886c5a 100644 --- a/mlir/lib/AffineOps/AffineOps.cpp +++ b/mlir/lib/AffineOps/AffineOps.cpp @@ -704,12 +704,11 @@ static LogicalResult checkHasAffineTerminator(OpState &op, Block &block) { if (block.empty() || isa(block.back())) return success(); - op.emitOpError("expects regions to end with '" + - AffineTerminatorOp::getOperationName() + "'") - .attachNote() - << "in custom textual format, the absence of terminator implies '" - << AffineTerminatorOp::getOperationName() << "'"; - return failure(); + return op.emitOpError("expects regions to end with '" + + AffineTerminatorOp::getOperationName() + "'") + .attachNote() + << "in custom textual format, the absence of terminator implies '" + << AffineTerminatorOp::getOperationName() << "'"; } // Insert `affine.terminator` at the end of the region's only block if it does diff --git a/mlir/lib/GPU/IR/GPUDialect.cpp b/mlir/lib/GPU/IR/GPUDialect.cpp index ddfdd29..272ffce 100644 --- a/mlir/lib/GPU/IR/GPUDialect.cpp +++ b/mlir/lib/GPU/IR/GPUDialect.cpp @@ -138,12 +138,11 @@ LogicalResult LaunchOp::verify() { if (block.back().getNumSuccessors() != 0) continue; if (!isa(&block.back())) { - block.back() - .emitError("expected 'gpu.terminator' or a terminator with " - "successors") - .attachNote(getLoc()) - << "in '" << getOperationName() << "' body region"; - return failure(); + return block.back() + .emitError("expected 'gpu.terminator' or a terminator with " + "successors") + .attachNote(getLoc()) + << "in '" << getOperationName() << "' body region"; } } diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp index a224465..7078aad 100644 --- a/mlir/lib/IR/Diagnostics.cpp +++ b/mlir/lib/IR/Diagnostics.cpp @@ -164,6 +164,9 @@ Diagnostic &Diagnostic::attachNote(llvm::Optional noteLoc) { return *notes.back(); } +/// Allow a diagnostic to be converted to 'failure'. +Diagnostic::operator LogicalResult() const { return failure(); } + //===----------------------------------------------------------------------===// // InFlightDiagnostic //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Linalg/IR/LinalgOps.cpp b/mlir/lib/Linalg/IR/LinalgOps.cpp index a54b57f..5937931 100644 --- a/mlir/lib/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Linalg/IR/LinalgOps.cpp @@ -115,12 +115,11 @@ static LogicalResult checkHasTerminator(OpState &op, Block &block) { if (block.empty() || isa(block.back())) return success(); - op.emitOpError("expects regions to end with '" + - TerminatorOp::getOperationName() + "'") - .attachNote() - << "in custom textual format, the absence of terminator implies '" - << TerminatorOp::getOperationName() << "'"; - return failure(); + return op.emitOpError("expects regions to end with '" + + TerminatorOp::getOperationName() + "'") + .attachNote() + << "in custom textual format, the absence of terminator implies '" + << TerminatorOp::getOperationName() << "'"; } // Insert `linalg.terminator` at the end of the ForOp only region's only block diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index fb77f43..f5108b5 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -2479,11 +2479,10 @@ ParseResult OperationParser::addDefinition(SSAUseInfo useInfo, Value *value) { // or a forward reference. if (auto *existing = entries[useInfo.number].first) { if (!isForwardRefPlaceholder(existing)) { - emitError(useInfo.loc) + return emitError(useInfo.loc) .append("redefinition of SSA value '", useInfo.name, "'") .attachNote(getEncodedSourceLocation(entries[useInfo.number].second)) .append("previously defined here"); - return failure(); } // If it was a forward reference, update everything that used it to use