From 729541f7ca1129731a2ec79492d15e7ecb3cad80 Mon Sep 17 00:00:00 2001
From: Thiago Macieira <thiago.macieira@intel.com>
Date: Tue, 4 Nov 2014 11:40:30 -0800
Subject: [PATCH] Store the GCC version number in Q_CC_GNU

The sequence of (__GNUC__ * 100 + __GNUC_MINOR__) was used in quite a
few places. Simplify it to make the code more readable.

This follows the change done for Clang, which was quite necessary since
Apple's version of Clang has different build numbers.

Change-Id: I886271a5a5f21ae59485ecf8d140527723345a46
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
---
 src/corelib/global/qcompilerdetection.h | 24 ++++++++++++------------
 src/corelib/global/qglobal.h            |  2 +-
 src/corelib/tools/qsimd.cpp             |  2 +-
 src/corelib/tools/qsimd_p.h             |  4 ++--
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h
index de8a53ea06f..ef37f001891 100644
--- a/src/corelib/global/qcompilerdetection.h
+++ b/src/corelib/global/qcompilerdetection.h
@@ -137,7 +137,7 @@
 #  endif
 
 #elif defined(__GNUC__)
-#  define Q_CC_GNU
+#  define Q_CC_GNU          (__GNUC__ * 100 + __GNUC_MINOR__)
 #  define Q_C_CALLBACKS
 #  if defined(__MINGW32__)
 #    define Q_CC_MINGW
@@ -187,7 +187,7 @@
 #    endif
 #  else
 /* Plain GCC */
-#    if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405
+#    if Q_CC_GNU >= 405
 #      define Q_ASSUME_IMPL(expr)  if (expr){} else __builtin_unreachable()
 #      define Q_UNREACHABLE_IMPL() __builtin_unreachable()
 #      define Q_DECL_DEPRECATED_X(text) __attribute__ ((__deprecated__(text)))
@@ -221,7 +221,7 @@
 #      define QT_NO_ARM_EABI
 #    endif
 #  endif
-#  if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403 && !defined(Q_CC_CLANG)
+#  if Q_CC_GNU >= 403 && !defined(Q_CC_CLANG)
 #      define Q_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
 #  endif
 
@@ -728,7 +728,7 @@
 #if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_CLANG)
 #  define Q_COMPILER_RESTRICTED_VLA
 #  define Q_COMPILER_THREADSAFE_STATICS
-#  if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403
+#  if Q_CC_GNU >= 403
 //   GCC supports binary literals in C, C++98 and C++11 modes
 #    define Q_COMPILER_BINARY_LITERALS
 #  endif
@@ -739,13 +739,13 @@
 #    define Q_COMPILER_VARIADIC_MACROS
 #  endif
 #  if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
-#    if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403
+#    if Q_CC_GNU >= 403
        /* C++11 features supported in GCC 4.3: */
 #      define Q_COMPILER_DECLTYPE
 #      define Q_COMPILER_RVALUE_REFS
 #      define Q_COMPILER_STATIC_ASSERT
 #    endif
-#    if (__GNUC__ * 100 + __GNUC_MINOR__) >= 404
+#    if Q_CC_GNU >= 404
        /* C++11 features supported in GCC 4.4: */
 #      define Q_COMPILER_AUTO_FUNCTION
 #      define Q_COMPILER_AUTO_TYPE
@@ -754,7 +754,7 @@
 #      define Q_COMPILER_UNICODE_STRINGS
 #      define Q_COMPILER_VARIADIC_TEMPLATES
 #    endif
-#    if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405
+#    if Q_CC_GNU >= 405
        /* C++11 features supported in GCC 4.5: */
 #      define Q_COMPILER_EXPLICIT_CONVERSIONS
        /* GCC 4.4 implements initializer_list but does not define typedefs required
@@ -764,7 +764,7 @@
 #      define Q_COMPILER_RAW_STRINGS
 #      define Q_COMPILER_CLASS_ENUM
 #    endif
-#    if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406
+#    if Q_CC_GNU >= 406
        /* Pre-4.6 compilers implement a non-final snapshot of N2346, hence default and delete
         * functions are supported only if they are public. Starting from 4.6, GCC handles
         * final version - the access modifier is not relevant. */
@@ -776,7 +776,7 @@
 #      define Q_COMPILER_UNRESTRICTED_UNIONS
 #      define Q_COMPILER_RANGE_FOR
 #    endif
