From a6a4e9766dad5d35a9a03cf508a92b11616f1112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Draszik?= Date: Mon, 25 May 2020 15:32:16 +0100 Subject: [PATCH] unity: annotate noreturn APIs (fix Wsuggest-attribute=noreturn warnings) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC (& Clang) have the notion of pure and const functions [1], where those attributes are intended to help the optimiser. Annotate a few APIs here with the appropriate key words, which also fixes Wsuggest-attribute=noreturn warning, which a source base might have enabled: Compiling unity.c... .../src/unity.c: In function ‘UnityFail’: .../src/unity.c:1759:6: warning: function might be candidate for attribute ‘noreturn’ [-Wsuggest-attribute=noreturn] 1759 | void UnityFail(const char* msg, const UNITY_LINE_TYPE line) | ^~~~~~~~~ .../src/unity.c: In function ‘UnityIgnore’: .../src/unity.c:1796:6: warning: function might be candidate for attribute ‘noreturn’ [-Wsuggest-attribute=noreturn] 1796 | void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line) | ^~~~~~~~~~~ [1] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html Signed-off-by: André Draszik --- src/unity_internals.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/unity_internals.h b/src/unity_internals.h index 705c612..09b7eda 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -40,6 +40,12 @@ #include #endif +#if defined __GNUC__ +# define UNITY_FUNCTION_ATTR(a) __attribute__((a)) +#else +# define UNITY_FUNCTION_ATTR(a) /* ignore */ +#endif + /*------------------------------------------------------- * Guess Widths If Not Specified *-------------------------------------------------------*/ @@ -611,8 +617,8 @@ void UnityAssertNumbersArrayWithin(const UNITY_UINT delta, const UNITY_DISPLAY_STYLE_T style, const UNITY_FLAGS_T flags); -void UnityFail(const char* message, const UNITY_LINE_TYPE line); -void UnityIgnore(const char* message, const UNITY_LINE_TYPE line); +void UnityFail(const char* message, const UNITY_LINE_TYPE line) UNITY_FUNCTION_ATTR(noreturn); +void UnityIgnore(const char* message, const UNITY_LINE_TYPE line) UNITY_FUNCTION_ATTR(noreturn); void UnityMessage(const char* message, const UNITY_LINE_TYPE line); #ifndef UNITY_EXCLUDE_FLOAT