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
--- 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 */