-#    if (__GNUC__ * 100 + __GNUC_MINOR__) >= 407
+#    if Q_CC_GNU >= 407
        /* GCC 4.4 implemented <atomic> and std::atomic using its old intrinsics.
         * However, the implementation is incomplete for most platforms until GCC 4.7:
         * instead, std::atomic would use an external lock. Since we need an std::atomic
@@ -792,20 +792,20 @@
 #      define Q_COMPILER_TEMPLATE_ALIAS
 #      define Q_COMPILER_UDL
 #    endif
-#    if (__GNUC__ * 100 + __GNUC_MINOR__) >= 408
+#    if Q_CC_GNU >= 408
 #      define Q_COMPILER_ATTRIBUTES
 #      define Q_COMPILER_ALIGNAS
 #      define Q_COMPILER_ALIGNOF
 #      define Q_COMPILER_INHERITING_CONSTRUCTORS
 #      define Q_COMPILER_THREAD_LOCAL
-#      if (__GNUC__ * 100 + __GNUC_MINOR__) > 408 || __GNUC_PATCHLEVEL__ >= 1
+#      if Q_CC_GNU > 408 || __GNUC_PATCHLEVEL__ >= 1
 #         define Q_COMPILER_REF_QUALIFIERS
 #      endif
 #    endif
      /* C++11 features are complete as of GCC 4.8.1 */
 #  endif
 #  if __cplusplus > 201103L
-#    if (__GNUC__ * 100 + __GNUC_MINOR__) >= 409
+#    if Q_CC_GNU >= 409
      /* C++1y features in GCC 4.9 - deprecated, do not update this list */
 //#    define Q_COMPILER_BINARY_LITERALS   // already supported since GCC 4.3 as an extension
 #      define Q_COMPILER_LAMBDA_CAPTURES
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 8bc489e5095..f17ff3dea08 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -877,7 +877,7 @@ public:
 // (http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#382).
 // GCC 4.3 and 4.4 have support for decltype, but are affected by DR 382.
 #  if defined(Q_COMPILER_DECLTYPE) && \
-    (defined(Q_CC_CLANG) || defined(Q_CC_INTEL) || !defined(Q_CC_GNU) || (__GNUC__ * 100 + __GNUC_MINOR__) >= 405)
+    (defined(Q_CC_CLANG) || defined(Q_CC_INTEL) || !defined(Q_CC_GNU) || Q_CC_GNU >= 405)
 #    define QT_FOREACH_DECLTYPE(x) typename QtPrivate::remove_reference<decltype(x)>::type
 #  else
 #    define QT_FOREACH_DECLTYPE(x) __typeof__((x))
diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp
index 0b3bbc0ad0d..5281723c5da 100644
--- a/src/corelib/tools/qsimd.cpp
+++ b/src/corelib/tools/qsimd.cpp
@@ -519,7 +519,7 @@ QBasicAtomicInt qt_cpu_features = Q_BASIC_ATOMIC_INITIALIZER(0);
 void qDetectCpuFeatures()
 {
 #if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL)
-# if (__GNUC__ * 100 + __GNUC_MINOR__) < 403
+# if Q_CC_GNU < 403
     // GCC 4.2 (at least the one that comes with Apple's XCode, on Mac) is
     // known to be broken beyond repair in dealing with the inline assembly
     // above. It will generate bad code that could corrupt important registers
diff --git a/src/corelib/tools/qsimd_p.h b/src/corelib/tools/qsimd_p.h
index 3241e09b08f..891a3ff0534 100644
--- a/src/corelib/tools/qsimd_p.h
+++ b/src/corelib/tools/qsimd_p.h
@@ -218,7 +218,7 @@
 #endif
 
 // other x86 intrinsics
-#if defined(Q_PROCESSOR_X86) && ((defined(Q_CC_GNU) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)) \
+#if defined(Q_PROCESSOR_X86) && ((defined(Q_CC_GNU) && (Q_CC_GNU >= 404)) \
     || (defined(Q_CC_CLANG) && (Q_CC_CLANG >= 208)) \
     || defined(Q_CC_INTEL))
 #  define QT_COMPILER_SUPPORTS_X86INTRIN
@@ -332,7 +332,7 @@ static __forceinline unsigned long _bit_scan_forward(uint val)
     _BitScanForward(&result, val);
     return result;
 }
-#  elif (defined(Q_CC_CLANG) || (defined(Q_CC_GNU) && __GNUC__ * 100 + __GNUC_MINOR__ < 405)) \
+#  elif (defined(Q_CC_CLANG) || (defined(Q_CC_GNU) && Q_CC_GNU < 405)) \
     && !defined(Q_CC_INTEL)
 // Clang is missing the intrinsic for _bit_scan_reverse
 // GCC only added it in version 4.5
-- 
GitLab