From e171e76319bd4ecaebf5585157dfc520006cf552 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Mon, 21 Jan 2013 19:42:15 -0800 Subject: [PATCH] Bug 833254 - Fix MFBT's gcc version checks. r=waldo --- mfbt/Assertions.h | 3 ++- mfbt/Attributes.h | 27 +++++++-------------------- mfbt/Compiler.h | 24 ++++++++++++++++++++++++ mfbt/NullPtr.h | 4 +++- mfbt/TypedEnum.h | 7 +------ mfbt/exported_headers.mk | 1 + 6 files changed, 38 insertions(+), 28 deletions(-) create mode 100644 mfbt/Compiler.h diff --git a/mfbt/Assertions.h b/mfbt/Assertions.h index ba949ce6a3a9..6b973627cba1 100644 --- a/mfbt/Assertions.h +++ b/mfbt/Assertions.h @@ -9,6 +9,7 @@ #define mozilla_Assertions_h_ #include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" #include #include @@ -312,7 +313,7 @@ MOZ_ReportAssertionFailure(const char* s, const char* file, int ln) * 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 diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h index ca18d6e9e5fa..35a23b6629c1 100644 --- a/mfbt/Attributes.h +++ b/mfbt/Attributes.h @@ -8,10 +8,7 @@ #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 @@ -81,28 +78,18 @@ # 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)) diff --git a/mfbt/Compiler.h b/mfbt/Compiler.h new file mode 100644 index 000000000000..e4f26f42faa8 --- /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_ */ diff --git a/mfbt/NullPtr.h b/mfbt/NullPtr.h index 6e518d6c7a30..7dcb03d73459 100644 --- a/mfbt/NullPtr.h +++ b/mfbt/NullPtr.h @@ -11,6 +11,8 @@ #ifndef mozilla_NullPtr_h_ #define mozilla_NullPtr_h_ +#include "mozilla/Compiler.h" + #if defined(__clang__) # ifndef __has_extension # define __has_extension __has_feature @@ -20,7 +22,7 @@ # 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 diff --git a/mfbt/TypedEnum.h b/mfbt/TypedEnum.h index 56ada45d6099..889960a32da9 100644 --- a/mfbt/TypedEnum.h +++ b/mfbt/TypedEnum.h @@ -27,14 +27,9 @@ # 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) diff --git a/mfbt/exported_headers.mk b/mfbt/exported_headers.mk index d1d3ecf2753e..ffd3405a5c50 100644 --- a/mfbt/exported_headers.mk +++ b/mfbt/exported_headers.mk @@ -14,6 +14,7 @@ EXPORTS_mozilla += \ BloomFilter.h \ Char16.h \ CheckedInt.h \ + Compiler.h \ Constants.h \ DebugOnly.h \ EnumSet.h \