Make it use builtin functions on clang

pull/13171/head
Esun Kim 6 years ago
parent b70f68269a
commit bc6d9518e1
  1. 6
      upb/port_def.inc

@ -45,14 +45,14 @@
/* UPB_INLINE: inline if possible, emit standalone code if required. */ /* UPB_INLINE: inline if possible, emit standalone code if required. */
#ifdef __cplusplus #ifdef __cplusplus
#define UPB_INLINE inline #define UPB_INLINE inline
#elif defined (__GNUC__) #elif defined (__GNUC__) || defined(__clang__)
#define UPB_INLINE static __inline__ #define UPB_INLINE static __inline__
#else #else
#define UPB_INLINE static #define UPB_INLINE static
#endif #endif
/* Hints to the compiler about likely/unlikely branches. */ /* Hints to the compiler about likely/unlikely branches. */
#ifdef __GNUC__ #if defined (__GNUC__) || defined(__clang__)
#define UPB_LIKELY(x) __builtin_expect((x),1) #define UPB_LIKELY(x) __builtin_expect((x),1)
#define UPB_UNLIKELY(x) __builtin_expect((x),0) #define UPB_UNLIKELY(x) __builtin_expect((x),0)
#else #else
@ -139,7 +139,7 @@ int msvc_snprintf(char* s, size_t n, const char* format, ...);
* exist in debug mode. This turns into regular assert. */ * exist in debug mode. This turns into regular assert. */
#define UPB_ASSERT_DEBUGVAR(expr) assert(expr) #define UPB_ASSERT_DEBUGVAR(expr) assert(expr)
#ifdef __GNUC__ #if defined(__GNUC__) || defined(__clang__)
#define UPB_UNREACHABLE() do { assert(0); __builtin_unreachable(); } while(0) #define UPB_UNREACHABLE() do { assert(0); __builtin_unreachable(); } while(0)
#else #else
#define UPB_UNREACHABLE() do { assert(0); } while(0) #define UPB_UNREACHABLE() do { assert(0); } while(0)

Loading…
Cancel
Save