1/* 2 * Copyright 2014, General Dynamics C4 Systems 3 * 4 * SPDX-License-Identifier: GPL-2.0-only 5 */ 6 7#pragma once 8 9#include <config.h> 10#include <util.h> 11 12#ifdef CONFIG_DEBUG_BUILD 13 14void _fail( 15 const char *str, 16 const char *file, 17 unsigned int line, 18 const char *function 19) NORETURN; 20 21#define fail(s) _fail(s, __FILE__, __LINE__, __func__) 22 23void _assert_fail( 24 const char *assertion, 25 const char *file, 26 unsigned int line, 27 const char *function 28) NORETURN; 29 30#define assert(expr) \ 31 if(!(expr)) _assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__) 32 33#else /* !DEBUG */ 34 35#define fail(s) halt() 36 37#define assert(expr) 38 39#endif /* DEBUG */ 40 41/* Create an assert that will trigger a compile error if it fails. */ 42#define compile_assert(name, expr) \ 43 typedef int __assert_failed_##name[(expr) ? 1 : -1]; 44 45/* Sometimes compile asserts contain expressions that the C parser cannot 46 * handle. For such expressions unverified_compile_assert should be used. */ 47#ifdef CONFIG_VERIFICATION_BUILD 48#define unverified_compile_assert(name, expr) 49#else 50#define unverified_compile_assert compile_assert 51#endif 52 53