Skip to content

Commit

Permalink
abtu: better ABTU_unreachable if __builtin_unreachable is unsupported
Browse files Browse the repository at this point in the history
Some compilers such as Oracle Solaris C Compiler do not support
__builtin_unreachable().  If so, ABTU_unreachable() should tell the
compiler and the user that this line does not return.  This patch
implements better ABTU_unreachable() for such compilers.
  • Loading branch information
shintaro-iwasaki committed Mar 25, 2021
1 parent 2db1501 commit d3c63b7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/include/abtu.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,24 @@ static inline size_t ABTU_roundup_size(size_t val, size_t multiple)
#define ABTU_unlikely(cond) (cond)
#endif

#ifdef HAVE___BUILTIN_UNREACHABLE
#define ABTU_unreachable() __builtin_unreachable()
#else
#define ABTU_unreachable()
#endif

#ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
#define ABTU_noreturn __attribute__((noreturn))
#else
#define ABTU_noreturn
#endif

#ifdef HAVE___BUILTIN_UNREACHABLE
#define ABTU_unreachable() __builtin_unreachable()
#else
/* abort is better than entering an unknown area. First assert(0), which shows
* something if assert() is enabled. If assert() is disabled, let's abort(). */
static inline ABTU_noreturn void ABTU_unreachable(void)
{
assert(0);
abort();
}
#endif

#ifdef ABT_CONFIG_HAVE_ALIGNOF_GCC
#define ABTU_alignof(type) (__alignof__(type))
#elif defined(ABT_CONFIG_HAVE_ALIGNOF_C11)
Expand Down

0 comments on commit d3c63b7

Please sign in to comment.