autoconf: attribute type checks 63/12963/5
authorMichael Meffie <mmeffie@sinenomine.net>
Sat, 17 Mar 2018 00:51:42 +0000 (20:51 -0400)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 10 Aug 2018 13:28:43 +0000 (09:28 -0400)
Check for function attributes by type and update src/afs/stds.h to
conditionally include the attributes detected, instead of checking for
specific compilers and compiler versions.

This allows attributes to be used when building under Solaris Studio.

Change-Id: I8a4dbc1b2cb6032d28176349481085bf6deb309c
Reviewed-on: https://gerrit.openafs.org/12963
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

src/cf/c-attribute.m4
src/config/stds.h

index be339a8..61b9410 100644 (file)
@@ -8,7 +8,11 @@ dnl printf-like arguments. This is the only use of function attributes in
 dnl roken.  The HAVE___ATTRIBUTE__ symbol is not used in the OpenAFS code.
 dnl
 AC_DEFUN([OPENAFS_C_ATTRIBUTE], [
+  AX_GCC_FUNC_ATTRIBUTE([always_inline])
   AX_GCC_FUNC_ATTRIBUTE([format])
+  AX_GCC_FUNC_ATTRIBUTE([nonnull])
+  AX_GCC_FUNC_ATTRIBUTE([noreturn])
+  AX_GCC_FUNC_ATTRIBUTE([unused])
 
   AS_IF([test "$ax_cv_have_func_attribute_format" = "yes"], [
     AC_DEFINE([HAVE___ATTRIBUTE__], [1],
index 0185623..8f04c9b 100644 (file)
@@ -275,7 +275,8 @@ typedef struct afsUUID afsUUID;
 #elif defined(AFS_SGI_ENV) || defined(AFS_USR_SGI_ENV)
 #define static_inline static
 #define hdr_static_inline(x) x
-#elif defined(AFS_NBSD_ENV) && !defined(AFS_NBSD50_ENV)
+#elif defined(AFS_NBSD_ENV) && !defined(AFS_NBSD50_ENV) \
+      && defined(HAVE_FUNC_ATTRIBUTE_ALWAYS_INLINE)
 #define static_inline static __inline __attribute__((always_inline))
 #define hdr_static_inline(x) static __inline __attribute__((always_inline)) x
 #else
@@ -299,21 +300,28 @@ hdr_static_inline(unsigned long long) afs_printable_uint64_lu(afs_uint64 d) { re
 #define afs_int_to_pointer(i)      ((void *)  (i))
 #endif
 
-#if defined(__GNUC__) && __GNUC__ > 2
-#define AFS_UNUSED __attribute__((unused))
-#define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y)))
-#define AFS_NORETURN __attribute__((__noreturn__))
-#define AFS_NONNULL(x) __attribute__((__nonnull__ x))
-#elif defined (__clang__)
-#define AFS_UNUSED __attribute__((unused))
-#define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y)))
-#define AFS_NORETURN __attribute__((__noreturn__))
-#define AFS_NONNULL(x) __attribute__((__nonnull__ x))
+#ifdef HAVE_FUNC_ATTRIBUTE_UNUSED
+# define AFS_UNUSED __attribute__((unused))
 #else
-#define AFS_UNUSED
-#define AFS_ATTRIBUTE_FORMAT(style,x,y)
-#define AFS_NORETURN
-#define AFS_NONNULL(x)
+# define AFS_UNUSED
+#endif
+
+#ifdef HAVE_FUNC_ATTRIBUTE_FORMAT
+# define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y)))
+#else
+# define AFS_ATTRIBUTE_FORMAT(style,x,y)
+#endif
+
+#ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
+# define AFS_NORETURN __attribute__((__noreturn__))
+#else
+# define AFS_NORETURN
+#endif
+
+#ifdef HAVE_FUNC_ATTRIBUTE_NONNULL
+# define AFS_NONNULL(x) __attribute__((__nonnull__ x))
+#else
+# define AFS_NONNULL(x)
 #endif
 
 /*