11#ifndef FORTRAN_RUNTIME_TERMINATOR_H_
12#define FORTRAN_RUNTIME_TERMINATOR_H_
14#include "flang/Common/api-attrs.h"
19namespace Fortran::runtime {
28 const char *sourceFileName,
int sourceLine = 0)
29 : sourceFileName_{sourceFileName}, sourceLine_{sourceLine} {}
31 RT_API_ATTRS
const char *sourceFileName()
const {
return sourceFileName_; }
32 RT_API_ATTRS
int sourceLine()
const {
return sourceLine_; }
34 RT_API_ATTRS
void SetLocation(
35 const char *sourceFileName =
nullptr,
int sourceLine = 0) {
36 sourceFileName_ = sourceFileName;
37 sourceLine_ = sourceLine;
45#pragma clang diagnostic push
46#pragma clang diagnostic ignored "-Wformat-security"
47#elif defined(__GNUC__)
48#pragma GCC diagnostic push
49#pragma GCC diagnostic ignored "-Wformat-security"
56 template <
typename... Args>
57 [[noreturn]] RT_DEVICE_NOINLINE RT_API_ATTRS
const char *Crash(
58 const char *message, Args... args)
const {
59#if !defined(RT_DEVICE_COMPILATION)
61 InvokeCrashHandler(message, args...);
64 PrintCrashArgs(message, args...);
68 template <
typename... Args>
69 RT_API_ATTRS
void PrintCrashArgs(
const char *message, Args... args)
const {
70#if defined(RT_DEVICE_COMPILATION)
71 std::printf(message, args...);
73 std::fprintf(stderr, message, args...);
78#pragma clang diagnostic pop
79#elif defined(__GNUC__)
80#pragma GCC diagnostic pop
83 RT_API_ATTRS
void CrashHeader()
const;
84 [[noreturn]] RT_API_ATTRS
void CrashFooter()
const;
85#if !defined(RT_DEVICE_COMPILATION)
86 void InvokeCrashHandler(
const char *message, ...)
const;
87 [[noreturn]]
void CrashArgs(
const char *message, va_list &)
const;
89 [[noreturn]] RT_API_ATTRS
void CheckFailed(
90 const char *predicate,
const char *file,
int line)
const;
91 [[noreturn]] RT_API_ATTRS
void CheckFailed(
const char *predicate)
const;
94 static void RegisterCrashHandler(
void (*)(
const char *sourceFile,
95 int sourceLine,
const char *message, va_list &ap));
98 const char *sourceFileName_{
nullptr};
103#define RUNTIME_CHECK(terminator, pred) \
107 (terminator).CheckFailed(#pred, __FILE__, __LINE__)
109#define INTERNAL_CHECK(pred) \
113 Terminator{__FILE__, __LINE__}.CheckFailed(#pred)
115RT_API_ATTRS
void NotifyOtherImagesOfNormalEnd();
116RT_API_ATTRS
void NotifyOtherImagesOfFailImageStatement();
117RT_API_ATTRS
void NotifyOtherImagesOfErrorTermination();
120namespace Fortran::runtime::io {
121RT_API_ATTRS
void FlushOutputOnCrash(
const Terminator &);
Definition: terminator.h:23