From 0720b100fb90a25802fe6476ab4233a6753b38c1 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Wed, 10 Jul 2024 10:53:43 +0200 Subject: [PATCH] Introduce ATTR_RETNONNULL to indicate functions that will never return NULL --- Macros.h | 10 ++++++++++ configure.ac | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Macros.h b/Macros.h index 051bedbc2..6b064abb6 100644 --- a/Macros.h +++ b/Macros.h @@ -69,6 +69,16 @@ in the source distribution for its full text. #endif /* HAVE_ATTR_NONNULL */ +#ifdef HAVE_ATTR_RETNONNULL + +#define ATTR_RETNONNULL __attribute__((returns_nonnull)) + +#else + +#define ATTR_RETNONNULL + +#endif /* HAVE_ATTR_RETNONNULL */ + #ifdef HAVE_ATTR_ALLOC_SIZE #define ATTR_ALLOC_SIZE1(a) __attribute__((alloc_size (a))) diff --git a/configure.ac b/configure.ac index e98fe4a06..b1e2e9c08 100644 --- a/configure.ac +++ b/configure.ac @@ -235,6 +235,21 @@ AC_COMPILE_IFELSE([ AC_MSG_RESULT(no)) CFLAGS="$old_CFLAGS" +AC_MSG_CHECKING(for returns_nonnull) +old_CFLAGS="$CFLAGS" +CFLAGS="$CFLAGS -Wno-error -Werror=attributes" +AC_COMPILE_IFELSE([ + AC_LANG_SOURCE( + [[ + /* Attribute supported in GCC 4.9 or later */ + __attribute__((returns_nonnull)) void* foo(void); + ]] + )], + AC_DEFINE([HAVE_ATTR_RETNONNULL], 1, [The returns_nonnull attribute is supported.]) + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) +CFLAGS="$old_CFLAGS" + AC_MSG_CHECKING(for NaN support) dnl Note: AC_RUN_IFELSE does not try compiling the program at all when dnl $cross_compiling is 'yes'.