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 *
foo(unsigned char * to,const unsigned char * from,int n)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 
bar(void)27 int 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 
38 static inline unsigned char *
foo2(unsigned char * to,const unsigned char * from,int n)39 foo2(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[4] = from [4]; /* { dg-warning "\\\[-Warray-bounds" } */
48       break;
49     }
50   return to;
51 }
52 
baz(void)53 int 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