About Social Code
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Ospite <antonio.ospite@collabora.com>2025-07-30 10:33:33 +0200
committerMarge Bot <marge-bot@fdo.invalid>2025-07-31 17:49:43 +0000
commit9ced3148ca18e8b057e7f2a7e773c701b95c8741 (patch)
tree5a45c0ecba185b417584911c9f08ae85594384f5
parentddf2aa3a4d305fddbe30b8e9b366887fc904d3ba (diff)
util: avoid calling UNREACHABLE(str) macro without arguments
After commit 2dcd6bed6a9 ("util: enforce unreachable()'s argument being a literal string", 2023-04-17) the compiler effectively emit errors when an argument that is not a string literal is passed to UNREACHABLE(str), however the compiler still allows the macro to be called without arguments, which can be confusing. Implement the type check outside of the assert() call so that we have two types of errors: 1. The compiler will error out when the argument passed to the macro is not a string literal because the concatenation with an empty string will not be allowed. 2. The compiler will error out when no arguments are passed to the macro because the invocation of assert() will be invalid. This also has the nice side-effect of removing the extra empty string printed in the assert() messages; after the changes the messages will look like: Assertion `!"Invalid type"' failed. instead of: Assertion `!"" "Invalid type"' failed. Fixes: 2dcd6bed6a9 ("util: enforce unreachable()'s argument being a literal string", 2023-04-17) Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36437>
-rw-r--r--src/util/macros.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/util/macros.h b/src/util/macros.h
index af4c8c80b60..9403d337e49 100644
--- a/src/util/macros.h
+++ b/src/util/macros.h
@@ -122,17 +122,23 @@
#if defined(HAVE___BUILTIN_UNREACHABLE) || __has_builtin(__builtin_unreachable)
#define UNREACHABLE(str) \
do { \
- assert(!"" str); \
+ (void)"" str; /* str must be a string literal */ \
+ assert(!str); \
__builtin_unreachable(); \
} while (0)
#elif defined (_MSC_VER)
#define UNREACHABLE(str) \
do { \
- assert(!"" str); \
+ (void)"" str; /* str must be a string literal */ \
+ assert(!str); \
__assume(0); \
} while (0)
#else
-#define UNREACHABLE(str) assert(!"" str)
+#define UNREACHABLE(str) \
+do { \
+ (void)"" str; /* str must be a string literal */ \
+ assert(!str); \
+} while (0)
#endif
/**