Restore attribute alloc_size for GCC.

clang doesn't support attribute alloc_size, but GCC uses it to give
diagnostics where clang can't, and we had a test for one such case.

Bug: http://b/30513330
Change-Id: I4c14771258992d6bea684db7f91d60312642662f
diff --git a/libc/include/malloc.h b/libc/include/malloc.h
index 07d7896..7452e53 100644
--- a/libc/include/malloc.h
+++ b/libc/include/malloc.h
@@ -23,12 +23,18 @@
 
 __BEGIN_DECLS
 
-void* malloc(size_t byte_count) __mallocfunc __wur;
-void* calloc(size_t item_count, size_t item_size) __mallocfunc __wur;
-void* realloc(void* p, size_t byte_count) __wur;
+#if defined(__clang__)
+#define __BIONIC_ALLOC_SIZE(...) /* clang doesn't support attribute alloc_size. */
+#else
+#define __BIONIC_ALLOC_SIZE(...) __attribute__((__alloc_size__(__VA_ARGS__)))
+#endif
+
+void* malloc(size_t byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(1) __wur;
+void* calloc(size_t item_count, size_t item_size) __mallocfunc __BIONIC_ALLOC_SIZE(1,2) __wur;
+void* realloc(void* p, size_t byte_count) __BIONIC_ALLOC_SIZE(2) __wur;
 void free(void* p);
 
-void* memalign(size_t alignment, size_t byte_count) __mallocfunc __wur;
+void* memalign(size_t alignment, size_t byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(2) __wur;
 size_t malloc_usable_size(const void* p) __INTRODUCED_IN(17);
 
 #ifndef STRUCT_MALLINFO_DECLARED