this repo has no description
at trunk 66 lines 3.4 kB view raw
1/* Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) */ 2#pragma once 3 4#include "globals.h" 5 6#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 7#define DCHECK_IS_ON() 0 8#else 9#define DCHECK_IS_ON() 1 10#endif 11 12#define CHECK(expr, ...) \ 13 do { \ 14 if (UNLIKELY(!(expr))) { \ 15 checkFailed(__FILE__, __LINE__, __func__, "check '" #expr "' failed", \ 16 __VA_ARGS__); \ 17 } \ 18 } while (0) 19 20#define CHECK_INDEX(index, high) \ 21 do { \ 22 if (UNLIKELY(!((index >= 0) && (index < high)))) { \ 23 checkIndexFailed(__FILE__, __LINE__, __func__, static_cast<word>(index), \ 24 static_cast<word>(high)); \ 25 } \ 26 } while (0) 27 28#define CHECK_BOUND(val, high) \ 29 do { \ 30 if (UNLIKELY(!((val >= 0) && (val <= high)))) { \ 31 checkBoundFailed(__FILE__, __LINE__, __func__, static_cast<word>(val), \ 32 static_cast<word>(high)); \ 33 } \ 34 } while (0) 35 36#if DCHECK_IS_ON() 37#define DCHECK(...) CHECK(__VA_ARGS__) 38#define DCHECK_BOUND(val, high) CHECK_BOUND(val, high) 39#define DCHECK_INDEX(index, high) CHECK_INDEX(index, high) 40#else 41#define DCHECK(...) \ 42 if (false) { \ 43 CHECK(__VA_ARGS__); \ 44 } 45#define DCHECK_BOUND(val, high) \ 46 if (false) { \ 47 CHECK_BOUND(val, high); \ 48 } 49#define DCHECK_INDEX(index, high) \ 50 if (false) { \ 51 CHECK_INDEX(index, high); \ 52 } 53#endif 54 55#define UNIMPLEMENTED(...) \ 56 checkFailed(__FILE__, __LINE__, __func__, "unimplemented", __VA_ARGS__) 57 58#define UNREACHABLE(...) \ 59 checkFailed(__FILE__, __LINE__, __func__, "unreachable", __VA_ARGS__) 60 61[[noreturn]] void checkFailed(const char* file, int line, const char* func, 62 const char* expr, ...); 63[[noreturn]] void checkIndexFailed(const char* file, int line, const char* func, 64 word index, word high); 65[[noreturn]] void checkBoundFailed(const char* file, int line, const char* func, 66 word value, word high);