feat(newlib): add option to disable eval of expression in assert() when NDEBUG set

According to the standard assert(X) should be replaced by a void expression when
NDEBUG is set. IDF's behavior was to not trigger an assertion, but we would still
evaluate X, e.g. if X was a function it would be ran.

This MR adds a kconfig option CONFIG_COMPILER_ASSERT_NDEBUG_EVALUATE which allows us
revert the behavior to be inline with the standard.

With IDF v6.0 the plan is to make CONFIG_COMPILER_ASSERT_NDEBUG_EVALUATE=n the default
behavior.

Closes https://github.com/espressif/esp-idf/issues/10136
Closes https://github.com/espressif/esp-idf/issues/2758
This commit is contained in:
Marius Vikhammer
2024-08-15 16:40:19 +08:00
parent c01ccd1f62
commit ff8265b6b3
3 changed files with 21 additions and 0 deletions

View File

@@ -30,7 +30,11 @@
#if defined(NDEBUG)
#if CONFIG_COMPILER_ASSERT_NDEBUG_EVALUATE
#define assert(__e) ((void)(__e))
#else
#define assert(__e) ((void)0)
#endif //CONFIG_COMPILER_ASSERT_NDEBUG_EVALUATE
#elif CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT