[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] build: make broken -Wlogical-op test be gcc-only



Commit 8b8fcdea introduced a check for broken gcc -Wlogical-op,
but did not guard the check against non-gcc compilers, which might
lead to spurious failures when another compiler encounters an
unknown pragma.  Additionally, all of our compiler warning logic
should belong in a single file, and use cache variables to allow
overriding the decision at configure time if necessary.

* configure.ac (BROKEN_GCC_WLOGICALOP): Move...
* m4/virt-compile-warnings.m4 (LIBVIRT_COMPILE_WARNINGS): ...here,
and update to modern autoconf idioms.
---

Fixes the issues mentioned here:
https://www.redhat.com/archives/libvir-list/2012-December/msg01197.html
https://www.redhat.com/archives/libvir-list/2012-December/msg01211.html

 configure.ac                | 23 -----------------------
 m4/virt-compile-warnings.m4 | 22 ++++++++++++++++++++++
 2 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/configure.ac b/configure.ac
index 20caa92..3c97e4f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -255,29 +255,6 @@ AC_CHECK_TYPE([struct ifreq],
         #include <net/if.h>
   ]])

-dnl Check whether strchr(s, char variable) causes a bogus compile warning
-dnl which is the case with a certain range of GCC versions
-AC_MSG_CHECKING([whether GCC -Wlogical-op is broken])
-
-save_CFLAGS="$CFLAGS"
-CFLAGS="-O2 -Wlogical-op -Werror"
-
-AC_TRY_COMPILE([#include <string.h>],
-                [const char *haystack;
-                 char needle;
-                 return strchr(haystack, needle) == haystack;],
-                [gcc_false_strchr_warning=no],
-                [gcc_false_strchr_warning=yes])
-
-CFLAGS="$save_CFLAGS"
-
-if test "x$gcc_false_strchr_warning" = xyes; then
-  AC_DEFINE_UNQUOTED([BROKEN_GCC_WLOGICALOP], 1,
-                       [GCC -Wlogical-op is reporting false positive on strchr])
-fi
-
-AC_MSG_RESULT([$gcc_false_strchr_warning])
-
 dnl Our only use of libtasn1.h is in the testsuite, and can be skipped
 dnl if the header is not present.  Assume -ltasn1 is present if the
 dnl header could be found.
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index 4a0f289..a08fcac 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4
@@ -95,6 +95,22 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
       dontwarn="$dontwarn -Wmissing-declarations"
     fi

+    dnl Check whether strchr(s, char variable) causes a bogus compile
+    dnl warning, which is the case with GCC < 4.6 on some glibc
+    AC_CACHE_CHECK([whether GCC -Wlogical-op gives bogus warnings],
+      [lv_cv_gcc_wlogical_op_broken], [
+      save_CFLAGS="$CFLAGS"
+      CFLAGS="-O2 -Wlogical-op -Werror"
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+        #include <string.h>
+        ]], [[
+        const char *haystack;
+        char needle;
+        return strchr(haystack, needle) == haystack;]])],
+        [lv_cv_gcc_wlogical_op_broken=no],
+        [lv_cv_gcc_wlogical_op_broken=yes])
+      CFLAGS="$save_CFLAGS"])
+
     # We might fundamentally need some of these disabled forever, but
     # ideally we'd turn many of them on
     dontwarn="$dontwarn -Wfloat-equal"
@@ -196,4 +212,10 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
     WARN_PYTHON_CFLAGS=$WARN_CFLAGS
     AC_SUBST(WARN_PYTHON_CFLAGS)
     WARN_CFLAGS=$save_WARN_CFLAGS
+
+    if test "$gl_cv_warn_c__Wlogical_op" = yes &&
+       test "$lv_cv_gcc_wlogical_op_broken" = yes; then
+      AC_DEFINE_UNQUOTED([BROKEN_GCC_WLOGICALOP], 1,
+       [Define to 1 if gcc -Wlogical-op reports false positives on strchr])
+    fi
 ])
-- 
1.8.0.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]