1 //===-- runtime/terminate.cpp ---------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "terminator.h"
13 namespace Fortran::runtime
{
15 [[noreturn
]] void Terminator::Crash(const char *message
, ...) const {
17 va_start(ap
, message
);
18 CrashArgs(message
, ap
);
22 static void (*crashHandler
)(const char *, int, const char *, va_list &){
25 void Terminator::RegisterCrashHandler(
26 void (*handler
)(const char *, int, const char *, va_list &)) {
27 crashHandler
= handler
;
30 [[noreturn
]] void Terminator::CrashArgs(
31 const char *message
, va_list &ap
) const {
33 crashHandler(sourceFileName_
, sourceLine_
, message
, ap
);
35 std::fputs("\nfatal Fortran runtime error", stderr
);
36 if (sourceFileName_
) {
37 std::fprintf(stderr
, "(%s", sourceFileName_
);
39 std::fprintf(stderr
, ":%d", sourceLine_
);
43 std::fputs(": ", stderr
);
44 std::vfprintf(stderr
, message
, ap
);
47 io::FlushOutputOnCrash(*this);
48 NotifyOtherImagesOfErrorTermination();
52 [[noreturn
]] void Terminator::CheckFailed(
53 const char *predicate
, const char *file
, int line
) const {
54 Crash("Internal error: RUNTIME_CHECK(%s) failed at %s(%d)", predicate
, file
,
58 [[noreturn
]] void Terminator::CheckFailed(const char *predicate
) const {
59 Crash("Internal error: RUNTIME_CHECK(%s) failed at %s(%d)", predicate
,
60 sourceFileName_
, sourceLine_
);
63 // TODO: These will be defined in the coarray runtime library
64 void NotifyOtherImagesOfNormalEnd() {}
65 void NotifyOtherImagesOfFailImageStatement() {}
66 void NotifyOtherImagesOfErrorTermination() {}
67 } // namespace Fortran::runtime