/* PR middle-end/36902 Array bound warning with dead code after optimization */
|
/* PR middle-end/36902 Array bound warning with dead code after optimization */
|
/* { dg-do compile } */
|
/* { dg-do compile } */
|
/* { dg-options "-O2 -Warray-bounds -Wall -Wextra" } */
|
/* { dg-options "-O2 -Warray-bounds -Wall -Wextra" } */
|
typedef unsigned char __u8;
|
typedef unsigned char __u8;
|
typedef unsigned short __u16;
|
typedef unsigned short __u16;
|
|
|
static inline unsigned char *
|
static inline unsigned char *
|
foo(unsigned char * to, const unsigned char * from, int n)
|
foo(unsigned char * to, const unsigned char * from, int n)
|
{
|
{
|
switch ( n )
|
switch ( n )
|
{
|
{
|
case 3:
|
case 3:
|
*to = *from;
|
*to = *from;
|
break;
|
break;
|
case 5:
|
case 5:
|
to[4] = from [4];
|
to[4] = from [4];
|
break;
|
break;
|
}
|
}
|
return to;
|
return to;
|
}
|
}
|
|
|
struct {
|
struct {
|
int size_of_select;
|
int size_of_select;
|
unsigned char pcr_select[4];
|
unsigned char pcr_select[4];
|
} sel;
|
} sel;
|
|
|
int bar(void)
|
int bar(void)
|
{
|
{
|
static unsigned char buf[64];
|
static unsigned char buf[64];
|
|
|
sel.size_of_select = 3;
|
sel.size_of_select = 3;
|
foo(buf, sel.pcr_select, sel.size_of_select);
|
foo(buf, sel.pcr_select, sel.size_of_select);
|
|
|
return 1;
|
return 1;
|
}
|
}
|
|
|
|
|
static inline unsigned char *
|
static inline unsigned char *
|
foo2(unsigned char * to, const unsigned char * from, int n)
|
foo2(unsigned char * to, const unsigned char * from, int n)
|
{
|
{
|
switch ( n )
|
switch ( n )
|
{
|
{
|
case 3:
|
case 3:
|
*to = *from;
|
*to = *from;
|
break;
|
break;
|
case 5:
|
case 5:
|
to[63] = from [111]; /* { dg-warning "array subscript is above array bounds" } */
|
to[63] = from [111]; /* { dg-warning "array subscript is above array bounds" } */
|
break;
|
break;
|
}
|
}
|
return to;
|
return to;
|
}
|
}
|
|
|
int baz(void)
|
int baz(void)
|
{
|
{
|
static unsigned char buf[64];
|
static unsigned char buf[64];
|
|
|
sel.size_of_select = 5;
|
sel.size_of_select = 5;
|
foo2(buf, sel.pcr_select, sel.size_of_select);
|
foo2(buf, sel.pcr_select, sel.size_of_select);
|
|
|
return 1;
|
return 1;
|
}
|
}
|
|
|