1/* 2 * Copyright 2014, General Dynamics C4 Systems 3 * 4 * This software may be distributed and modified according to the terms of 5 * the GNU General Public License version 2. Note that NO WARRANTY is provided. 6 * See "LICENSE_GPLv2.txt" for details. 7 * 8 * @TAG(GD_GPL) 9 */ 10 11#ifndef __ASSERT_H 12#define __ASSERT_H 13 14#include <config.h> 15#include <util.h> 16 17#ifdef CONFIG_DEBUG_BUILD 18 19void _fail( 20 const char* str, 21 const char* file, 22 unsigned int line, 23 const char* function 24) NORETURN; 25 26#define fail(s) _fail(s, __FILE__, __LINE__, __func__) 27 28void _assert_fail( 29 const char* assertion, 30 const char* file, 31 unsigned int line, 32 const char* function 33) NORETURN; 34 35#define assert(expr) \ 36 if(!(expr)) _assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__) 37 38#else /* !DEBUG */ 39 40#define fail(s) halt() 41 42#define assert(expr) 43 44#endif /* DEBUG */ 45 46/* Create an assert that will trigger a compile error if it fails. */ 47#define compile_assert(name, expr) \ 48 typedef int __assert_failed_##name[(expr) ? 1 : -1]; 49 50/* Sometimes compile asserts contain expressions that the C parser cannot 51 * handle. For such expressions unverified_compile_assert should be used. */ 52#ifdef CONFIG_VERIFICATION_BUILD 53#define unverified_compile_assert(name, expr) 54#else 55#define unverified_compile_assert compile_assert 56#endif 57 58#endif 59