Bug 833254 - Fix MFBT's gcc version checks. r=waldo
authorChris Peterson <cpeterson@mozilla.com>
Mon, 21 Jan 2013 19:42:15 -0800
changeset 120533 ecdbffdf275adaf214ae7c8e2cc91ba20ccfd181
parent 120532 566e7485b29a069593bbcaf53c0cf59e6b8d517a
child 120534 d7f4807655ec0ab476070469c3fc2fe01680a4f4
push id24256
push userryanvm@gmail.com
push dateFri, 01 Feb 2013 20:50:01 +0000
treeherdermozilla-central@4e7c92906a79 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs833254
milestone21.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 833254 - Fix MFBT's gcc version checks. r=waldo
mfbt/Assertions.h
mfbt/Attributes.h
mfbt/Compiler.h
mfbt/NullPtr.h
mfbt/TypedEnum.h
mfbt/exported_headers.mk
--- a/mfbt/Assertions.h
+++ b/mfbt/Assertions.h
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Implementations of runtime and static assertion macros for C and C++. */
 
 #ifndef mozilla_Assertions_h_
 #define mozilla_Assertions_h_
 
 #include "mozilla/Attributes.h"
+#include "mozilla/Compiler.h"
 
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #ifdef WIN32
    /*
     * TerminateProcess and GetCurrentProcess are defined in <winbase.h>, which
     * further depends on <windef.h>.  We hardcode these few definitions manually
@@ -307,17 +308,17 @@ MOZ_ReportAssertionFailure(const char* s
 #if defined(__clang__)
 #  define MOZ_NOT_REACHED_MARKER() __builtin_unreachable()
 #elif defined(__GNUC__)
    /*
     * __builtin_unreachable() was implemented in gcc 4.5.  If we don't have
     * that, call a noreturn function; abort() will do nicely.  Qualify the call
     * in C++ in case there's another abort() visible in local scope.
     */
-#  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+#  if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0)
 #    define MOZ_NOT_REACHED_MARKER() __builtin_unreachable()
 #  else
 #    ifdef __cplusplus
 #      define MOZ_NOT_REACHED_MARKER() ::abort()
 #    else
 #      define MOZ_NOT_REACHED_MARKER() abort()
 #    endif
 #  endif
--- a/mfbt/Attributes.h
+++ b/mfbt/Attributes.h
@@ -3,20 +3,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/. */
 
 /* Implementations of various class and method modifier attributes. */
 
 #ifndef mozilla_Attributes_h_
 #define mozilla_Attributes_h_
 
-/*
- * This header does not include any other headers so that it can be included by
- * code that is (only currently) mfbt-incompatible.
- */
+#include "mozilla/Compiler.h"
 
 /*
  * MOZ_INLINE is a macro which expands to tell the compiler that the method
  * decorated with it should be inlined.  This macro is usable from C and C++
  * code, even though C89 does not support the |inline| keyword.  The compiler
  * may ignore this directive if it chooses.
  */
 #if defined(__cplusplus)
@@ -76,38 +73,28 @@
 #  if __has_attribute(noinline)
 #    define MOZ_HAVE_NEVER_INLINE        __attribute__((noinline))
 #  endif
 #  if __has_attribute(noreturn)
 #    define MOZ_HAVE_NORETURN            __attribute__((noreturn))
 #  endif
 #elif defined(__GNUC__)
 #  if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
-#    if __GNUC__ > 4
-#      define MOZ_HAVE_CXX11_DELETE
+#    if MOZ_GCC_VERSION_AT_LEAST(4, 7, 0)
 #      define MOZ_HAVE_CXX11_OVERRIDE
 #      define MOZ_HAVE_CXX11_FINAL       final
-#    elif __GNUC__ == 4
-#      if __GNUC_MINOR__ >= 7
-#        define MOZ_HAVE_CXX11_OVERRIDE
-#        define MOZ_HAVE_CXX11_FINAL     final
-#      endif
-#      if __GNUC_MINOR__ >= 6
-#        define MOZ_HAVE_CXX11_CONSTEXPR
-#      endif
-#      define MOZ_HAVE_CXX11_DELETE
 #    endif
