Re: [libvirt] Compiler warnings

2011-10-18 Thread Wen Congyang

On 10/18/2011 10:02 AM, Wen Congyang wrote:

At 10/18/2011 01:03 AM, Eric Blake Write:

On 10/17/2011 10:17 AM, Alex Jia wrote:

Eric,
It's latest libvirt upstream, current commit id is commit 0a71c79.

# rpm -q glibc
glibc-2.12-1.42.el6.x86_64




430 if (strchr(toescape, *cur))



  CC libvirt_util_la-buf.lo
util/buf.c: In function 'virBufferEscape':
util/buf.c:430: warning: logical '' with non-zero constant will
always
evaluate as true [-Wlogical-op]


Something's screwy.  There's no  in that line, unless strchr() is a
macro based on your particular compilation flags.  I'm suspecting that
this is a case of -D_FORTIFY_SOURCE going awry.  I don't see how this
could possibly be a libvirt issue; more likely, it is an issue with the
choice of compiler flags you are using, coupled with an issue in the
system headers causing the preprocessor to expand strchr() into
something that tickles a spurious gcc warning.



Yes, strchr() is a macro, I use -E, and get the following:

 while (*cur != 0) {
 if ((__extension__ (__builtin_constant_p (*cur)  !__builtin_constant_p 
(toescape)  (*cur) == '\0' ? (char *) __rawmemchr (toescape, *cur) : __builtin_strchr 
(toescape, *cur
 *out++ = '\\';
 *out++ = *cur;
 cur++;
 }
 *out = 0;


I reproduce this problem on RHEL6.

Hmm, I test it on Fedora15, and the problem does not happen.
I check the output with -E, and the macro strchr()'s expansion
is the same as its expansion on RHEL6.

I think it maybe gcc's problem.

Thanks
Wen Congyang



Thanks
Wen Congyang

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Compiler warnings

2011-10-18 Thread Wen Congyang

On 10/17/2011 11:35 PM, Alex Jia wrote:

Hi all,
I meet the following compiler warnings today:
..
   CC libvirt_util_la-buf.lo
util/buf.c: In function 'virBufferEscape':
util/buf.c:430: warning: logical '' with non-zero constant will always
evaluate as true [-Wlogical-op]
   CC libvirt_util_la-command.lo
..
   CC libvirt_lxc-buf.o
util/buf.c: In function 'virBufferEscape':
util/buf.c:430: warning: logical '' with non-zero constant will always
evaluate as true [-Wlogical-op]
   CC libvirt_lxc-command.o
..

Has anybody the same experience?


I meet another warnings, but it does not break the buildings:

  CCLD   libvirt_driver_remote.la
  CCLD   libvirt.la
  CCLD   libvirt_test.la

*** Warning: Linking the shared library libvirt_test.la against the 
non-libtool

*** objects  probes.o is not portable!

*** Warning: Linking the shared library libvirt.la against the non-libtool
*** objects  probes.o is not portable!
  CCLD   libvirt-qemu.la
make[3]: Leaving directory `/home/wency/rpmbuild/BUILD/libvirt-0.9.6/src'

Thanks
Wen Congyang



Thanks,
Alex


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Compiler warnings

2011-10-18 Thread Eric Blake

On 10/18/2011 07:21 AM, Wen Congyang wrote:

I meet another warnings, but it does not break the buildings:

CCLD libvirt_driver_remote.la
CCLD libvirt.la
CCLD libvirt_test.la

*** Warning: Linking the shared library libvirt_test.la against the
non-libtool
*** objects probes.o is not portable!


Yes, that warning is present if you are compiling on Linux and have the 
dtrace tool enabled for systemtap probe points.  It is harmless, because 
we aren't trying to link against probes.o on any platform except Linux, 
but we have no way to tell libtool to shut up.  It would only be worth 
worrying about if we tried to use probes.o on other platforms.


--
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Compiler warnings

2011-10-17 Thread Eric Blake

On 10/17/2011 09:35 AM, Alex Jia wrote:

Hi all,
I meet the following compiler warnings today:
..
   CC libvirt_util_la-buf.lo
util/buf.c: In function 'virBufferEscape':
util/buf.c:430: warning: logical '' with non-zero constant will always
evaluate as true [-Wlogical-op]


Which version of gcc?



Has anybody the same experience?


Not with gcc 4.5.1 (Fedora 14), but not the first time that newer gcc 
has become smarter.  I'll patch it if I can reproduce it (I'll try a 
rawhide build shortly).


--
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Compiler warnings

2011-10-17 Thread Alex Jia
Eric,
# rpm -q gcc
gcc-4.4.6-3.el6.x86_64

Regards,
Alex

- Original Message -
From: Eric Blake ebl...@redhat.com
To: Alex Jia a...@redhat.com
Cc: libvir-list@redhat.com
Sent: Monday, October 17, 2011 11:38:50 PM
Subject: Re: [libvirt]  Compiler warnings

On 10/17/2011 09:35 AM, Alex Jia wrote:
 Hi all,
 I meet the following compiler warnings today:
 ..
CC libvirt_util_la-buf.lo
 util/buf.c: In function 'virBufferEscape':
 util/buf.c:430: warning: logical '' with non-zero constant will always
 evaluate as true [-Wlogical-op]

Which version of gcc?


 Has anybody the same experience?

Not with gcc 4.5.1 (Fedora 14), but not the first time that newer gcc 
has become smarter.  I'll patch it if I can reproduce it (I'll try a 
rawhide build shortly).

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Compiler warnings

2011-10-17 Thread Eric Blake

On 10/17/2011 09:51 AM, Alex Jia wrote:

Eric,
# rpm -q gcc
gcc-4.4.6-3.el6.x86_64


I'm still not seeing it on my RHEL 6 host.  What version of glibc (in 
case it's a header problem), and is this the latest libvirt.git or a 
particular source rpm rebuild?  What's on line 430 of the file in question?



CC libvirt_util_la-buf.lo
util/buf.c: In function 'virBufferEscape':
util/buf.c:430: warning: logical '' with non-zero constant will always
evaluate as true [-Wlogical-op]


--
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Compiler warnings

2011-10-17 Thread Alex Jia
Eric,
It's latest libvirt upstream, current commit id is commit 0a71c79.

# rpm -q glibc
glibc-2.12-1.42.el6.x86_64

399 void
400 virBufferEscape(const virBufferPtr buf,
401 const char *toescape,
402 const char *format,
403 const char *str)
404 {
.

427 cur = str;
428 out = escaped;
429 while (*cur != 0) {
430 if (strchr(toescape, *cur))
431 *out++ = '\\';
432 *out++ = *cur;
433 cur++;
434 }

..


Regards,
Alex



- Original Message -
From: Eric Blake ebl...@redhat.com
To: Alex Jia a...@redhat.com
Cc: libvir-list@redhat.com
Sent: Tuesday, October 18, 2011 12:11:19 AM
Subject: Re: [libvirt]  Compiler warnings

On 10/17/2011 09:51 AM, Alex Jia wrote:
 Eric,
 # rpm -q gcc
 gcc-4.4.6-3.el6.x86_64

I'm still not seeing it on my RHEL 6 host.  What version of glibc (in 
case it's a header problem), and is this the latest libvirt.git or a 
particular source rpm rebuild?  What's on line 430 of the file in question?

 CC libvirt_util_la-buf.lo
 util/buf.c: In function 'virBufferEscape':
 util/buf.c:430: warning: logical '' with non-zero constant will always
 evaluate as true [-Wlogical-op]

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Compiler warnings

2011-10-17 Thread Eric Blake

On 10/17/2011 11:03 AM, Eric Blake wrote:

On 10/17/2011 10:17 AM, Alex Jia wrote:

Eric,
It's latest libvirt upstream, current commit id is commit 0a71c79.

# rpm -q glibc
glibc-2.12-1.42.el6.x86_64




430 if (strchr(toescape, *cur))



CC libvirt_util_la-buf.lo
util/buf.c: In function 'virBufferEscape':
util/buf.c:430: warning: logical '' with non-zero constant will
always
evaluate as true [-Wlogical-op]


Something's screwy. There's no  in that line, unless strchr() is a
macro based on your particular compilation flags. I'm suspecting that
this is a case of -D_FORTIFY_SOURCE going awry. I don't see how this
could possibly be a libvirt issue; more likely, it is an issue with the
choice of compiler flags you are using, coupled with an issue in the
system headers causing the preprocessor to expand strchr() into
something that tickles a spurious gcc warning.


Just to make sure, could you show 'make V=1' output, so we know exactly 
which compiler flags are in effect?


--
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Compiler warnings

2011-10-17 Thread Eric Blake

On 10/17/2011 10:17 AM, Alex Jia wrote:

Eric,
It's latest libvirt upstream, current commit id is commit 0a71c79.

# rpm -q glibc
glibc-2.12-1.42.el6.x86_64




430 if (strchr(toescape, *cur))



 CC libvirt_util_la-buf.lo
util/buf.c: In function 'virBufferEscape':
util/buf.c:430: warning: logical '' with non-zero constant will always
evaluate as true [-Wlogical-op]


Something's screwy.  There's no  in that line, unless strchr() is a 
macro based on your particular compilation flags.  I'm suspecting that 
this is a case of -D_FORTIFY_SOURCE going awry.  I don't see how this 
could possibly be a libvirt issue; more likely, it is an issue with the 
choice of compiler flags you are using, coupled with an issue in the 
system headers causing the preprocessor to expand strchr() into 
something that tickles a spurious gcc warning.


--
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



Re: [libvirt] Compiler warnings

2011-10-17 Thread Wen Congyang
At 10/18/2011 01:04 AM, Eric Blake Write:
 On 10/17/2011 11:03 AM, Eric Blake wrote:
 On 10/17/2011 10:17 AM, Alex Jia wrote:
 Eric,
 It's latest libvirt upstream, current commit id is commit 0a71c79.

 # rpm -q glibc
 glibc-2.12-1.42.el6.x86_64


 430 if (strchr(toescape, *cur))

 CC libvirt_util_la-buf.lo
 util/buf.c: In function 'virBufferEscape':
 util/buf.c:430: warning: logical '' with non-zero constant will
 always
 evaluate as true [-Wlogical-op]

 Something's screwy. There's no  in that line, unless strchr() is a
 macro based on your particular compilation flags. I'm suspecting that
 this is a case of -D_FORTIFY_SOURCE going awry. I don't see how this
 could possibly be a libvirt issue; more likely, it is an issue with the
 choice of compiler flags you are using, coupled with an issue in the
 system headers causing the preprocessor to expand strchr() into
 something that tickles a spurious gcc warning.
 
 Just to make sure, could you show 'make V=1' output, so we know exactly
 which compiler flags are in effect?
 

I can reproduce this problem, here is 'make V=1' output:

=
make[3]: Entering directory `/root/rpmbuild/BUILD/libvirt-0.9.6/src'
/bin/sh ../libtool  --tag=CC   --mode=compile gcc -std=gnu99 -DHAVE_CONFIG_H 
-I. -I.. -I../gnulib/lib -I../gnulib/lib -I../include -I../src/util 
-I../include -DIN_LIBVIRT-I/usr/include/libxml2   -Wall -W -Wformat-y2k 
-Wformat-security -Winit-self -Wmissing-include-dirs -Wunused -Wunknown-pragmas 
-Wstrict-aliasing -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align 
-Wwrite-strings -Wlogical-op -Waggregate-return -Wstrict-prototypes 
-Wold-style-definition -Wmissing-prototypes -Wmissing-declarations 
-Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls 
-Wnested-externs -Winline -Winvalid-pch -Wvolatile-register-var 
-Wdisabled-optimization -Wbuiltin-macro-redefined -Wmudflap 
-Wpacked-bitfield-compat -Wsync-nand -Wattributes -Wcoverage-mismatch 
-Wmultichar -Wno-missing-field-initializers -Wno-sign-compare 
-Wframe-larger-than=4096 -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-all 
--param=ssp-buffer-size=4 -fexceptions -fasynchronous-unwind-tables 
-fdiagnostics-s
how-option -funit-at-a-time -Werror  -O2 -g -pipe -Wall 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m64 -mtune=generic -MT libvirt_util_la-buf.lo -MD 
-MP -MF .deps/libvirt_util_la-buf.Tpo -c -o libvirt_util_la-buf.lo `test -f 
'util/buf.c' || echo './'`util/buf.c
libtool: compile:  gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I.. -I../gnulib/lib 
-I../gnulib/lib -I../include -I../src/util -I../include -DIN_LIBVIRT 
-I/usr/include/libxml2 -Wall -W -Wformat-y2k -Wformat-security -Winit-self 
-Wmissing-include-dirs -Wunused -Wunknown-pragmas -Wstrict-aliasing -Wshadow 
-Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wlogical-op 
-Waggregate-return -Wstrict-prototypes -Wold-style-definition 
-Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn 
-Wmissing-format-attribute -Wredundant-decls -Wnested-externs -Winline 
-Winvalid-pch -Wvolatile-register-var -Wdisabled-optimization 
-Wbuiltin-macro-redefined -Wmudflap -Wpacked-bitfield-compat -Wsync-nand 
-Wattributes -Wcoverage-mismatch -Wmultichar -Wno-missing-field-initializers 
-Wno-sign-compare -Wframe-larger-than=4096 -Wp,-D_FORTIFY_SOURCE=2 
-fstack-protector-all --param=ssp-buffer-size=4 -fexceptions 
-fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time -Werror 
-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m64 -mtune=generic -MT libvirt_util_la-buf.lo -MD 
-MP -MF .deps/libvirt_util_la-buf.Tpo -c util/buf.c  -fPIC -DPIC -o 
.libs/libvirt_util_la-buf.o
cc1: warnings being treated as errors
util/buf.c: In function 'virBufferEscape':
util/buf.c:430: error: logical '' with non-zero constant will always evaluate 
as true [-Wlogical-op]
make[3]: *** [libvirt_util_la-buf.lo] Error 1
=

If I remove -O2, I can build util/buf.c.

I am still investigating this problem.

Thanks
Wen Congyang

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Compiler warnings

2011-10-17 Thread Wen Congyang
At 10/18/2011 01:03 AM, Eric Blake Write:
 On 10/17/2011 10:17 AM, Alex Jia wrote:
 Eric,
 It's latest libvirt upstream, current commit id is commit 0a71c79.

 # rpm -q glibc
 glibc-2.12-1.42.el6.x86_64

 
 430 if (strchr(toescape, *cur))
 
  CC libvirt_util_la-buf.lo
 util/buf.c: In function 'virBufferEscape':
 util/buf.c:430: warning: logical '' with non-zero constant will
 always
 evaluate as true [-Wlogical-op]
 
 Something's screwy.  There's no  in that line, unless strchr() is a
 macro based on your particular compilation flags.  I'm suspecting that
 this is a case of -D_FORTIFY_SOURCE going awry.  I don't see how this
 could possibly be a libvirt issue; more likely, it is an issue with the
 choice of compiler flags you are using, coupled with an issue in the
 system headers causing the preprocessor to expand strchr() into
 something that tickles a spurious gcc warning.
 

Yes, strchr() is a macro, I use -E, and get the following:

while (*cur != 0) {
if ((__extension__ (__builtin_constant_p (*cur)  
!__builtin_constant_p (toescape)  (*cur) == '\0' ? (char *) __rawmemchr 
(toescape, *cur) : __builtin_strchr (toescape, *cur
*out++ = '\\';
*out++ = *cur;
cur++;
}
*out = 0;

Thanks
Wen Congyang

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Compiler warnings

2011-10-17 Thread Wen Congyang
At 10/18/2011 09:32 AM, Wen Congyang Write:
 At 10/18/2011 01:04 AM, Eric Blake Write:
 On 10/17/2011 11:03 AM, Eric Blake wrote:
 On 10/17/2011 10:17 AM, Alex Jia wrote:
 Eric,
 It's latest libvirt upstream, current commit id is commit 0a71c79.

 # rpm -q glibc
 glibc-2.12-1.42.el6.x86_64


 430 if (strchr(toescape, *cur))

 CC libvirt_util_la-buf.lo
 util/buf.c: In function 'virBufferEscape':
 util/buf.c:430: warning: logical '' with non-zero constant will
 always
 evaluate as true [-Wlogical-op]

 Something's screwy. There's no  in that line, unless strchr() is a
 macro based on your particular compilation flags. I'm suspecting that
 this is a case of -D_FORTIFY_SOURCE going awry. I don't see how this
 could possibly be a libvirt issue; more likely, it is an issue with the
 choice of compiler flags you are using, coupled with an issue in the
 system headers causing the preprocessor to expand strchr() into
 something that tickles a spurious gcc warning.

 Just to make sure, could you show 'make V=1' output, so we know exactly
 which compiler flags are in effect?

 
 I can reproduce this problem, here is 'make V=1' output:
 
 =
 make[3]: Entering directory `/root/rpmbuild/BUILD/libvirt-0.9.6/src'
 /bin/sh ../libtool  --tag=CC   --mode=compile gcc -std=gnu99 -DHAVE_CONFIG_H 
 -I. -I.. -I../gnulib/lib -I../gnulib/lib -I../include -I../src/util 
 -I../include -DIN_LIBVIRT-I/usr/include/libxml2   -Wall -W 
 -Wformat-y2k -Wformat-security -Winit-self -Wmissing-include-dirs -Wunused 
 -Wunknown-pragmas -Wstrict-aliasing -Wshadow -Wpointer-arith 
 -Wbad-function-cast -Wcast-align -Wwrite-strings -Wlogical-op 
 -Waggregate-return -Wstrict-prototypes -Wold-style-definition 
 -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn 
 -Wmissing-format-attribute -Wredundant-decls -Wnested-externs -Winline 
 -Winvalid-pch -Wvolatile-register-var -Wdisabled-optimization 
 -Wbuiltin-macro-redefined -Wmudflap -Wpacked-bitfield-compat -Wsync-nand 
 -Wattributes -Wcoverage-mismatch -Wmultichar -Wno-missing-field-initializers 
 -Wno-sign-compare -Wframe-larger-than=4096 -Wp,-D_FORTIFY_SOURCE=2 
 -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions 
 -fasynchronous-unwind-tables -fdiagnostics
-s
 how-option -funit-at-a-time -Werror  -O2 -g -pipe -Wall 
 -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
 --param=ssp-buffer-size=4 -m64 -mtune=generic -MT libvirt_util_la-buf.lo -MD 
 -MP -MF .deps/libvirt_util_la-buf.Tpo -c -o libvirt_util_la-buf.lo `test -f 
 'util/buf.c' || echo './'`util/buf.c
 libtool: compile:  gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I.. -I../gnulib/lib 
 -I../gnulib/lib -I../include -I../src/util -I../include -DIN_LIBVIRT 
 -I/usr/include/libxml2 -Wall -W -Wformat-y2k -Wformat-security -Winit-self 
 -Wmissing-include-dirs -Wunused -Wunknown-pragmas -Wstrict-aliasing -Wshadow 
 -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wlogical-op 
 -Waggregate-return -Wstrict-prototypes -Wold-style-definition 
 -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn 
 -Wmissing-format-attribute -Wredundant-decls -Wnested-externs -Winline 
 -Winvalid-pch -Wvolatile-register-var -Wdisabled-optimization 
 -Wbuiltin-macro-redefined -Wmudflap -Wpacked-bitfield-compat -Wsync-nand 
 -Wattributes -Wcoverage-mismatch -Wmultichar -Wno-missing-field-initializers 
 -Wno-sign-compare -Wframe-larger-than=4096 -Wp,-D_FORTIFY_SOURCE=2 
 -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions 
 -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time -Werro
r 
 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
 --param=ssp-buffer-size=4 -m64 -mtune=generic -MT libvirt_util_la-buf.lo -MD 
 -MP -MF .deps/libvirt_util_la-buf.Tpo -c util/buf.c  -fPIC -DPIC -o 
 .libs/libvirt_util_la-buf.o
 cc1: warnings being treated as errors
 util/buf.c: In function 'virBufferEscape':
 util/buf.c:430: error: logical '' with non-zero constant will always 
 evaluate as true [-Wlogical-op]
 make[3]: *** [libvirt_util_la-buf.lo] Error 1
 =
 
 If I remove -O2, I can build util/buf.c.

I test strchr in a small program:
=
# cat test.c
#include stdio.h
#include string.h

int main() {
char *s = abcdefg;
int chr = (int)'d';
char *d;

d = strchr(s, chr);
if (d)
printf(%s\n, d);

return 0;
}
# gcc -std=c99 -Wall -o test test.c -Wlogical-op -Werror
# gcc -std=c99 -O2 -Wall -o test test.c -Wlogical-op -Werror
cc1: warnings being treated as errors
test.c: In function ‘main’:
test.c:9: error: logical ‘’ with non-zero constant will always evaluate as 
true
# gcc -std=c99 -Wall -o test test.c -Wlogical-op -Werror
# gcc -std=c99 -Wall -o test test.c -Werror
=

The building failed only when '-O2' and '-Wlogical-op' are specified at the 

Re: [libvirt] Compiler warnings

2011-10-17 Thread Alex Jia

On 10/18/2011 10:09 AM, Wen Congyang wrote:

At 10/18/2011 09:32 AM, Wen Congyang Write:

At 10/18/2011 01:04 AM, Eric Blake Write:

On 10/17/2011 11:03 AM, Eric Blake wrote:

On 10/17/2011 10:17 AM, Alex Jia wrote:

Eric,
It's latest libvirt upstream, current commit id is commit 0a71c79.

# rpm -q glibc
glibc-2.12-1.42.el6.x86_64

430 if (strchr(toescape, *cur))

CC libvirt_util_la-buf.lo
util/buf.c: In function 'virBufferEscape':
util/buf.c:430: warning: logical '' with non-zero constant will
always
evaluate as true [-Wlogical-op]

Something's screwy. There's no  in that line, unless strchr() is a
macro based on your particular compilation flags. I'm suspecting that
this is a case of -D_FORTIFY_SOURCE going awry. I don't see how this
could possibly be a libvirt issue; more likely, it is an issue with the
choice of compiler flags you are using, coupled with an issue in the
system headers causing the preprocessor to expand strchr() into
something that tickles a spurious gcc warning.

Just to make sure, could you show 'make V=1' output, so we know exactly
which compiler flags are in effect?


I can reproduce this problem, here is 'make V=1' output:

=
make[3]: Entering directory `/root/rpmbuild/BUILD/libvirt-0.9.6/src'
/bin/sh ../libtool  --tag=CC   --mode=compile gcc -std=gnu99 -DHAVE_CONFIG_H 
-I. -I.. -I../gnulib/lib -I../gnulib/lib -I../include -I../src/util 
-I../include -DIN_LIBVIRT-I/usr/include/libxml2   -Wall -W -Wformat-y2k 
-Wformat-security -Winit-self -Wmissing-include-dirs -Wunused -Wunknown-pragmas 
-Wstrict-aliasing -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align 
-Wwrite-strings -Wlogical-op -Waggregate-return -Wstrict-prototypes 
-Wold-style-definition -Wmissing-prototypes -Wmissing-declarations 
-Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls 
-Wnested-externs -Winline -Winvalid-pch -Wvolatile-register-var 
-Wdisabled-optimization -Wbuiltin-macro-redefined -Wmudflap 
-Wpacked-bitfield-compat -Wsync-nand -Wattributes -Wcoverage-mismatch 
-Wmultichar -Wno-missing-field-initializers -Wno-sign-compare 
-Wframe-larger-than=4096 -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-all 
--param=ssp-buffer-size=4 -fexceptions -fasynchronous-unwind-tables 
-fdiagnostics

-s

how-option -funit-at-a-time -Werror  -O2 -g -pipe -Wall 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m64 -mtune=generic -MT libvirt_util_la-buf.lo -MD 
-MP -MF .deps/libvirt_util_la-buf.Tpo -c -o libvirt_util_la-buf.lo `test -f 
'util/buf.c' || echo './'`util/buf.c
libtool: compile:  gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I.. -I../gnulib/lib 
-I../gnulib/lib -I../include -I../src/util -I../include -DIN_LIBVIRT 
-I/usr/include/libxml2 -Wall -W -Wformat-y2k -Wformat-security -Winit-self 
-Wmissing-include-dirs -Wunused -Wunknown-pragmas -Wstrict-aliasing -Wshadow 
-Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wlogical-op 
-Waggregate-return -Wstrict-prototypes -Wold-style-definition 
-Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn 
-Wmissing-format-attribute -Wredundant-decls -Wnested-externs -Winline 
-Winvalid-pch -Wvolatile-register-var -Wdisabled-optimization 
-Wbuiltin-macro-redefined -Wmudflap -Wpacked-bitfield-compat -Wsync-nand 
-Wattributes -Wcoverage-mismatch -Wmultichar -Wno-missing-field-initializers 
-Wno-sign-compare -Wframe-larger-than=4096 -Wp,-D_FORTIFY_SOURCE=2 
-fstack-protector-all --param=ssp-buffer-size=4 -fexceptions 
-fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time -Werro

r

-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m64 -mtune=generic -MT libvirt_util_la-buf.lo -MD 
-MP -MF .deps/libvirt_util_la-buf.Tpo -c util/buf.c  -fPIC -DPIC -o 
.libs/libvirt_util_la-buf.o
cc1: warnings being treated as errors
util/buf.c: In function 'virBufferEscape':
util/buf.c:430: error: logical '' with non-zero constant will always evaluate 
as true [-Wlogical-op]
make[3]: *** [libvirt_util_la-buf.lo] Error 1
=

If I remove -O2, I can build util/buf.c.

I test strchr in a small program:
=
# cat test.c
#includestdio.h
#includestring.h

int main() {
 char *s = abcdefg;
 int chr = (int)'d';
 char *d;

 d = strchr(s, chr);
 if (d)
 printf(%s\n, d);

 return 0;
}
# gcc -std=c99 -Wall -o test test.c -Wlogical-op -Werror
# gcc -std=c99 -O2 -Wall -o test test.c -Wlogical-op -Werror
cc1: warnings being treated as errors
test.c: In function ‘main’:
test.c:9: error: logical ‘’ with non-zero constant will always evaluate as 
true
# gcc -std=c99 -Wall -o test test.c -Wlogical-op -Werror
# gcc -std=c99 -Wall -o test test.c -Werror
=

The building failed only when '-O2' and '-Wlogical-op' are specified at the 
same time.