FLANG

terminator.h
1 //===-- runtime/terminator.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 // Termination of the image
10
11 #ifndef FORTRAN_RUNTIME_TERMINATOR_H_
12 #define FORTRAN_RUNTIME_TERMINATOR_H_
13
14 #include "entry-names.h"
15 #include <cstdarg>
16
17 namespace Fortran::runtime {
18
19 // A mixin class for statement-specific image error termination
20 // for errors detected in the runtime library
21 class Terminator {
22 public:
23 Terminator() {}
24 Terminator(const Terminator &) = default;
25 explicit Terminator(const char *sourceFileName, int sourceLine = 0)
26 : sourceFileName_{sourceFileName}, sourceLine_{sourceLine} {}
27 void SetLocation(const char *sourceFileName = nullptr, int sourceLine = 0) {
28 sourceFileName_ = sourceFileName;
29 sourceLine_ = sourceLine;
30 }
31 [[noreturn]] void Crash(const char *message, ...) const;
32 [[noreturn]] void CrashArgs(const char *message, va_list &) const;
33 [[noreturn]] void CheckFailed(
34 const char *predicate, const char *file, int line) const;
35
36 // For test harnessing - overrides CrashArgs().
37 static void RegisterCrashHandler(void (*)(const char *sourceFile,
38 int sourceLine, const char *message, va_list &ap));
39
40 private:
41 const char *sourceFileName_{nullptr};
42 int sourceLine_{0};
43 };
44
45 // RUNTIME_CHECK() guarantees evaluation of its predicate.
46 #define RUNTIME_CHECK(terminator, pred) \
47 if (pred) \
48 ; \
49 else \
50 (terminator).CheckFailed(#pred, __FILE__, __LINE__)
51
52 void NotifyOtherImagesOfNormalEnd();
53 void NotifyOtherImagesOfFailImageStatement();
54 void NotifyOtherImagesOfErrorTermination();
55 } // namespace Fortran::runtime
56
57 namespace Fortran::runtime::io {
58 void FlushOutputOnCrash(const Terminator &);
59 }
60
61 #endif // FORTRAN_RUNTIME_TERMINATOR_H_
Fortran::runtime::Terminator
Definition: terminator.h:21