[flang] Add DIE macro

`DIE()` is like `common::die()` but with the source location appended,
as in `CHECK()`.

Original-commit: flang-compiler/f18@ed586c3f38
Reviewed-on: https://github.com/flang-compiler/f18/pull/443
Tree-same-pre-rewrite: false
This commit is contained in:
Tim Keith 2019-05-03 08:02:31 -07:00
parent 28f80675e9
commit 12f1660117
2 changed files with 7 additions and 14 deletions

View File

@ -25,17 +25,13 @@
#include "llvm/Support/raw_ostream.h"
// Some useful, self-documenting macros for failure modes
#define STRINGIFY(X) #X
#define LINE2STRING(X) STRINGIFY(X)
#define AT_HERE " at " __FILE__ "(" LINE2STRING(__LINE__) ")"
#define DIE Fortran::common::die
#define SEMANTICS_FAILED(STRING) DIE("semantics bug: " STRING AT_HERE)
#define SEMANTICS_FAILED(STRING) DIE("semantics bug: " STRING)
#define SEMANTICS_CHECK(CONDITION, STRING) \
if (CONDITION) { \
} else { \
DIE("semantics bug: " STRING AT_HERE); \
DIE("semantics bug: " STRING); \
}
#define WRONG_PATH() DIE("control should not reach here" AT_HERE)
#define WRONG_PATH() DIE("control should not reach here")
namespace Fortran::FIR {

View File

@ -69,18 +69,15 @@ template<typename... LAMBDAS> visitors(LAMBDAS... x)->visitors<LAMBDAS...>;
// Calls std::fprintf(stderr, ...), then abort().
[[noreturn]] void die(const char *, ...);
#define DIE(x) Fortran::common::die(x " at " __FILE__ "(%d)", __LINE__)
// For switch statements without default: labels.
#define CRASH_NO_CASE \
Fortran::common::die("no case at " __FILE__ "(%d)", __LINE__)
#define CRASH_NO_CASE DIE("no case")
// For cheap assertions that should be applied in production.
// To disable, compile with '-DCHECK=(void)'
#ifndef CHECK
#define CHECK(x) \
((x) || \
(Fortran::common::die( \
"CHECK(" #x ") failed at " __FILE__ "(%d)", __LINE__), \
false))
#define CHECK(x) ((x) || (DIE("CHECK(" #x ") failed"), false))
#endif
// User-defined type traits that default to false: