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 14 void _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 23 void _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 do { \ 32 if (!(expr)) { \ 33 _assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__); \ 34 } \ 35 } while(0) 36 37 #else /* !DEBUG */ 38 39 #define fail(s) halt() 40 41 #define assert(expr) 42 43 #endif /* DEBUG */ 44 45 /* Create an assert that will trigger a compile error if it fails. */ 46 #define compile_assert(name, expr) \ 47 typedef int __assert_failed_##name[(expr) ? 1 : -1] UNUSED; 48 49 /* Sometimes compile asserts contain expressions that the C parser cannot 50 * handle. For such expressions unverified_compile_assert should be used. */ 51 #ifdef CONFIG_VERIFICATION_BUILD 52 #define unverified_compile_assert(name, expr) 53 #else 54 #define unverified_compile_assert compile_assert 55 #endif 56