[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/4] Require use of GCC 4.4 or CLang compilers



We only ever test libvirt with GCC or CLang which provides a
GCC compatible compilation environment. Between them, these
compilers cover every important operating system platform,
even Windows.

Mandate their use to make it explicit that we don't care about
compilers like Microsoft VCC or other UNIX vendor C compilers.

GCC 4.4 was picked as the baseline, since RHEL-6 ships 4.4.7
and that lets us remove a large set of checks. There is a slight
issue that CLang reports itself as GCC 4.2, so we must also check
if __clang__ is defined. We could check a particular CLang version
too, but that would require someone to figure out a suitable min
version which is fun because OS-X reports totally different CLang
version numbers from CLang builds on Linux/BSD

Signed-off-by: Daniel P. Berrange <berrange redhat com>
---
 config-post.h  |  20 +++++-----
 src/internal.h | 116 ++++++++++++++++-----------------------------------------
 2 files changed, 44 insertions(+), 92 deletions(-)

diff --git a/config-post.h b/config-post.h
index 75e7d02..4bddbac 100644
--- a/config-post.h
+++ b/config-post.h
@@ -74,6 +74,10 @@
 # undef WITH_CAPNG
 #endif /* LIBVIRT_NSS */
 
+#ifndef __GNUC__
+# error "Libvirt requires GCC >= 4.4, or CLang"
+#endif
+
 /*
  * Define __GNUC_PREREQ to a sane default if it isn't yet defined.
  * This is done here so that it's included as early as possible; gnulib relies
@@ -81,13 +85,11 @@
  * This doesn't happen on many non-glibc systems.
  * When __GNUC_PREREQ is not defined, gnulib defines it to 0, which breaks things.
  */
-#ifdef __GNUC__
-# ifndef __GNUC_PREREQ
-#  if defined __GNUC__ && defined __GNUC_MINOR__
-#   define __GNUC_PREREQ(maj, min)                                        \
-   ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
-#  else
-#   define __GNUC_PREREQ(maj, min) 0
-#  endif
-# endif
+#ifndef __GNUC_PREREQ
+#  define __GNUC_PREREQ(maj, min)                                        \
+  ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+#endif
+
+#if !__GNUC_PREREQ(4, 4) || defined(__clang__)
+# error "Libvirt requires GCC >= 4.4, or CLang"
 #endif
diff --git a/src/internal.h b/src/internal.h
index faf3e2b..9e2e72c 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -101,41 +101,32 @@
 # define NUL_TERMINATE(buf) do { (buf)[sizeof(buf)-1] = '\0'; } while (0)
 # define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array)))
 
-/* C99 uses __func__.  __FUNCTION__ is legacy. */
-# ifndef __GNUC__
-#  define __FUNCTION__ __func__
-# endif
-
 /**
  * ATTRIBUTE_UNUSED:
  *
  * Macro to flag consciously unused parameters to functions
  */
-#  ifndef ATTRIBUTE_UNUSED
-#   define ATTRIBUTE_UNUSED __attribute__((__unused__))
-#  endif
+# ifndef ATTRIBUTE_UNUSED
+#  define ATTRIBUTE_UNUSED __attribute__((__unused__))
+# endif
 
 /**
  * ATTRIBUTE_NORETURN:
  *
  * Macro to indicate that a function won't return to the caller
  */
-#  ifndef ATTRIBUTE_NORETURN
-#   define ATTRIBUTE_NORETURN __attribute__((__noreturn__))
-#  endif
+# ifndef ATTRIBUTE_NORETURN
+#  define ATTRIBUTE_NORETURN __attribute__((__noreturn__))
+# endif
 
 /**
  * ATTRIBUTE_SENTINEL:
  *
  * Macro to check for NULL-terminated varargs lists
  */
-#  ifndef ATTRIBUTE_SENTINEL
-#   if __GNUC_PREREQ (4, 0)
-#    define ATTRIBUTE_SENTINEL __attribute__((__sentinel__))
-#   else
-#    define ATTRIBUTE_SENTINEL
-#   endif
-#  endif
+# ifndef ATTRIBUTE_SENTINEL
+#  define ATTRIBUTE_SENTINEL __attribute__((__sentinel__))
+# endif
 
 /**
  * ATTRIBUTE_NOINLINE:
@@ -143,13 +134,9 @@
  * Force compiler not to inline a method. Should be used if
  * the method need to be overridable by test mocks.
  */
-#  ifndef ATTRIBUTE_NOINLINE
-#   if __GNUC_PREREQ (4, 0)
-#    define ATTRIBUTE_NOINLINE __attribute__((__noinline__))
-#   else
-#    define ATTRIBUTE_NOINLINE
-#   endif
-#  endif
+# ifndef ATTRIBUTE_NOINLINE
+#  define ATTRIBUTE_NOINLINE __attribute__((__noinline__))
+# endif
 
 /**
  * ATTRIBUTE_FMT_PRINTF
@@ -161,23 +148,14 @@
  * printf format specifiers even on broken Win32 platforms
  * hence we have to force 'gnu_printf' for new GCC
  */
