changeset 17976:64dd75ab6054

eealloc, pagealign_alloc, xalloc: avoid clang warnings Avoid [-Wunknown-attributes] warnings like: warning: unknown attribute '__alloc_size__' ignored * lib/xalloc.h: Don't use the __alloc_size__ attribute with clang, as support has been fully removed as of clang 3.5: https://github.com/llvm-mirror/clang/commit/c047507a * lib/eealloc.h: Likewise. * lib/pagealign_alloc.h: Likewise.
author Pádraig Brady <P@draigBrady.com>
date Tue, 28 Apr 2015 22:24:45 +0100
parents e9738bb175fe
children 1a4219ef5f25
files ChangeLog lib/eealloc.h lib/pagealign_alloc.h lib/xalloc.h
diffstat 4 files changed, 43 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2015-04-28  Pádraig Brady  <P@draigBrady.com>
+
+	eealloc, pagealign_alloc, xalloc: avoid clang warnings
+	Avoid [-Wunknown-attributes] warnings like:
+	warning: unknown attribute '__alloc_size__' ignored
+	* lib/xalloc.h: Don't use the __alloc_size__  attribute
+	with clang, as support has been fully removed as of clang 3.5:
+	https://github.com/llvm-mirror/clang/commit/c047507a
+	* lib/eealloc.h: Likewise.
+	* lib/pagealign_alloc.h: Likewise.
+
 2015-04-27  Paul Eggert  <eggert@cs.ucla.edu>
 
 	tests: pacify GCC 5.1's stricter printf checking
--- a/lib/eealloc.h
+++ b/lib/eealloc.h
@@ -39,17 +39,24 @@
 # define EEALLOC_INLINE _GL_INLINE
 #endif
 
+#if __GNUC__ >= 3
+# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
+#else
+# define _GL_ATTRIBUTE_MALLOC
+#endif
+
+#if ! defined __clang__ && \
+    (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
+# define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
+#else
+# define _GL_ATTRIBUTE_ALLOC_SIZE(args)
+#endif
+
 #if MALLOC_0_IS_NONNULL
 # define eemalloc malloc
 #else
-# if __GNUC__ >= 3
 EEALLOC_INLINE void *eemalloc (size_t n)
-     __attribute__ ((__malloc__))
-#  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
-     __attribute__ ((__alloc_size__ (1)))
-#  endif
-  ;
-# endif
+     _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
 EEALLOC_INLINE void *
 eemalloc (size_t n)
 {
@@ -63,10 +70,8 @@
 #if REALLOC_0_IS_NONNULL
 # define eerealloc realloc
 #else
-# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
 EEALLOC_INLINE void *eerealloc (void *p, size_t n)
-     __attribute__ ((__alloc_size__ (2)));
-# endif
+     _GL_ATTRIBUTE_ALLOC_SIZE ((2));
 EEALLOC_INLINE void *
 eerealloc (void *p, size_t n)
 {
--- a/lib/pagealign_alloc.h
+++ b/lib/pagealign_alloc.h
@@ -20,6 +20,19 @@
 
 # include <stddef.h>
 
+#if __GNUC__ >= 3
+# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
+#else
+# define _GL_ATTRIBUTE_MALLOC
+#endif
+
+#if ! defined __clang__ && \
+    (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
+# define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
+#else
+# define _GL_ATTRIBUTE_ALLOC_SIZE(args)
+#endif
+
 /* Allocate a block of memory of SIZE bytes, aligned on a system page
    boundary.
    If SIZE is not a multiple of the system page size, it will be rounded up
@@ -27,24 +40,12 @@
    Return a pointer to the start of the memory block. Upon allocation failure,
    return NULL and set errno.  */
 extern void *pagealign_alloc (size_t size)
-# if __GNUC__ >= 3
-     __attribute__ ((__malloc__))
-#  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
-     __attribute__ ((__alloc_size__ (1)))
-#  endif
-# endif
-     ;
+     _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
 
 /* Like pagealign_alloc, except it exits the program if the allocation
    fails.  */
 extern void *pagealign_xalloc (size_t size)
-# if __GNUC__ >= 3
-     __attribute__ ((__malloc__))
-#  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
-     __attribute__ ((__alloc_size__ (1)))
-#  endif
-# endif
-     ;
+     _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
 
 /* Free a memory block.
    PTR must be a non-NULL pointer returned by pagealign_alloc or
--- a/lib/xalloc.h
+++ b/lib/xalloc.h
@@ -41,7 +41,8 @@
 # define _GL_ATTRIBUTE_MALLOC
 #endif
 
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if ! defined __clang__ && \
+    (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
 #else
 # define _GL_ATTRIBUTE_ALLOC_SIZE(args)