gcc-4.6.0-0.12.fc15.x86_64 breaks strcmp? (was: Re: gcc-4.6.0-0.11.fc15.x86_64 breaks strcmp?)
On Mon, Mar 07, 2011 at 10:14:57AM -0500, Adam Jackson wrote: On 3/7/11 9:49 AM, Richard W.M. Jones wrote: Compiling libguestfs using gcc-4.6.0-0.11.fc15.x86_64 gives lots of: error: assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C1 +- C2 [-Werror=strict-overflow] These seem to be associated with code that does 'if (strcmp (s1, s2) == 0)' For example: dir.c: In function ‘do_rm_rf’: dir.c:59:7: error: assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C1 +- C2 [-Werror=strict-overflow] I'm not able to repro this with -0.12.fc15. Firstly, I have just installed -0.12 and I can reproduce it. If I had to guess, you've got a macro for strcmp somewhere that's making type assumptions. What does the .i file look like if you compile with -save-temps ? OK ... When you said that, I initially suspected gnulib (which I am using in this code), but I cannot see gnulib doing any macros or replacement of strcmp. Below is how the failure line expands(!) -- if ((__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ((path)) __builtin_constant_p ((/)) (__s1_len = strlen ((path)), __s2_len = strlen ((/)), (!((size_t)(const void *)(((path)) + 1) - (size_t)(const void *)((path)) == 1) || __s1_len = 4) (!((size_t)(const void *)(((/)) + 1) - (size_t)(const void *)((/)) == 1) || __s2_len = 4)) ? __builtin_strcmp ((path), (/)) : (__builtin_constant_p ((path)) ((size_t)(const void *)(((path)) + 1) - (size_t)(const void *)((path)) == 1) (__s1_len = strlen ((path)), __s1_len 4) ? (__builtin_constant_p ((/)) ((size_t)(const void *)(((/)) + 1) - (size_t)(const void *)((/)) == 1) ? __builtin_strcmp ((path), (/)) : (__extension__ ({ __const unsigned char *__s2 = (__const unsigned char *) (__const char *) ((/)); register int __result = (((__const unsigned char *) (__const char *) ((path)))[0] - __s2[0]); if (__s1_len 0 __result == 0) { __result = (((__const unsigned char *) (__const char *) ((path)))[1] - __s2[1]); if (__s1_len 1 __result == 0) { __result = (((__const unsigned char *) (__const char *) ((path)))[2] - __s2[2]); if (__s1_len 2 __result == 0) __result = (((__const unsigned char *) (__const char *) ((path)))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ((/)) ((size_t)(const void *)(((/)) + 1) - (size_t)(const void *)((/)) == 1) (__s2_len = strlen ((/)), __s2_len 4) ? (__builtin_constant_p ((path)) ((size_t)(const void *)(((path)) + 1) - (size_t)(const void *)((path)) == 1) ? __builtin_strcmp ((path), (/)) : (__extension__ ({ __const unsigned char *__s1 = (__const unsigned char *) (__const char *) ((path)); register int __result = __s1[0] - ((__const unsigned char *) (__const char *) ((/)))[0]; if (__s2_len 0 __result == 0) { __result = (__s1[1] - ((__const unsigned char *) (__const char *) ((/)))[1]); if (__s2_len 1 __result == 0) { __result = (__s1[2] - ((__const unsigned char *) (__const char *) ((/)))[2]); if (__s2_len 2 __result == 0) __result = (__s1[3] - ((__const unsigned char *) (__const char *) ((/)))[3]); } } __result; }))) : __builtin_strcmp ((path), (/); }) == 0)) { -- Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v -- devel mailing list devel@lists.fedoraproject.org https://admin.fedoraproject.org/mailman/listinfo/devel
Re: gcc-4.6.0-0.12.fc15.x86_64 breaks strcmp?
On 3/7/11 10:35 AM, Richard W.M. Jones wrote: Below is how the failure line expands(!) Thanks, I needed a laugh this morning. If I do this as a minimal testcase: --- #include string.h #include stdio.h int do_rm_rf (const char *path) { int r; char *buf, *err; if (!strcmp(path, /)) { printf (cannot remove root directory); return -1; } return 0; } --- And build it with -c -save-temps, I don't get anything remotely like what you're getting in the .i file; the strcmp call is emitted unmolested. So I'm choosing to blame this on some other header you're including, and the easiest way to find it is to do: #define STREQ broken #define strcmp broken right before the call and let cpp tell you where the original is. % rpm -q glibc gcc glibc-2.13.90-4.x86_64 gcc-4.6.0-0.12.fc15.x86_64 - ajax -- devel mailing list devel@lists.fedoraproject.org https://admin.fedoraproject.org/mailman/listinfo/devel
Re: gcc-4.6.0-0.12.fc15.x86_64 breaks strcmp?
Adam Jackson wrote: On 3/7/11 10:35 AM, Richard W.M. Jones wrote: Below is how the failure line expands(!) Thanks, I needed a laugh this morning. If I do this as a minimal testcase: --- #include string.h #include stdio.h int do_rm_rf (const char *path) { int r; char *buf, *err; if (!strcmp(path, /)) { printf (cannot remove root directory); return -1; } return 0; } Shame on me. I forgot string.h and -Wall ;-) With the former and -O3, I do see your warning. Here's a pared-down test case: $ cat k.c #include string.h void do_rm_rf (const char *p) { if (strcmp (p, /) == 0) return; } $ gcc -Wall -O3 -c k.c -Werror=strict-overflow k.c: In function ‘do_rm_rf’: k.c:2:1678: error: assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C1 +- C2 [-Werror=strict-overflow] cc1: some warnings being treated as errors [Exit 1] -- devel mailing list devel@lists.fedoraproject.org https://admin.fedoraproject.org/mailman/listinfo/devel
Re: gcc-4.6.0-0.12.fc15.x86_64 breaks strcmp?
On Mon, Mar 07, 2011 at 05:15:18PM +0100, Jim Meyering wrote: With the former and -O3, I do see your warning. Here's a pared-down test case: $ cat k.c #include string.h void do_rm_rf (const char *p) { if (strcmp (p, /) == 0) return; } $ gcc -Wall -O3 -c k.c -Werror=strict-overflow k.c: In function ‘do_rm_rf’: k.c:2:1678: error: assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C1 +- C2 [-Werror=strict-overflow] cc1: some warnings being treated as errors FYI, as a workaround -D__NO_STRING_INLINES should work, then strcmp isn't expanded to the fancy glibc expansion... Jakub -- devel mailing list devel@lists.fedoraproject.org https://admin.fedoraproject.org/mailman/listinfo/devel
Re: gcc-4.6.0-0.12.fc15.x86_64 breaks strcmp?
On Mon, Mar 07, 2011 at 11:06:44AM -0500, Adam Jackson wrote: And build it with -c -save-temps, I don't get anything remotely like what you're getting in the .i file; the strcmp call is emitted unmolested. So I'm choosing to blame this on some other header you're including, and the easiest way to find it is to do: #define STREQ broken #define strcmp broken /usr/include/bits/string2.h:800:0: note: this is the location of the previous definition right before the call and let cpp tell you where the original is. % rpm -q glibc gcc glibc-2.13.90-4.x86_64 gcc-4.6.0-0.12.fc15.x86_64 I'm using: glibc-2.12.90-21.x86_64 gcc-4.6.0-0.12.fc15.x86_64 I'll try updating glibc next. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw -- devel mailing list devel@lists.fedoraproject.org https://admin.fedoraproject.org/mailman/listinfo/devel
Re: gcc-4.6.0-0.12.fc15.x86_64 breaks strcmp?
On 3/7/11 11:15 AM, Jim Meyering wrote: Shame on me. I forgot string.h and -Wall ;-) With the former and -O3, I do see your warning. Shame on me as well, -O1 or better would be needed since otherwise you're never going to hit the simplification logic that would introduce this message. I find it a little comical that glibc does this given that gcc has this level of constant expression elimination built in, but hey, why solve any problem only once. - ajax -- devel mailing list devel@lists.fedoraproject.org https://admin.fedoraproject.org/mailman/listinfo/devel