]> granicus.if.org Git - gc/commitdiff
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>
Tue, 12 May 2015 08:57:37 +0000 (11:57 +0300)
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 67ed6b0ca6f3a36dd0d204a76fa07537ab7fb751..9285ddb798c5e517c233ffda46e2f297caeec6ec 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