1 //===-- Optimizer/Support/FatalError.h --------------------------*- C++ -*-===// 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 // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/ 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef FORTRAN_OPTIMIZER_SUPPORT_FATALERROR_H 14 #define FORTRAN_OPTIMIZER_SUPPORT_FATALERROR_H 15 16 #include "mlir/IR/Diagnostics.h" 17 #include "llvm/Support/ErrorHandling.h" 18 19 namespace fir { 20 21 /// Fatal error reporting helper. Report a fatal error with a source location 22 /// and immediately interrupt flang. If `genCrashDiag` is true, then 23 /// the execution is aborted and the backtrace is printed, otherwise, 24 /// flang exits with non-zero exit code and without backtrace printout. 25 [[noreturn]] inline void emitFatalError(mlir::Location loc, 26 const llvm::Twine &message, 27 bool genCrashDiag = true) { 28 mlir::emitError(loc, message); 29 llvm::report_fatal_error("aborting", genCrashDiag); 30 } 31 32 } // namespace fir 33 34 #endif // FORTRAN_OPTIMIZER_SUPPORT_FATALERROR_H 35