Fix __alloc_size__ availability detection (Clang)
authorYusuke Suzuki <utatane.tea@gmail.com>
Wed, 1 Oct 2014 18:38:02 +0000 (03:38 +0900)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 16 Oct 2014 20:15:12 +0000 (00:15 +0400)
Since __clang_major__/__clang_minor__ etc. are vendor dependent values,
we cannot implement the feature detection based on it.
For example, Apple clang versioning is different from the FreeBSD clang.
(At this time, Apple clang version is "6.0 (clang-600.0.51)" and
__clang_major__ is 6.)
Instead of this, we can use the clang feature detection macro,
__has_attribute.

* include/gc_config_macros.h (GC_ATTR_ALLOC_SIZE): Replace predefined
__clang_major/minor__ testing with __has_attribute() one (in case of
clang).

include/gc_config_macros.h

index 13f7e77..d6da7ca 100644 (file)
 #ifndef GC_ATTR_ALLOC_SIZE
   /* 'alloc_size' attribute improves __builtin_object_size correctness. */
   /* Only single-argument form of 'alloc_size' attribute is used.       */
-# if defined(__GNUC__) && (__GNUC__ > 4 \
-        || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3 && !defined(__ICC)) \
-        || __clang_major__ > 3 \
-        || (__clang_major__ == 3 && __clang_minor__ >= 2 \
-            && (__clang_minor__ != 5 || __clang_patchlevel__ != 0)))
+# ifdef __clang__
+#   if __has_attribute(__alloc_size__)
+#     define GC_ATTR_ALLOC_SIZE(argnum) __attribute__((__alloc_size__(argnum)))
+#   else
+#     define GC_ATTR_ALLOC_SIZE(argnum) /* empty */
+#   endif
+# elif __GNUC__ > 4 \
+       || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3 && !defined(__ICC))
 #   define GC_ATTR_ALLOC_SIZE(argnum) __attribute__((__alloc_size__(argnum)))
 # else
-#   define GC_ATTR_ALLOC_SIZE(argnum)
+#   define GC_ATTR_ALLOC_SIZE(argnum) /* empty */
 # endif
 #endif