| 1 |
/* PR middle-end/36902 Array bound warning with dead code after optimization */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-O2 -Warray-bounds -Wall -Wextra" } */ |
| 4 |
typedef unsigned char __u8; |
| 5 |
typedef unsigned short __u16; |
| 6 |
|
| 7 |
static inline unsigned char * |
| 8 |
foo(unsigned char * to, const unsigned char * from, int n) |
| 9 |
{ |
| 10 |
switch ( n ) |
| 11 |
{ |
| 12 |
case 3: |
| 13 |
*to = *from; |
| 14 |
break; |
| 15 |
case 5: |
| 16 |
to[4] = from [4]; |
| 17 |
break; |
| 18 |
} |
| 19 |
return to; |
| 20 |
} |
| 21 |
|
| 22 |
struct { |
| 23 |
int size_of_select; |
| 24 |
unsigned char pcr_select[4]; |
| 25 |
} sel; |
| 26 |
|
| 27 |
unsigned char buf[64]; |
| 28 |
int bar(void) |
| 29 |
{ |
| 30 |
sel.size_of_select = 3; |
| 31 |
foo(buf, sel.pcr_select, sel.size_of_select); |
| 32 |
|
| 33 |
return 1; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
static inline unsigned char * |
| 38 |
foo2(unsigned char * to, const unsigned char * from, int n) |
| 39 |
{ |
| 40 |
switch ( n ) |
| 41 |
{ |
| 42 |
case 3: |
| 43 |
*to = *from; |
| 44 |
break; |
| 45 |
case 5: |
| 46 |
to[4] = from [4]; /* { dg-warning "\\\[-Warray-bounds" } */ |
| 47 |
break; |
| 48 |
} |
| 49 |
return to; |
| 50 |
} |
| 51 |
|
| 52 |
int baz(void) |
| 53 |
{ |
| 54 |
sel.size_of_select = 5; |
| 55 |
foo2(buf, sel.pcr_select, sel.size_of_select); |
| 56 |
|
| 57 |
return 1; |
| 58 |
} |