diff --git a/core/assert.c b/core/assert.c index 873634467d..853623d6b7 100644 --- a/core/assert.c +++ b/core/assert.c @@ -16,15 +16,17 @@ #include #include "assert.h" +#include "panic.h" -#ifdef DEBUG_ASSERT_VERBOSE -NORETURN void _assert_failure(const char *file, unsigned line) +__NORETURN void _assert_failure(const char *file, unsigned line) { - printf("%s:%u => ", file, line); \ - core_panic(PANIC_ASSERT_FAIL, assert_crash_message); \ + printf("%s:%u => ", file, line); + core_panic(PANIC_ASSERT_FAIL, "FAILED ASSERTION."); +} + +__NORETURN void _assert_panic(void) +{ + core_panic(PANIC_ASSERT_FAIL, "FAILED ASSERTION."); } -#else -typedef int dont_be_pedantic; -#endif /** @} */ diff --git a/core/include/assert.h b/core/include/assert.h index bbfd8e35e7..4d8664bada 100644 --- a/core/include/assert.h +++ b/core/include/assert.h @@ -22,8 +22,6 @@ #ifndef ASSERT_H #define ASSERT_H -#include "panic.h" - #ifdef __cplusplus extern "C" { #endif @@ -51,9 +49,18 @@ extern "C" { #endif /** - * @brief the string that is passed to panic in case of a failing assertion - */ -extern const char assert_crash_message[]; + * @def __NORETURN + * @internal + * Duplicating the definitions of kernel_defines.h as these are unsuitable for + * system header files like the assert.h. + * kernel_defines.h would define symbols that are not reserved. */ +#ifndef __NORETURN +#ifdef __GNUC__ +#define __NORETURN __attribute__((noreturn)) +#else /*__GNUC__*/ +#define __NORETURN +#endif /*__GNUC__*/ +#endif /*__NORETURN*/ #ifdef NDEBUG #define assert(ignore)((void)0) @@ -68,8 +75,7 @@ extern const char assert_crash_message[]; * @param[in] file The file name of the file the assertion failed in * @param[in] line The code line of @p file the assertion failed in */ -NORETURN void _assert_failure(const char *file, unsigned line); - +__NORETURN void _assert_failure(const char *file, unsigned line); /** * @brief abort the program if assertion is false * @@ -103,10 +109,10 @@ NORETURN void _assert_failure(const char *file, unsigned line); */ #define assert(cond) ((cond) ? (void)0 : _assert_failure(RIOT_FILE_RELATIVE, \ __LINE__)) -#else -#define assert(cond) ((cond) ? (void)0 : core_panic(PANIC_ASSERT_FAIL, \ - assert_crash_message)) -#endif +#else /* DEBUG_ASSERT_VERBOSE */ +__NORETURN void _assert_panic(void); +#define assert(cond) ((cond) ? (void)0 : _assert_panic()) +#endif /* DEBUG_ASSERT_VERBOSE */ #if !defined __cplusplus #if __STDC_VERSION__ >= 201112L diff --git a/core/panic.c b/core/panic.c index 6f04d79481..5ccef7410f 100644 --- a/core/panic.c +++ b/core/panic.c @@ -43,8 +43,6 @@ #include "usb_board_reset.h" #endif -const char assert_crash_message[] = "FAILED ASSERTION."; - /* flag preventing "recursive crash printing loop" */ static int crashed = 0;