From f8b10a67dae2b183af129ec89888b46e78ebea32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 30 May 2025 14:54:49 +0200 Subject: [PATCH] mark _mi_assert_fail as noreturn, cold and throw --- include/mimalloc/internal.h | 26 ++++++++++++++++++++++++++ include/mimalloc/types.h | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/mimalloc/internal.h b/include/mimalloc/internal.h index eae85ab6..e1d1cdf6 100644 --- a/include/mimalloc/internal.h +++ b/include/mimalloc/internal.h @@ -52,6 +52,32 @@ terms of the MIT license. A copy of the license can be found in the file #define mi_decl_hidden #endif +#if (MI_DEBUG) +#if defined(_MSC_VER) +#define mi_decl_noreturn __declspec(noreturn) +#elif (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__clang__) +#define mi_decl_noreturn __attribute__((__noreturn__)) +#else +#define mi_decl_noreturn +#endif + +/* + * 'cold' attribute seems to have been fully supported since GCC 4.x. + * See https://github.com/gcc-mirror/gcc/commit/52bf96d2f299e9e6. + */ +#if (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) +#define mi_decl_cold __attribute__((cold)) +#else +#define mi_decl_cold +#endif + +#if (defined(__GNUC__) && defined(__THROW)) +#define mi_decl_throw __THROW +#else +#define mi_decl_throw +#endif +#endif + #if defined(__EMSCRIPTEN__) && !defined(__wasi__) #define __wasi__ #endif diff --git a/include/mimalloc/types.h b/include/mimalloc/types.h index 5a3f5fe2..6959116f 100644 --- a/include/mimalloc/types.h +++ b/include/mimalloc/types.h @@ -650,7 +650,8 @@ struct mi_tld_s { #if (MI_DEBUG) // use our own assertion to print without memory allocation -void _mi_assert_fail(const char* assertion, const char* fname, unsigned int line, const char* func ); +mi_decl_noreturn mi_decl_cold mi_decl_throw +void _mi_assert_fail(const char* assertion, const char* fname, unsigned int line, const char* func); #define mi_assert(expr) ((expr) ? (void)0 : _mi_assert_fail(#expr,__FILE__,__LINE__,__func__)) #else #define mi_assert(x)