build: Add unreachable()
unreachable() is used to hint to the compiler that a certain branch cannot ever be reached. The implementation is taken from Mesa. Signed-off-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
parent
35f04139c8
commit
ef87ad2237
@ -79,7 +79,8 @@ elif cc.has_header_symbol('sys/mkdev.h', 'major')
|
||||
endif
|
||||
|
||||
optional_libc_funcs = [
|
||||
'mkostemp', 'strchrnul', 'initgroups', 'posix_fallocate', 'memfd_create'
|
||||
'mkostemp', 'strchrnul', 'initgroups', 'posix_fallocate',
|
||||
'memfd_create', 'unreachable',
|
||||
]
|
||||
foreach func : optional_libc_funcs
|
||||
if cc.has_function(func)
|
||||
|
@ -179,6 +179,26 @@ u64_from_u32s(uint32_t hi, uint32_t lo)
|
||||
return ((uint64_t)hi << 32) + lo;
|
||||
}
|
||||
|
||||
#ifndef __has_builtin
|
||||
# define __has_builtin(x) 0
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_UNREACHABLE) || __has_builtin(__builtin_unreachable)
|
||||
#define unreachable(str) \
|
||||
do { \
|
||||
assert(!str); \
|
||||
__builtin_unreachable(); \
|
||||
} while (0)
|
||||
#elif defined (_MSC_VER)
|
||||
#define unreachable(str) \
|
||||
do { \
|
||||
assert(!str); \
|
||||
__assume(0); \
|
||||
} while (0)
|
||||
#else
|
||||
#define unreachable(str) assert(!str)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user