Daily bump.
[official-gcc.git] / libcody / fatal.cc
blob0e805b1456ccd6011af61bf9bb4093622e92bfe9
1 // CODYlib -*- mode:c++ -*-
2 // Copyright (C) 2019-2020 Nathan Sidwell, nathan@acm.org
3 // License: Apache v2.0
5 // Cody
6 #include "internal.hh"
7 // C
8 #include <csignal>
9 #include <cstdint>
10 #include <cstdio>
11 #include <cstdlib>
12 #include <cstring>
14 namespace Cody {
16 #if NMS_CHECKING
17 void (AssertFailed) (Location loc) noexcept
19 (HCF) ("assertion failed", loc);
21 void (Unreachable) (Location loc) noexcept
23 (HCF) ("unreachable reached", loc);
25 #endif
27 void (HCF) (char const *msg
28 #if NMS_CHECKING
29 , Location const loc
30 #endif
31 ) noexcept
32 { // HCF - you goofed!
34 #if !NMS_CHECKING
35 constexpr Location loc (nullptr, 0);
36 #endif
38 fprintf (stderr, "CODYlib: %s", msg ? msg : "internal error");
39 if (char const *file = loc.File ())
41 char const *src = SRCDIR;
43 if (src[0])
45 size_t l = strlen (src);
47 if (!strncmp (src, file, l) && file[l] == '/')
48 file += l + 1;
50 fprintf (stderr, " at %s:%u", file, loc.Line ());
52 fprintf (stderr, "\n");
53 raise (SIGABRT);
54 exit (2);