Bug 836078 - Replace all gcc __GNUC__ version checks with MOZ_GCC_VERSION_AT_LEAST macro. r=dvander
authorStephen Kraemer <sbkraeme@uwaterloo.ca>
Wed, 01 May 2013 15:45:05 -0400
changeset 141472 4412438e83c4aa55195dcfaf56070d2ff8d9bd95
parent 141471 331187bfb98382ac561ad3a23401bd6d95eb52f7
child 141473 05275490b9c18457c4459057a117afd6d6c9226d
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs836078
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 836078 - Replace all gcc __GNUC__ version checks with MOZ_GCC_VERSION_AT_LEAST macro. r=dvander
js/public/Utility.h
js/src/jsutil.h
mfbt/Compiler.h
toolkit/mozapps/update/updater/updater.cpp
xpcom/reflect/xptcall/src/md/unix/xptcinvoke_arm.cpp
--- a/js/public/Utility.h
+++ b/js/public/Utility.h
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef js_utility_h__
 #define js_utility_h__
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/Compiler.h"
 #include "mozilla/Scoped.h"
 
 #include <stdlib.h>
 #include <string.h>
 
 #ifdef JS_OOM_DO_BACKTRACES
 #include <stdio.h>
 #include <execinfo.h>
@@ -224,27 +225,42 @@ unsigned char _BitScanReverse64(unsigned
 
     _BitScanReverse64(&idx, val);
     return (int)(63-idx);
 }
 # define js_bitscan_ctz64(val)  __BitScanForward64(val)
 # define js_bitscan_clz64(val)  __BitScanReverse64(val)
 # define JS_HAS_BUILTIN_BITSCAN64
 #endif
-#elif (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+#elif MOZ_IS_GCC
+
+#if MOZ_GCC_VERSION_AT_LEAST(3, 4, 0)
+# define USE_BUILTIN_CTZ
+#endif
+
+#elif defined(__clang__)
 
+#if __has_builtin(__builtin_ctz)
+# define USE_BUILTIN_CTZ
+#endif
+
+#endif
+
+#if defined(USE_BUILTIN_CTZ)
 # define js_bitscan_ctz32(val)  __builtin_ctz(val)
 # define js_bitscan_clz32(val)  __builtin_clz(val)
 # define JS_HAS_BUILTIN_BITSCAN32
 # if (JS_BYTES_PER_WORD == 8)
 #  define js_bitscan_ctz64(val)  __builtin_ctzll(val)
 #  define js_bitscan_clz64(val)  __builtin_clzll(val)
 #  define JS_HAS_BUILTIN_BITSCAN64
 # endif
 
+# undef USE_BUILTIN_CTZ
+
 #endif
 
 /*
 ** Macro version of JS_CeilingLog2: Compute the log of the least power of
 ** 2 greater than or equal to _n. The result is returned in _log2.
 */
 #ifdef JS_HAS_BUILTIN_BITSCAN32
 /*
--- a/js/src/jsutil.h
+++ b/js/src/jsutil.h
@@ -7,16 +7,17 @@
 /*
  * PR assertion checker.
  */
 
 #ifndef jsutil_h___
 #define jsutil_h___
 
 #include "mozilla/Attributes.h"
+#include "mozilla/Compiler.h"
 #include "mozilla/GuardObjects.h"
 
 #include "js/Utility.h"
 
 #ifdef USE_ZLIB
 #include "zlib.h"
 #endif
 
@@ -365,24 +366,29 @@ typedef size_t jsbitmap;
 # define JS_SILENCE_UNUSED_VALUE_IN_EXPR(expr)                                \
     JS_BEGIN_MACRO                                                            \
         _Pragma("clang diagnostic push")                                      \
         /* If these _Pragmas cause warnings for you, try disabling ccache. */ \
         _Pragma("clang diagnostic ignored \"-Wunused-value\"")                \
         { expr; }                                                             \
         _Pragma("clang diagnostic pop")                                       \
     JS_END_MACRO
-#elif (__GNUC__ >= 5) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#elif MOZ_IS_GCC
+
+#if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0)
 # define JS_SILENCE_UNUSED_VALUE_IN_EXPR(expr)                                \
     JS_BEGIN_MACRO                                                            \
         _Pragma("GCC diagnostic push")                                        \
         _Pragma("GCC diagnostic ignored \"-Wunused-but-set-variable\"")       \
         expr;                                                                 \
         _Pragma("GCC diagnostic pop")                                         \
     JS_END_MACRO
