]> xenbits.xensource.com Git - libvirt.git/commitdiff
build: add GCC 6.0 -Wlogical-op workaround
authorPavel Hrdina <phrdina@redhat.com>
Sun, 10 Apr 2016 16:22:20 +0000 (18:22 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 11 Apr 2016 10:09:14 +0000 (12:09 +0200)
fdstream.c: In function 'virFDStreamWrite':
fdstream.c:390:29: error: logical 'or' of equal expressions [-Werror=logical-op]
        if (errno == EAGAIN || errno == EWOULDBLOCK) {
                            ^~

Fedora rawhide now uses gcc 6.0 and there is a bug with -Wlogical-op
producing false warnings.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602

Use GCC pragma push/pop and ignore -Wlogical-op for GCC that supports
push/pop pragma and also has this bug.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
m4/virt-compile-warnings.m4
src/fdstream.c
src/internal.h
src/rpc/virnetsshsession.c
src/security/security_selinux.c

index 1b0a2cf9e3e1e0e55ba708df4275e8967b532ab0..eb689e2f88a664cdb7b9e2d9b83306731d2d2300 100644 (file)
@@ -117,6 +117,20 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
         [lv_cv_gcc_wlogical_op_broken=yes])
       CFLAGS="$save_CFLAGS"])
 
+    AC_CACHE_CHECK([whether gcc gives bogus warnings for -Wlogical-op],
+      [lv_cv_gcc_wlogical_op_equal_expr_broken], [
+        save_CFLAGS="$CFLAGS"
+        CFLAGS="-O2 -Wlogical-op -Werror"
+        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+          #define TEST1 1
+          #define TEST2 TEST1
+        ]], [[
+          int test = 0;
+          return test == TEST1 || test == TEST2;]])],
+        [lv_cv_gcc_wlogical_op_equal_expr_broken=no],
+        [lv_cv_gcc_wlogical_op_equal_expr_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"
@@ -239,4 +253,10 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
       AC_DEFINE_UNQUOTED([BROKEN_GCC_WLOGICALOP_STRCHR], 1,
        [Define to 1 if gcc -Wlogical-op reports false positives on strchr])
     fi
+
+    if test "$gl_cv_warn_c__Wlogical_op" = yes &&
+       test "$lv_cv_gcc_wlogical_op_equal_expr_broken" = yes; then
+      AC_DEFINE_UNQUOTED([BROKEN_GCC_WLOGICALOP_EQUAL_EXPR], 1,
+        [Define to 1 if gcc -Wlogical-op reports false positive 'or' equal expr])
+    fi
 ])
index a85cf9dd63217070888b283589ebe4c98dd4f448..ef118b56ec5031c4ed57e6bb20420f555dd1c2aa 100644 (file)
@@ -387,7 +387,9 @@ static int virFDStreamWrite(virStreamPtr st, const char *bytes, size_t nbytes)
  retry:
     ret = write(fdst->fd, bytes, nbytes);
     if (ret < 0) {
+        VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR
         if (errno == EAGAIN || errno == EWOULDBLOCK) {
+        VIR_WARNINGS_RESET
             ret = -2;
         } else if (errno == EINTR) {
             goto retry;
@@ -437,7 +439,9 @@ static int virFDStreamRead(virStreamPtr st, char *bytes, size_t nbytes)
  retry:
     ret = read(fdst->fd, bytes, nbytes);
     if (ret < 0) {
+        VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR
         if (errno == EAGAIN || errno == EWOULDBLOCK) {
+        VIR_WARNINGS_RESET
             ret = -2;
         } else if (errno == EINTR) {
             goto retry;
index cf86a56af1ff1d0419d1827417c85fe7403d5746..0dc34c755d63f44e76962bdaea6a62d09fea307e 100644 (file)
     _Pragma ("GCC diagnostic push")
 #  endif
 
+/* Workaround bogus GCC 6.0 for logical 'or' equal expression warnings.
+ * (GCC bz 69602) */
+#  if BROKEN_GCC_WLOGICALOP_EQUAL_EXPR
+#   define VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR            \
+     _Pragma ("GCC diagnostic push")                        \
+     _Pragma ("GCC diagnostic ignored \"-Wlogical-op\"")
+#  else
+#   define VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR            \
+     _Pragma ("GCC diagnostic push")
+#  endif
+
 #  define VIR_WARNINGS_RESET \
     _Pragma ("GCC diagnostic pop")
 # else
 #  define VIR_WARNINGS_NO_CAST_ALIGN
 #  define VIR_WARNINGS_NO_PRINTF
+#  define VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR
 #  define VIR_WARNINGS_RESET
 # endif
 
index 406a8314b5fedf25f1df7c6cf6eada2780f79771..e7421756545a6f0da566f862a652dc3114c9f5ef 100644 (file)
@@ -545,9 +545,11 @@ virNetSSHAuthenticateAgent(virNetSSHSessionPtr sess,
                                            agent_identity)))
             return 0; /* key accepted */
 
+        VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR
         if (ret != LIBSSH2_ERROR_AUTHENTICATION_FAILED &&
             ret != LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED &&
             ret != LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED) {
+        VIR_WARNINGS_RESET
             libssh2_session_last_error(sess->session, &errmsg, NULL, 0);
             virReportError(VIR_ERR_AUTH_FAILED,
                            _("failed to authenticate using SSH agent: %s"),
@@ -605,9 +607,11 @@ virNetSSHAuthenticatePrivkey(virNetSSHSessionPtr sess,
                                                    priv->password)) == 0)
         return 0; /* success */
 
+    VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR
     if (priv->password ||
         ret == LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED ||
         ret == LIBSSH2_ERROR_AUTHENTICATION_FAILED) {
+    VIR_WARNINGS_RESET
         libssh2_session_last_error(sess->session, &errmsg, NULL, 0);
         virReportError(VIR_ERR_AUTH_FAILED,
                        _("authentication with private key '%s' "
@@ -673,11 +677,13 @@ virNetSSHAuthenticatePrivkey(virNetSSHSessionPtr sess,
                          "has failed: %s"),
                        priv->filename, errmsg);
 
+        VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR
         if (ret == LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED ||
             ret == LIBSSH2_ERROR_AUTHENTICATION_FAILED)
             return 1;
         else
             return -1;
+        VIR_WARNINGS_RESET
     }
 
     return 0;
index 26d95d172064e360440c2fa7b98876a956121849..04760a1f41d100d451e8743066e7f173be19234c 100644 (file)
@@ -911,8 +911,10 @@ virSecuritySELinuxSetFileconHelper(const char *path, char *tcon,
          * hopefully sets one of the necessary SELinux virt_use_{nfs,usb,pci}
          * boolean tunables to allow it ...
          */
+        VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR
         if (setfilecon_errno != EOPNOTSUPP && setfilecon_errno != ENOTSUP &&
             setfilecon_errno != EROFS) {
+        VIR_WARNINGS_RESET
             virReportSystemError(setfilecon_errno,
                                  _("unable to set security context '%s' on '%s'"),
                                  tcon, path);