#pragma once /* SPDX-License-Identifier: Unlicense */ #ifdef NDEBUG #define __DEBUG 0 #else #define __DEBUG 1 #endif #ifndef __TRACE #define __TRACE 0 #endif #define TRACE(format, ...) \ if (__TRACE) fprintf(stderr, "%s:%d %s: " format "\n", \ __FILE__, __LINE__, __func__ __VA_OPT__(,) __VA_ARGS__) #if defined(__SANITIZE_ADDRESS__) || defined(__SANITIZE_THREAD__) #define __SANITIZER_PRINT_STACK_TRACE() __sanitizer_print_stack_trace() #include #else #define __SANITIZER_PRINT_STACK_TRACE() #endif #if __DEBUG #define ASSERT(x) ((x) ? (void)(x) : (__SANITIZER_PRINT_STACK_TRACE(), assert(x))) #define ASSERT_CONSUME(x) ASSERT(x) #define UNREACHABLE_BODY() (ASSERT(!"unreachable code reached"), abort()) #else #define ASSERT(x) ((void)0) #define ASSERT_CONSUME(x) ((void)(x)) #define UNREACHABLE_BODY() ((void)0) #endif #include #ifdef __GNUC__ #define BUILTIN_UNREACHABLE() __builtin_unreachable() #else #define BUILTIN_UNREACHABLE() ((void)0) #endif #define UNREACHABLE() (UNREACHABLE_BODY(), BUILTIN_UNREACHABLE())