-#else
+#endif
+#endif
+
+#if !defined(JS_SILENCE_UNUSED_VALUE_IN_EXPR)
 # define JS_SILENCE_UNUSED_VALUE_IN_EXPR(expr)                                \
     JS_BEGIN_MACRO                                                            \
         expr;                                                                 \
     JS_END_MACRO
 #endif
 
 #endif /* jsutil_h___ */
--- a/mfbt/Compiler.h
+++ b/mfbt/Compiler.h
@@ -4,21 +4,28 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Various compiler checks. */
 
 #ifndef mozilla_Compiler_h_
 #define mozilla_Compiler_h_
 
 #if !defined(__clang__) && defined(__GNUC__)
+
+#define MOZ_IS_GCC 1
    /*
     * This macro should simplify gcc version checking. For example, to check
     * for gcc 4.5.1 or later, check `#ifdef MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`.
     */
 #  define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel)          \
      ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \
       >= ((major) * 10000 + (minor) * 100 + (patchlevel)))
 #if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0)
 #  error "mfbt (and Gecko) require at least gcc 4.4 to build."
 #endif
+
+#else
+
+#define MOZ_IS_GCC 0
+
 #endif
 
 #endif  /* mozilla_Compiler_h_ */
--- a/toolkit/mozapps/update/updater/updater.cpp
+++ b/toolkit/mozapps/update/updater/updater.cpp
@@ -45,16 +45,18 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <limits.h>
 #include <errno.h>
 
 #include "updatelogging.h"
 
+#include "mozilla/Compiler.h"
+
 // Amount of the progress bar to use in each of the 3 update stages,
 // should total 100.0.
 #define PROGRESS_PREPARE_SIZE 20.0f
 #define PROGRESS_EXECUTE_SIZE 75.0f
 #define PROGRESS_FINISH_SIZE   5.0f
 
 #if defined(XP_MACOSX)
 // These functions are defined in launchchild_osx.mm
@@ -114,22 +116,30 @@ static bool sUseHardLinks = true;
       } \
   }
 #endif
 
 //-----------------------------------------------------------------------------
 
 // This variable lives in libbz2.  It's declared in bzlib_private.h, so we just
 // declare it here to avoid including that entire header file.
-#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
+#define BZ2_CRC32TABLE_UNDECLARED
+
+#if MOZ_IS_GCC
+#if MOZ_GCC_VERSION_AT_LEAST(3, 3, 0)
 extern "C"  __attribute__((visibility("default"))) unsigned int BZ2_crc32Table[256];
+#undef BZ2_CRC32TABLE_UNDECLARED
+#endif
 #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
 extern "C" __global unsigned int BZ2_crc32Table[256];
-#else
+#undef BZ2_CRC32TABLE_UNDECLARED
+#endif
+#if defined(BZ2_CRC32TABLE_UNDECLARED)
 extern "C" unsigned int BZ2_crc32Table[256];
+#undef BZ2_CRC32TABLE_UNDECLARED
 #endif
 
 static unsigned int
 crc32(const unsigned char *buf, unsigned int len)
 {
   unsigned int crc = 0xffffffffL;
 
   const unsigned char *end = buf + len;
--- a/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_arm.cpp
+++ b/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_arm.cpp
@@ -2,24 +2,28 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Platform specific code to invoke XPCOM methods on native objects */
 
 #include "xptcprivate.h"
 
+#include "mozilla/Compiler.h"
+
 #if !defined(__arm__) && !(defined(LINUX) || defined(ANDROID))
 #error "This code is for Linux ARM only. Check that it works on your system, too.\nBeware that this code is highly compiler dependent."
 #endif
 
-#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) \
+#if MOZ_IS_GCC
+#if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) \
     && defined(__ARM_EABI__) && !defined(__ARM_PCS_VFP) && !defined(__ARM_PCS)
 #error "Can't identify floating point calling conventions.\nPlease ensure that your toolchain defines __ARM_PCS or __ARM_PCS_VFP."
 #endif
+#endif
 
 #ifndef __ARM_PCS_VFP
 
 /* This function copies a 64-bits word from dw to the given pointer in
  * a buffer delimited by start and end, possibly wrapping around the
  * buffer boundaries, and/or properly aligning the data at 64-bits word
  * boundaries (for EABI).
  * start and end are both assumed to be 64-bits aligned.