#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 {
// 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: