Gate `__returns_nonnull__` attribute to gcc 4.9 or later
authorMichael Lee <mzlee@fb.com>
Wed, 5 Oct 2016 23:15:02 +0000 (16:15 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Wed, 5 Oct 2016 23:23:31 +0000 (16:23 -0700)
Summary: The attribute `__returns_nonnull__` is only applicable for gcc 4.9 or later (https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/Function-Attributes.html#Function-Attributes)

Reviewed By: ot

Differential Revision: D3976598

fbshipit-source-id: 3c678a11c5046e5a8b7686327dbb3ebc9b598616

folly/Malloc.h

index de75e45195b573db2bdb447a384b384f279c6e7b..3aeb765c2cca357f69aa1637beea4fc46cb3fbc5 100644 (file)
@@ -124,11 +124,15 @@ namespace folly {
 // Cannot depend on Portability.h when _LIBSTDCXX_FBSTRING.
 #if defined(__GNUC__)
 #define FOLLY_MALLOC_NOINLINE __attribute__((__noinline__))
+#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL) >= 40900
 // This is for checked malloc-like functions (returns non-null pointer
 // which cannot alias any outstanding pointer).
 #define FOLLY_MALLOC_CHECKED_MALLOC                     \
   __attribute__((__returns_nonnull__, __malloc__))
 #else
+#define FOLLY_MALLOC_CHECKED_MALLOC __attribute__((__malloc__))
+#endif
+#else
 #define FOLLY_MALLOC_NOINLINE
 #define FOLLY_MALLOC_CHECKED_MALLOC
 #endif