+#    if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0)
+#      define MOZ_HAVE_CXX11_CONSTEXPR
+#    endif
+#    define MOZ_HAVE_CXX11_DELETE
 #  else
      /* __final is a non-C++11 GCC synonym for 'final', per GCC r176655. */
-#    if __GNUC__ > 4
+#    if MOZ_GCC_VERSION_AT_LEAST(4, 7, 0)
 #      define MOZ_HAVE_CXX11_FINAL       __final
-#    elif __GNUC__ == 4
-#      if __GNUC_MINOR__ >= 7
-#        define MOZ_HAVE_CXX11_FINAL     __final
-#      endif
 #    endif
 #  endif
 #  define MOZ_HAVE_NEVER_INLINE          __attribute__((noinline))
 #  define MOZ_HAVE_NORETURN              __attribute__((noreturn))
 #elif defined(_MSC_VER)
 #  if _MSC_VER >= 1700
 #    define MOZ_HAVE_CXX11_FINAL         final
 #  else
new file mode 100644
--- /dev/null
+++ b/mfbt/Compiler.h
@@ -0,0 +1,24 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+/* Various compiler checks. */
+
+#ifndef mozilla_Compiler_h_
+#define mozilla_Compiler_h_
+
+#if !defined(__clang__) && defined(__GNUC__)
+   /*
+    * 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
+#endif
+
+#endif  /* mozilla_Compiler_h_ */
--- a/mfbt/NullPtr.h
+++ b/mfbt/NullPtr.h
@@ -6,26 +6,28 @@
 /*
  * Implements a workaround for compilers which do not support the C++11 nullptr
  * constant.
  */
 
 #ifndef mozilla_NullPtr_h_
 #define mozilla_NullPtr_h_
 
+#include "mozilla/Compiler.h"
+
 #if defined(__clang__)
 #  ifndef __has_extension
 #    define __has_extension __has_feature
 #  endif
 #  if __has_extension(cxx_nullptr)
 #    define MOZ_HAVE_CXX11_NULLPTR
 #  endif
 #elif defined(__GNUC__)
 #  if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
-#    if (__GNUC__ * 1000 + __GNUC_MINOR__) >= 4006
+#    if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0)
 #      define MOZ_HAVE_CXX11_NULLPTR
 #    endif
 #  endif
 #elif _MSC_VER >= 1600
 # define MOZ_HAVE_CXX11_NULLPTR
 #endif
 
 /**
--- a/mfbt/TypedEnum.h
+++ b/mfbt/TypedEnum.h
@@ -22,24 +22,19 @@
 #    define __has_extension __has_feature /* compatibility, for older versions of clang */
 #  endif
 #  if __has_extension(cxx_strong_enums)
 #    define MOZ_HAVE_CXX11_ENUM_TYPE
 #    define MOZ_HAVE_CXX11_STRONG_ENUMS
 #  endif
 #elif defined(__GNUC__)
 #  if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
-#    if __GNUC__ > 4
+#    if MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)
 #      define MOZ_HAVE_CXX11_ENUM_TYPE
 #      define MOZ_HAVE_CXX11_STRONG_ENUMS
-#    elif __GNUC__ == 4
-#      if __GNUC_MINOR__ >= 5
-#        define MOZ_HAVE_CXX11_ENUM_TYPE
-#        define MOZ_HAVE_CXX11_STRONG_ENUMS
-#      endif
 #    endif
 #  endif
 #elif defined(_MSC_VER)
 #  if _MSC_VER >= 1400
 #    define MOZ_HAVE_CXX11_ENUM_TYPE
 #  endif
 #  if _MSC_VER >= 1700
 #    define MOZ_HAVE_CXX11_STRONG_ENUMS
--- a/mfbt/exported_headers.mk
+++ b/mfbt/exported_headers.mk
@@ -9,16 +9,17 @@
 EXPORTS_NAMESPACES += mozilla
 
 EXPORTS_mozilla += \
   Assertions.h \
   Attributes.h \
   BloomFilter.h \
   Char16.h \
   CheckedInt.h \
+  Compiler.h \
   Constants.h \
   DebugOnly.h \
   EnumSet.h \
   FloatingPoint.h \
   GuardObjects.h \
   HashFunctions.h \
   Likely.h \
   LinkedList.h \