Skip to content

Commit c600310

Browse files
authored
gh-134586: mark _mi_assert_fail as noreturn, cold and throw (#134624)
We add the following attributes on `_mi_assert_fail` to help IDE introspection: * `__attribute__((__noreturn__))` * `__attribute__((cold))` * `__THROW` (GCC only)
1 parent ebf6d13 commit c600310

File tree

1 file changed

+28
-1
lines changed
  • Include/internal/mimalloc/mimalloc

1 file changed

+28
-1
lines changed

Include/internal/mimalloc/mimalloc/types.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,32 @@ terms of the MIT license. A copy of the license can be found in the file
5050
#define mi_decl_cache_align
5151
#endif
5252

53+
#if (MI_DEBUG)
54+
#if defined(_MSC_VER)
55+
#define mi_decl_noreturn __declspec(noreturn)
56+
#elif (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__clang__)
57+
#define mi_decl_noreturn __attribute__((__noreturn__))
58+
#else
59+
#define mi_decl_noreturn
60+
#endif
61+
62+
/*
63+
* 'cold' attribute seems to have been fully supported since GCC 4.x.
64+
* See https://github.com/gcc-mirror/gcc/commit/52bf96d2f299e9e6.
65+
*/
66+
#if (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__)
67+
#define mi_decl_cold __attribute__((cold))
68+
#else
69+
#define mi_decl_cold
70+
#endif
71+
72+
#if (defined(__GNUC__) && defined(__THROW))
73+
#define mi_decl_throw __THROW
74+
#else
75+
#define mi_decl_throw
76+
#endif
77+
#endif
78+
5379
// ------------------------------------------------------
5480
// Variants
5581
// ------------------------------------------------------
@@ -582,7 +608,8 @@ struct mi_heap_s {
582608

583609
#if (MI_DEBUG)
584610
// use our own assertion to print without memory allocation
585-
void _mi_assert_fail(const char* assertion, const char* fname, unsigned int line, const char* func );
611+
mi_decl_noreturn mi_decl_cold mi_decl_throw
612+
void _mi_assert_fail(const char* assertion, const char* fname, unsigned int line, const char* func);
586613
#define mi_assert(expr) ((expr) ? (void)0 : _mi_assert_fail(#expr,__FILE__,__LINE__,__func__))
587614
#else
588615
#define mi_assert(x)

0 commit comments

Comments
 (0)