Add two-argument alloc_size attribute to calloc_explicitly_typed (GCC)
authorIvan Maidanski <ivmai@mail.ru>
Fri, 20 Oct 2017 18:54:06 +0000 (21:54 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 20 Oct 2017 18:54:06 +0000 (21:54 +0300)
* include/gc_config_macros.h [!GC_ATTR_CALLOC_SIZE]
(GC_ATTR_CALLOC_SIZE): New macro (which uses alloc_size attribute
if GCC or Clang).
* include/gc_typed.h (GC_calloc_explicitly_typed): Add
GC_ATTR_CALLOC_SIZE(1,2) attribute.

include/gc_config_macros.h
include/gc_typed.h

index 38752d6..f99a11f 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.       */
+# undef GC_ATTR_CALLOC_SIZE
 # ifdef __clang__
 #   if __has_attribute(__alloc_size__)
 #     define GC_ATTR_ALLOC_SIZE(argnum) __attribute__((__alloc_size__(argnum)))
+#     define GC_ATTR_CALLOC_SIZE(n, s) __attribute__((__alloc_size__(n, s)))
 #   else
 #     define GC_ATTR_ALLOC_SIZE(argnum) /* empty */
 #   endif
 # elif GC_GNUC_PREREQ(4, 3) && !defined(__ICC)
 #   define GC_ATTR_ALLOC_SIZE(argnum) __attribute__((__alloc_size__(argnum)))
+#   define GC_ATTR_CALLOC_SIZE(n, s) __attribute__((__alloc_size__(n, s)))
 # else
 #   define GC_ATTR_ALLOC_SIZE(argnum) /* empty */
 # endif
 #endif
 
+#ifndef GC_ATTR_CALLOC_SIZE
+# define GC_ATTR_CALLOC_SIZE(n, s) /* empty */
+#endif
+
 #ifndef GC_ATTR_NONNULL
 # if GC_GNUC_PREREQ(4, 0)
 #   define GC_ATTR_NONNULL(argnum) __attribute__((__nonnull__(argnum)))
index 06e8261..8b1e92f 100644 (file)
@@ -90,7 +90,7 @@ GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void * GC_CALL
         GC_malloc_explicitly_typed_ignore_off_page(size_t /* size_in_bytes */,
                                                    GC_descr /* d */);
 
-GC_API GC_ATTR_MALLOC void * GC_CALL
+GC_API GC_ATTR_MALLOC GC_ATTR_CALLOC_SIZE(1, 2) void * GC_CALL
         GC_calloc_explicitly_typed(size_t /* nelements */,
                                    size_t /* element_size_in_bytes */,
                                    GC_descr /* d */);