Bug 32887 - warning for memset with zero size
Summary: warning for memset with zero size
Status: RESOLVED DUPLICATE of bug 16794
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-25 01:20 UTC by littlestar
Modified: 2007-09-10 14:07 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
file (10.95 KB, application/x-gzip)
2007-07-26 08:02 UTC, littlestar
Details
(64bit)gcc -m32 -O3 -Wall test.c -save-temps (11.06 KB, application/x-gzip)
2007-07-26 08:13 UTC, littlestar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description littlestar 2007-07-25 01:20:53 UTC
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;
}
Comment 1 Andrew Pinski 2007-07-25 02:43:30 UTC
What is the warning that you are expecting?  We don't warn at all for memset with a zero size.
Comment 2 littlestar 2007-07-25 02:49:17 UTC
why gcc show warnings on x86.
not show warnings on x64?
Bug?
Comment 3 Andrew Pinski 2007-07-25 09:09:43 UTC
(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.
Comment 4 littlestar 2007-07-25 09:13:44 UTC
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.

Comment 5 littlestar 2007-07-26 02:29:52 UTC
Why the behavior on both platform is not the same? 
same code, same release of GCC.



Comment 6 Andrew Pinski 2007-07-26 07:42:33 UTC
> 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?
Comment 7 littlestar 2007-07-26 07:45:57 UTC
test.c:14: warning: statement with no effect

So I think it is gcc warning....
Comment 8 Andrew Pinski 2007-07-26 07:50:22 UTC
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.
Comment 9 littlestar 2007-07-26 08:02:25 UTC
Created attachment 13980 [details]
file

gcc -m32 -O3 -Wall test.c -save-temps
Comment 10 Andrew Pinski 2007-07-26 08:10:07 UTC
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.  
Comment 11 littlestar 2007-07-26 08:13:14 UTC
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?
Comment 12 littlestar 2007-07-26 08:20:42 UTC
I want the warning.
but why the warning is glibc's bug?

because memset(x,19,0), is buggy code.
I need the warning.
Comment 13 Manuel López-Ibáñez 2007-07-26 13:57:40 UTC
(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).



Comment 14 pinskia@gmail.com 2007-07-26 16:51:25 UTC
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
Comment 15 Manuel López-Ibáñez 2007-07-26 16:58:47 UTC
(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.
Comment 16 Andrew Pinski 2007-09-10 14:07:08 UTC

*** This bug has been marked as a duplicate of 16794 ***