Mark H Weaver <m...@netris.org> skribis:

> This is clearly an issue with bdwgc on clang, and possibly only on
> Apple's version of clang.  Here's the relevant section of
> gc/gc_config_macros.h from bdwgc 7.4.2:
>
> #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))
> #   define GC_ATTR_ALLOC_SIZE(argnum) __attribute__((__alloc_size__(argnum)))
> # else
> #   define GC_ATTR_ALLOC_SIZE(argnum)
> # endif
> #endif

AFAIK, Clang and ICC define __GNUC__ by default, even though they don’t
implement all the features of the corresponding GCC, which may explain
why the above doesn’t work as expected.

> You can see that the bdwgc developers have made an effort to check both
> GCC and clang version numbers before using the __alloc_size__ attribute.
> The code above seems to suggest that they believed clang 3.2 or later
> supported this attribute, whereas your version of clang seems to be
> based on upstream clang 3.5.  Perhaps Apple removed support for this
> attribute from their clang?

I think for Clang the right way would be to use the ‘__has_attribute’
magic macro:

  http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute

Ludo’.



Reply via email to