[libvirt] [PATCH] maint: turn on gcc logical-op checking

Matthias Bolte matthias.bolte at googlemail.com
Sat Jul 24 20:36:50 UTC 2010


2010/7/23 Eric Blake <eblake at redhat.com>:
> This would have detected the bug in commit 38ad33931 (Aug 09), which
> we missed until commit f828ca35 (Jul 10); over 11 months later.
>
> However, on Fedora 13, it also triggers LOTS of warnings from
> the libcurl-devel header for one file:
>
> esx/esx_vi.c: In function 'esxVI_CURL_Perform':
> esx/esx_vi.c:232: error: logical '&&' with non-zero constant will always evaluate as true [-Wlogical-op]
> esx/esx_vi.c:232: error: logical '&&' with non-zero constant will always evaluate as true [-Wlogical-op]
> esx/esx_vi.c:232: error: logical '&&' with non-zero constant will always evaluate as true [-Wlogical-op]
> ...
>
> I figure the gross hack to disable the warnings in the third-party
> code, along with the reduction in type-safety in just esx_vi.c,
> is worth the improved compiler checking throughout the rest of libvirt.
>
> * acinclude.m4 (--enable-compile-warnings=error): Add
> -Wlogical-op.
> * src/esx/esx_vi.c (includes): Hack around broken libcurl-devel
> header, to avoid compilation warning.
> Suggested by Daniel P. Berrange.
> ---
>
> In response to
>  https://www.redhat.com/archives/libvir-list/2010-July/msg00497.html
> and fixing some long lines while I was at it.
>
>  acinclude.m4     |   16 +++++++++++++---
>  src/esx/esx_vi.c |   10 ++++++++++
>  2 files changed, 23 insertions(+), 3 deletions(-)
>

> @@ -36,6 +36,16 @@
>  #include "esx_vi_methods.h"
>  #include "esx_util.h"
>
> +
> +/* XXX "esx_vi.h" includes <curl/curl.h>; as of
> + * libcurl-devel-7.20.1-3.fc13.x86_64, curl ships a version of this
> + * header that #defines several wrapper macros around underlying
> + * functions to add type safety for gcc only.  However, these macros
> + * spuriously trip gcc's -Wlogical-op warning.  Avoid the warning by
> + * nuking the wrappers; even if it removes some type-check safety.  */
> +# undef curl_easy_getinfo
> +# undef curl_easy_setopt
> +
>  #define VIR_FROM_THIS VIR_FROM_ESX

No need to hack here. We can define CURL_DISABLE_TYPECHECK to disable
those type checks.

Also the warnings are not that spuriously. If you look at
typecheck-gcc.h you'll see that the condition of the if clauses only
depend onto type information. This type information is static at
compile- and runtime, so gcc is correct to warn about them being fixed
true or false.

This also affects the XenAPI driver because it includes curl.h too.
Therefore, I suggest the attached variation of your patch.

Matthias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-maint-turn-on-gcc-logical-op-checking.diff
Type: text/x-diff
Size: 4058 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100724/75fc8244/attachment-0001.bin>


More information about the libvir-list mailing list