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" } */ 4typedef unsigned char __u8; 5typedef unsigned short __u16; 6 7static inline unsigned char * 8foo(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 22struct { 23 int size_of_select; 24 unsigned char pcr_select[4]; 25} sel; 26 27int bar(void) 28{ 29 static unsigned char buf[64]; 30 31 sel.size_of_select = 3; 32 foo(buf, sel.pcr_select, sel.size_of_select); 33 34 return 1; 35} 36 37 38static inline unsigned char * 39foo2(unsigned char * to, const unsigned char * from, int n) 40{ 41 switch ( n ) 42 { 43 case 3: 44 *to = *from; 45 break; 46 case 5: 47 to[63] = from [111]; /* { dg-warning "array subscript is above array bounds" } */ 48 break; 49 } 50 return to; 51} 52 53int baz(void) 54{ 55 static unsigned char buf[64]; 56 57 sel.size_of_select = 5; 58 foo2(buf, sel.pcr_select, sel.size_of_select); 59 60 return 1; 61} 62