Skip to content

gh-134586: mark _mi_assert_fail as noreturn, cold and nothrow #134624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Include/internal/mimalloc/mimalloc/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ terms of the MIT license. A copy of the license can be found in the file
#define mi_decl_cache_align
#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

// ------------------------------------------------------
// Variants
// ------------------------------------------------------
Expand Down Expand Up @@ -582,7 +608,8 @@ struct mi_heap_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)
Expand Down
Loading