1//===- DiagnosedSilenceableFailure.cpp - Tri-state result -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the DiagnosedSilenceableFailure class allowing to store
10// a tri-state result (definite failure, recoverable failure, success) with an
11// optional associated list of diagnostics.
12//
13//===----------------------------------------------------------------------===//
14
15#include "mlir/Dialect/Transform/Utils/DiagnosedSilenceableFailure.h"
16
17using namespace mlir;
18
19LogicalResult mlir::DiagnosedSilenceableFailure::checkAndReport() {
20#if LLVM_ENABLE_ABI_BREAKING_CHECKS
21 assert(!reported && "attempting to report a diagnostic more than once");
22 reported = true;
23#endif // LLVM_ENABLE_ABI_BREAKING_CHECKS
24 if (!diagnostics.empty()) {
25 for (auto &&diagnostic : diagnostics) {
26 diagnostic.getLocation().getContext()->getDiagEngine().emit(
27 diag: std::move(diagnostic));
28 }
29 diagnostics.clear();
30 result = ::mlir::failure();
31 }
32 return result;
33}
34

source code of mlir/lib/Dialect/Transform/Utils/DiagnosedSilenceableFailure.cpp