-#  ifndef ATTRIBUTE_FMT_PRINTF
-#   if __GNUC_PREREQ (4, 4)
-#    define ATTRIBUTE_FMT_PRINTF(fmtpos, argpos) \
-    __attribute__((__format__ (__gnu_printf__, fmtpos, argpos)))
-#   else
-#    define ATTRIBUTE_FMT_PRINTF(fmtpos, argpos) \
-    __attribute__((__format__ (__printf__, fmtpos, argpos)))
-#   endif
-#  endif
+# ifndef ATTRIBUTE_FMT_PRINTF
+#  define ATTRIBUTE_FMT_PRINTF(fmtpos, argpos) \
+     __attribute__((__format__ (__gnu_printf__, fmtpos, argpos)))
+# endif
 
-#  ifndef ATTRIBUTE_RETURN_CHECK
-#   if __GNUC_PREREQ (3, 4)
-#    define ATTRIBUTE_RETURN_CHECK __attribute__((__warn_unused_result__))
-#   else
-#    define ATTRIBUTE_RETURN_CHECK
-#   endif
-#  endif
+# ifndef ATTRIBUTE_RETURN_CHECK
+#  define ATTRIBUTE_RETURN_CHECK __attribute__((__warn_unused_result__))
+# endif
 
 /**
  * ATTRIBUTE_PACKED
@@ -188,13 +166,9 @@
  * ethernet packets.
  * Others compiler than gcc may use something different e.g. #pragma pack(1)
  */
-#  ifndef ATTRIBUTE_PACKED
-#   if __GNUC_PREREQ (3, 3)
-#    define ATTRIBUTE_PACKED __attribute__((packed))
-#   else
-#    error "Need an __attribute__((packed)) equivalent"
-#   endif
-#  endif
+# ifndef ATTRIBUTE_PACKED
+#  define ATTRIBUTE_PACKED __attribute__((packed))
+# endif
 
 /* gcc's handling of attribute nonnull is less than stellar - it does
  * NOT improve diagnostics, and merely allows gcc to optimize away
@@ -205,45 +179,21 @@
  * based on whether we are compiling for real or for analysis, while
  * still requiring correct gcc syntax when it is turned off.  See also
  * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17308 */
-#  ifndef ATTRIBUTE_NONNULL
-#   if __GNUC_PREREQ (3, 3)
-#    if STATIC_ANALYSIS
-#     define ATTRIBUTE_NONNULL(m) __attribute__((__nonnull__(m)))
-#    else
-#     define ATTRIBUTE_NONNULL(m) __attribute__(())
-#    endif
-#   else
-#    define ATTRIBUTE_NONNULL(m)
-#   endif
-#  endif
-
-#  ifndef ATTRIBUTE_FALLTHROUGH
-#   if __GNUC_PREREQ (7, 0)
-#    define ATTRIBUTE_FALLTHROUGH __attribute__((fallthrough))
-#   else
-#    define ATTRIBUTE_FALLTHROUGH do {} while(0)
-#   endif
+# ifndef ATTRIBUTE_NONNULL
+#  if STATIC_ANALYSIS
+#   define ATTRIBUTE_NONNULL(m) __attribute__((__nonnull__(m)))
+#  else
+#   define ATTRIBUTE_NONNULL(m) __attribute__(())
 #  endif
+# endif
 
-# else
-#  ifndef ATTRIBUTE_UNUSED
-#   define ATTRIBUTE_UNUSED
-#  endif
-#  ifndef ATTRIBUTE_FMT_PRINTF
-#   define ATTRIBUTE_FMT_PRINTF(...)
-#  endif
-#  ifndef ATTRIBUTE_RETURN_CHECK
-#   define ATTRIBUTE_RETURN_CHECK
-#  endif
-#  ifndef ATTRIBUTE_NOINLINE
-#   define ATTRIBUTE_NOINLINE
-#  endif
-#
-#  ifndef ATTRIBUTE_FALLTHROUGH
+# ifndef ATTRIBUTE_FALLTHROUGH
+#  if __GNUC_PREREQ (7, 0)
+#   define ATTRIBUTE_FALLTHROUGH __attribute__((fallthrough))
+#  else
 #   define ATTRIBUTE_FALLTHROUGH do {} while(0)
 #  endif
-# endif				/* __GNUC__ */
-
+# endif
 
 # if WORKING_PRAGMA_PUSH
 #  define VIR_WARNINGS_NO_CAST_ALIGN \
-- 
2.9.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]