From 377ab2f2d781aef9408f26b24bb8b17426be6606 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Fri, 13 May 2016 13:17:02 -0700 Subject: [PATCH] util: Add ATTRIBUTE_RETURNS_NONNULL. Reviewed-by: Kenneth Graunke --- configure.ac | 1 + m4/ax_gcc_func_attribute.m4 | 7 +++++++ src/util/macros.h | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/configure.ac b/configure.ac index 023110e184c..9fbfe4d5ea4 100644 --- a/configure.ac +++ b/configure.ac @@ -224,6 +224,7 @@ AX_GCC_FUNC_ATTRIBUTE([format]) AX_GCC_FUNC_ATTRIBUTE([malloc]) AX_GCC_FUNC_ATTRIBUTE([packed]) AX_GCC_FUNC_ATTRIBUTE([pure]) +AX_GCC_FUNC_ATTRIBUTE([returns_nonnull]) AX_GCC_FUNC_ATTRIBUTE([unused]) AX_GCC_FUNC_ATTRIBUTE([warn_unused_result]) diff --git a/m4/ax_gcc_func_attribute.m4 b/m4/ax_gcc_func_attribute.m4 index 4e0ecbb56c5..2e67ea2926d 100644 --- a/m4/ax_gcc_func_attribute.m4 +++ b/m4/ax_gcc_func_attribute.m4 @@ -53,6 +53,7 @@ # optimize # packed # pure +# returns_nonnull # unused # used # visibility @@ -76,6 +77,9 @@ #serial 2 +# mattst88: +# Added support for returns_nonnull attribute + AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [ AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1]) @@ -175,6 +179,9 @@ AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [ [pure], [ int foo( void ) __attribute__(($1)); ], + [returns_nonnull], [ + int *foo( void ) __attribute__(($1)); + ], [unused], [ int foo( void ) __attribute__(($1)); ], diff --git a/src/util/macros.h b/src/util/macros.h index c0bfb15a47a..9ddf675965b 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -154,6 +154,12 @@ do { \ #define ATTRIBUTE_PURE #endif +#ifdef HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL +#define ATTRIBUTE_RETURNS_NONNULL __attribute__((__returns_nonnull__)) +#else +#define ATTRIBUTE_RETURNS_NONNULL +#endif + #ifdef __cplusplus /** * Macro function that evaluates to true if T is a trivially -- 2.30.2