This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/36902] Array bound warning with dead code after optimization
- From: "hjl dot tools at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Jul 2008 01:23:18 -0000
- Subject: [Bug middle-end/36902] Array bound warning with dead code after optimization
- References: <bug-36902-682@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #12 from hjl dot tools at gmail dot com 2008-07-23 01:23 -------
(In reply to comment #11)
> Thanks. Actually, I think the experiment would be more meaningful if you could
> put also the equivalent of your main (a calling function, that is) inside the
> header, because in your testcase the warning is triggered inside the main, not
> in foo.
>
Same:
[hjl@gnu-6 tmp]$ cat y.h
#pragma GCC system_header
static inline unsigned char *
foo(unsigned char * to, const unsigned char * from, int n)
{
switch ( n )
{
case 3:
*to = *from;
break;
case 5:
to[4] = from [4];
break;
}
return to;
}
struct {
int size_of_select;
unsigned char pcr_select[4];
} sel;
static int
bar (void)
{
static unsigned char buf[64];
sel.size_of_select = 3;
foo(buf, sel.pcr_select, sel.size_of_select);
return 1;
}
[hjl@gnu-6 tmp]$ cat y.c
#include <y.h>
int
main ()
{
return bar ();
}
[hjl@gnu-6 tmp]$ gcc -Wall -O2 -c y.c -Werror -I.
cc1: warnings being treated as errors
y.c: In function âmainâ:
./y.h:11: error: array subscript is above array bounds
[hjl@gnu-6 tmp]$
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36902