2020-01-28 10:18:45 +08:00
|
|
|
//===-- runtime/terminate.cpp -----------------------------------*- C++ -*-===//
|
2020-01-09 05:27:32 +08:00
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
2020-01-11 04:12:03 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2020-01-09 05:27:32 +08:00
|
|
|
|
|
|
|
#include "terminator.h"
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
namespace Fortran::runtime {
|
|
|
|
|
2020-02-05 08:55:45 +08:00
|
|
|
[[noreturn]] void Terminator::Crash(const char *message, ...) const {
|
2020-01-09 05:27:32 +08:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, message);
|
|
|
|
CrashArgs(message, ap);
|
|
|
|
}
|
|
|
|
|
2020-07-05 05:24:32 +08:00
|
|
|
static void (*crashHandler)(const char *, int, const char *, va_list &){
|
|
|
|
nullptr};
|
2020-02-14 06:41:56 +08:00
|
|
|
|
|
|
|
void Terminator::RegisterCrashHandler(
|
2020-07-05 05:24:32 +08:00
|
|
|
void (*handler)(const char *, int, const char *, va_list &)) {
|
2020-02-14 06:41:56 +08:00
|
|
|
crashHandler = handler;
|
|
|
|
}
|
|
|
|
|
2020-02-05 08:55:45 +08:00
|
|
|
[[noreturn]] void Terminator::CrashArgs(
|
|
|
|
const char *message, va_list &ap) const {
|
2020-02-14 06:41:56 +08:00
|
|
|
if (crashHandler) {
|
2020-07-05 05:24:32 +08:00
|
|
|
crashHandler(sourceFileName_, sourceLine_, message, ap);
|
2020-02-14 06:41:56 +08:00
|
|
|
}
|
2020-01-09 05:27:32 +08:00
|
|
|
std::fputs("\nfatal Fortran runtime error", stderr);
|
|
|
|
if (sourceFileName_) {
|
|
|
|
std::fprintf(stderr, "(%s", sourceFileName_);
|
|
|
|
if (sourceLine_) {
|
|
|
|
std::fprintf(stderr, ":%d", sourceLine_);
|
|
|
|
}
|
|
|
|
fputc(')', stderr);
|
|
|
|
}
|
|
|
|
std::fputs(": ", stderr);
|
|
|
|
std::vfprintf(stderr, message, ap);
|
|
|
|
fputc('\n', stderr);
|
|
|
|
va_end(ap);
|
2020-02-05 08:55:45 +08:00
|
|
|
io::FlushOutputOnCrash(*this);
|
2020-01-09 05:27:32 +08:00
|
|
|
NotifyOtherImagesOfErrorTermination();
|
|
|
|
std::abort();
|
|
|
|
}
|
|
|
|
|
2020-01-17 05:51:25 +08:00
|
|
|
[[noreturn]] void Terminator::CheckFailed(
|
2020-02-05 08:55:45 +08:00
|
|
|
const char *predicate, const char *file, int line) const {
|
2020-01-17 05:51:25 +08:00
|
|
|
Crash("Internal error: RUNTIME_CHECK(%s) failed at %s(%d)", predicate, file,
|
|
|
|
line);
|
|
|
|
}
|
|
|
|
|
2020-11-11 07:13:02 +08:00
|
|
|
[[noreturn]] void Terminator::CheckFailed(const char *predicate) const {
|
|
|
|
Crash("Internal error: RUNTIME_CHECK(%s) failed at %s(%d)", predicate,
|
|
|
|
sourceFileName_, sourceLine_);
|
|
|
|
}
|
|
|
|
|
2020-02-05 08:55:45 +08:00
|
|
|
// TODO: These will be defined in the coarray runtime library
|
|
|
|
void NotifyOtherImagesOfNormalEnd() {}
|
|
|
|
void NotifyOtherImagesOfFailImageStatement() {}
|
|
|
|
void NotifyOtherImagesOfErrorTermination() {}
|
2020-03-29 12:00:16 +08:00
|
|
|
} // namespace Fortran::runtime
|