From acd26eedac09749f82646ea1ac0a662109cca7a8 Mon Sep 17 00:00:00 2001 From: Petr Spacek Date: Fri, 19 Feb 2016 13:39:27 +0100 Subject: [PATCH] Fix build with GCC 4.9+. GCC 4.9+ is too aggressive when optimizing functions with nonnull attributes. This removes most of asserts() in the plugin. GCC 6 adds warnings for these cases. We are disabling the unwanted condition pruning by adding -fno-delete-null-pointer-checks argument. BIND 9 did the same in its commit 603a78708343f063b44affb882ef93bb19a5142a. Additionally we enable nonnull attribute only when the build is running under Clang static analyzer or Coverity. https://bugzilla.redhat.com/show_bug.cgi?id=1307346 --- configure.ac | 14 ++++++++++++++ src/util.h | 8 ++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index a06708b1a5ee64bb64c80272c10ed1a35670c8d0..48f5cb63c3bb5535fe1da56abe7583e15d4b5f92 100644 --- a/configure.ac +++ b/configure.ac @@ -39,6 +39,20 @@ AC_TRY_COMPILE([ [CFLAGS="$SAVED_CFLAGS" AC_MSG_RESULT([no])]) +# Check if build chain supports -fno-delete-null-pointer-checks +# this flag avoids too agressive optimizations which would remove some asserts +# BIND 9 did the same in its commit 603a78708343f063b44affb882ef93bb19a5142a +AC_MSG_CHECKING([for -fno-delete-null-pointer-checks compiler flag]) +SAVED_CFLAGS="$CFLAGS" +CFLAGS="-fno-delete-null-pointer-checks -Werror" +AC_TRY_COMPILE([ + extern int fdef(void); +],[], +[AC_MSG_RESULT([yes]) + CFLAGS="$SAVED_CFLAGS -fno-delete-null-pointer-checks"], +[CFLAGS="$SAVED_CFLAGS" + AC_MSG_RESULT([no])]) + # Get CFLAGS from isc-config.sh AC_ARG_VAR([BIND9_CFLAGS], [C compiler flags for bind9, overriding isc-config.sh]) diff --git a/src/util.h b/src/util.h index 9849ff9b6c38ec1c6dd143440d5b5e584b2ecd51..402503c339a5ab6ca5273cae420e743b9fc252ab 100644 --- a/src/util.h +++ b/src/util.h @@ -103,11 +103,15 @@ extern isc_boolean_t verbose_checks; /* from settings.c */ /* If no argument index list is given to the nonnull attribute, * all pointer arguments are marked as non-null. */ #define ATTR_NONNULLS ATTR_NONNULL() -#ifdef __GNUC__ +#if defined(__COVERITY__) || defined(__clang_analyzer__) #define ATTR_NONNULL(...) __attribute__((nonnull(__VA_ARGS__))) -#define ATTR_CHECKRESULT __attribute__((warn_unused_result)) #else #define ATTR_NONNULL(...) +#endif + +#if defined(__GNUC__) +#define ATTR_CHECKRESULT __attribute__((warn_unused_result)) +#else #define ATTR_CHECKRESULT #endif -- 2.5.0