lib: os: assert: Add unreachable path hint for assertion failure
This commit adds the `CODE_UNREACHABLE` hint at the end of the assertion failure branch so that the compiler takes note of the assert function not returning when an assertion fails. This prevents the compiler from generating misguided warnings assuming the asserted execution paths. It also introduces the `ASSERT_TEST` Kconfig symbol, which indicates that the "assert test mode" is enabled. This symbol may be selected by the tests that require the assert post action function to return without aborting so that the test can proceed. Note that the `CODE_UNREACHABLE` hint is specified only when the assert test mode is disabled in order to prevent the tests from crashing when the assert post action function returns. Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
This commit is contained in:
parent
8401644416
commit
230ddd9a7f
@ -87,6 +87,17 @@ void assert_post_action(const char *file, unsigned int line);
|
||||
#define __ASSERT_POST_ACTION() assert_post_action(__FILE__, __LINE__)
|
||||
#endif /* CONFIG_ASSERT_NO_FILE_INFO */
|
||||
|
||||
/*
|
||||
* When the assert test mode is enabled, the default kernel fatal error handler
|
||||
* and the custom assert hook function may return in order to allow the test to
|
||||
* proceed.
|
||||
*/
|
||||
#ifdef CONFIG_ASSERT_TEST
|
||||
#define __ASSERT_UNREACHABLE
|
||||
#else
|
||||
#define __ASSERT_UNREACHABLE CODE_UNREACHABLE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -96,6 +107,7 @@ void assert_post_action(const char *file, unsigned int line);
|
||||
if (!(test)) { \
|
||||
__ASSERT_LOC(test); \
|
||||
__ASSERT_POST_ACTION(); \
|
||||
__ASSERT_UNREACHABLE; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
@ -105,6 +117,7 @@ void assert_post_action(const char *file, unsigned int line);
|
||||
__ASSERT_LOC(test); \
|
||||
__ASSERT_MSG_INFO(fmt, ##__VA_ARGS__); \
|
||||
__ASSERT_POST_ACTION(); \
|
||||
__ASSERT_UNREACHABLE; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
|
||||
@ -281,6 +281,15 @@ config ASSERT_NO_MSG_INFO
|
||||
before disabling file info since the message can be found in the
|
||||
source using file info.
|
||||
|
||||
config ASSERT_TEST
|
||||
bool "Assert test mode"
|
||||
help
|
||||
This option enables the assert test mode, which allows the assert
|
||||
post action handler to return (i.e. not abort) when the asserted
|
||||
condition is false. The tests that validate the assert feature may
|
||||
select this option to allow the test to proceed by implementing a
|
||||
custom assert post action hook.
|
||||
|
||||
config OVERRIDE_FRAME_POINTER_DEFAULT
|
||||
bool "Override compiler defaults for -fomit-frame-pointer"
|
||||
help
|
||||
|
||||
Loading…
Reference in New Issue
Block a user