Re: [suse-programming-e] SuSE-9.0 gcc-3.3.1 optimization turns off important warning
Marcus Meissner <meissner@suse.de> writes:
But why is there no warning when optimization is turned on? (When the warning is actually needed :-) This is my main point.
It is there with -Wall on SuSE Linux 9.0:
$ cat xx.c void f(char *s) { while (*s) { *s++ = *s | 0x20; } } $ gcc -O2 -Wall -c xx.c xx.c: In function `f': xx.c:3: Warnung: operation on `s' may be undefined
It is the toupper that turns it off then: markgray@soyo:/usr/src/packages/BUILD/bug> cat xx.c #include <ctype.h> void strupr_OLD (char *s) { while (*s) { *s++ = toupper(*s); } } markgray@soyo:/usr/src/packages/BUILD/bug> gcc -O2 -Wall -c xx.c markgray@soyo:/usr/src/packages/BUILD/bug> (This is also 9.0 btw)
On Wed, Dec 31, 2003 at 09:22:36AM -0500, Mark Gray wrote:
Marcus Meissner <meissner@suse.de> writes:
But why is there no warning when optimization is turned on? (When the warning is actually needed :-) This is my main point.
It is there with -Wall on SuSE Linux 9.0:
$ cat xx.c void f(char *s) { while (*s) { *s++ = *s | 0x20; } } $ gcc -O2 -Wall -c xx.c xx.c: In function `f': xx.c:3: Warnung: operation on `s' may be undefined
It is the toupper that turns it off then:
markgray@soyo:/usr/src/packages/BUILD/bug> cat xx.c #include <ctype.h>
void strupr_OLD (char *s) { while (*s) { *s++ = toupper(*s); } }
markgray@soyo:/usr/src/packages/BUILD/bug> gcc -O2 -Wall -c xx.c markgray@soyo:/usr/src/packages/BUILD/bug>
(This is also 9.0 btw)
Hmm. Probably because *s++ = toupper(*s); is translated by a macro to: *s++ = (__extension__ ({ int __res; if (sizeof (*s) > 1) { if (__builtin_constant_p (*s)) { int __c = (*s); __res = __c < -128 || __c > 255 ? __c : (*__ctype_toupper_loc ())[__c]; } else __res = toupper (*s); } else __res = (*__ctype_toupper_loc ())[(int) (*s)]; __res; })); Might be to hard for the compiler to spot the problem. Ciao, Marcus
participants (2)
-
Marcus Meissner
-
Mark Gray