gcc -O3 -Wall test.c can gernerate warning on gcc-4.2.1 on x86. but no warning on gcc-4.2.1/x64. even -m32 or -m64. #include <stdio.h> #include <string.h> #include <stdlib.h> int main(int argc, char **argv) { char x[20]; memset(x,19,0); return 0; }
What is the warning that you are expecting? We don't warn at all for memset with a zero size.
why gcc show warnings on x86. not show warnings on x64? Bug?
(In reply to comment #2) > why gcc show warnings on x86. I am saying this does not warn in a normal FSF GCC release. So what warning do you expect? A warning for a zero sized memset? Well the FSF GCC does not warn for that case at all.
I download GCC from ftp.gnu.org, 4.2.1 release. gcc -O3 -Wall test.c can gernerate warning on gcc-4.2.1 on x86 but no warning on gcc-4.2.1/x64. even -m32 or -m64. I only think the behavior on both platform is the same, because of same release of GCC.
Why the behavior on both platform is not the same? same code, same release of GCC.
> can gernerate warning on gcc-4.2.1 on x86 What is the warning? Because I am not seeing it. It might be that glibc is doing the warning. Can you paste the warning you are getting?
test.c:14: warning: statement with no effect So I think it is gcc warning....
It might be, can you attach the preprocessed source? Which you can find by adding -save-temps and it will be either end in .i or .ii. The difference in glibc versions could be cause different warnings to show up in some cases, I remember fixing statement with no effect for memset already in 4.2.0.
Created attachment 13980 [details] file gcc -m32 -O3 -Wall test.c -save-temps
This is a bug in glibc version you are using, the warning is comming from the expansion of a #define. Looking at the expanded version, I see that glibc is violating C aliasing rules anyways so the code might not always work.
Created attachment 13981 [details] (64bit)gcc -m32 -O3 -Wall test.c -save-temps (64bit)gcc -m32 -O3 -Wall test.c -save-temps In this platform, it's no warning. why these with no warning?
I want the warning. but why the warning is glibc's bug? because memset(x,19,0), is buggy code. I need the warning.
(In reply to comment #12) > I want the warning. > but why the warning is glibc's bug? Andrew already tried to explain. It is a side-effect of a bug in glibc. > because memset(x,19,0), is buggy code. > I need the warning. I think that is a sensible feature request, am I missing something Andrew? I hope someone will be so kind to implement it for you (or you decide to implement it yourself).
Subject: Re: warning for memset with zero size On 26 Jul 2007 13:57:41 -0000, manu at gcc dot gnu dot org <gcc-bugzilla@gcc.gnu.org> wrote: > > I think that is a sensible feature request, am I missing something Andrew? memset with a zero size is valid code. Thanks, Andrew Pinski
(In reply to comment #14) > Subject: Re: warning for memset with zero size > > On 26 Jul 2007 13:57:41 -0000, manu at gcc dot gnu dot org > <gcc-bugzilla@gcc.gnu.org> wrote: > > > > I think that is a sensible feature request, am I missing something Andrew? > > memset with a zero size is valid code. > I am not saying that is invalid. I am saying that it is a statement with no effect. So it could be warned as we warn for: { 0; } Perhaps memset with size 0 appears frequently in real-code as the result of macro expansions or such. Then, this must be closed as WONTFIX and similar requests can be directed at this PR.
*** This bug has been marked as a duplicate of 16794 ***