fix(hal): use __builtin_unreachable in no-assert mode

otherwise due to esp-idf using -Werror, we can get errors in code which
uses HAL_ASSERT if for example the compiler believes that a variable is
used uninitialised, or similar.

Inspired by https://github.com/espressif/esp-idf/pull/13256
This commit is contained in:
morris 2024-03-04 11:04:03 +08:00
parent eeb5e2f080
commit be8033701c
2 changed files with 4 additions and 1 deletions

View File

@ -38,7 +38,7 @@ extern void abort(void);
#elif CONFIG_HAL_DEFAULT_ASSERTION_LEVEL == 2 // full assertion #elif CONFIG_HAL_DEFAULT_ASSERTION_LEVEL == 2 // full assertion
#define HAL_ASSERT(__e) (__builtin_expect(!!(__e), 1) ? (void)0 : __assert_func(__FILE__, __LINE__, __ASSERT_FUNC, #__e)) #define HAL_ASSERT(__e) (__builtin_expect(!!(__e), 1) ? (void)0 : __assert_func(__FILE__, __LINE__, __ASSERT_FUNC, #__e))
#else // no assert #else // no assert
#define HAL_ASSERT(__e) ((void)(__e)) #define HAL_ASSERT(__e) (__builtin_expect(!!(__e), 1) ? (void)0 : __builtin_unreachable())
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,3 +1,6 @@
CONFIG_PARTITION_TABLE_OFFSET=0x9000 CONFIG_PARTITION_TABLE_OFFSET=0x9000
CONFIG_BT_ENABLED=y CONFIG_BT_ENABLED=y
CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=n CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=n
# want to test clang build with HAL assertion disabled
CONFIG_HAL_ASSERTION_DISABLE=y