MLIR  20.0.0git
DiagnosedSilenceableFailure.cpp
Go to the documentation of this file.
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 
16 
17 using namespace mlir;
18 
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  std::move(diagnostic));
28  }
29  diagnostics.clear();
30  result = ::mlir::failure();
31  }
32  return result;
33 }
LogicalResult checkAndReport()
Converts all kinds of failure into a LogicalResult failure, emitting the diagnostic if necessary.
Include the generated interface declarations.