Bug 1424206 - Do not use __builtin_expect when compiling with GCC < 6 draft
authorBotond Ballo <botond@mozilla.com>
Wed, 31 Jan 2018 17:53:09 -0500
changeset 749801 d1e72c32ecce0e8d0a233c9db942bd29f147dd6f
parent 748403 117e0c0d1ebe2cf5bdffc3474744add2416fc511
push id97490
push userbballo@mozilla.com
push dateWed, 31 Jan 2018 22:56:50 +0000
bugs1424206, 68470
milestone60.0a1
Bug 1424206 - Do not use __builtin_expect when compiling with GCC < 6 This is an attempt to workaround GCC PR 68470. MozReview-Commit-ID: JStvo7mVwc3
mfbt/Likely.h
--- a/mfbt/Likely.h
+++ b/mfbt/Likely.h
@@ -7,17 +7,32 @@
 /*
  * MOZ_LIKELY and MOZ_UNLIKELY macros to hint to the compiler how a
  * boolean predicate should be branch-predicted.
  */
 
 #ifndef mozilla_Likely_h
 #define mozilla_Likely_h
 
-#if defined(__clang__) || defined(__GNUC__)
+#include "mozilla/Compiler.h"
+
+#if defined(__clang__)
+#  define MOZ_USE_BUILTIN_EXPECT 1
+#elif defined (__GNUC__)
+// Work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68470
+#  if MOZ_GCC_VERSION_AT_LEAST(6, 0, 0)
+#    define MOZ_USE_BUILTIN_EXPECT 1
+#  else
+#    define MOZ_USE_BUILTIN_EXPECT 0
+#  endif
+#else
+#  define MOZ_USE_BUILTIN_EXPECT 1
+#endif
+
+#if MOZ_USE_BUILTIN_EXPECT
 #  define MOZ_LIKELY(x)   (__builtin_expect(!!(x), 1))
 #  define MOZ_UNLIKELY(x) (__builtin_expect(!!(x), 0))
 #else
 #  define MOZ_LIKELY(x)   (!!(x))
 #  define MOZ_UNLIKELY(x) (!!(x))
 #endif
 
 #endif /* mozilla_Likely_h */