[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / runtime / terminator.cpp
blobf242ac6f2de2293c34a24b19d64acb4567590e9a
1 //===-- runtime/terminate.cpp ---------------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "terminator.h"
10 #include <cstdio>
11 #include <cstdlib>
13 namespace Fortran::runtime {
15 [[noreturn]] void Terminator::Crash(const char *message, ...) const {
16 va_list ap;
17 va_start(ap, message);
18 CrashArgs(message, ap);
19 va_end(ap);
22 static void (*crashHandler)(const char *, int, const char *, va_list &){
23 nullptr};
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 {
32 if (crashHandler) {
33 crashHandler(sourceFileName_, sourceLine_, message, ap);
35 std::fputs("\nfatal Fortran runtime error", stderr);
36 if (sourceFileName_) {
37 std::fprintf(stderr, "(%s", sourceFileName_);
38 if (sourceLine_) {
39 std::fprintf(stderr, ":%d", sourceLine_);
41 fputc(')', stderr);
43 std::fputs(": ", stderr);
44 std::vfprintf(stderr, message, ap);
45 fputc('\n', stderr);
46 va_end(ap);
47 io::FlushOutputOnCrash(*this);
48 NotifyOtherImagesOfErrorTermination();
49 std::abort();
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,
55 line);
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